lomas_server.dp_queries.dp_libraries package

Submodules

lomas_server.dp_queries.dp_libraries.diffprivlib module

lomas_server.dp_queries.dp_libraries.factory module

lomas_server.dp_queries.dp_libraries.opendp module

class lomas_server.dp_queries.dp_libraries.opendp.OpenDPQuerier(private_dataset: PrivateDataset)[source]

Bases: DPQuerier

Concrete implementation of the DPQuerier ABC for the OpenDP library.

cost(query_json: OpenDPInp) tuple[float, float][source]

Estimate cost of query

Parameters:

query_json (BaseModel) – The JSON request object for the query.

Raises:
Returns:

The tuple of costs, the first value

is the epsilon cost, the second value is the delta value.

Return type:

tuple[float, float]

query(query_json: OpenDPInp) List | int | float[source]

Perform the query and return the response.

Parameters:

query_json (BaseModel) – The JSON request object for the query.

Raises:

ExternalLibraryException – For exceptions from libraries external to this package.

Returns:

(Union[List, int, float]) query result

lomas_server.dp_queries.dp_libraries.opendp.get_output_measure(opendp_pipe: Measurement) str[source]

Get output measure type.

Parameters:

opendp_pipe (dp.Measurement) – Pipeline to get measure type.

Raises:

InternalServerException – If the measure type is unknown.

Returns:

One of OpenDPMeasurement.

Return type:

str

lomas_server.dp_queries.dp_libraries.opendp.has_dataset_input_metric(pipeline: Measurement) None[source]

Check that the input metric of the pipeline is a dataset metric

Parameters:

pipeline (dp.Measurement) – The pipeline to check.

Raises:

InvalidQueryException – If the pipeline input metric is not a dataset input metric.

lomas_server.dp_queries.dp_libraries.opendp.is_measurement(pipeline: Measurement) None[source]

Check if the pipeline is a measurement.

Parameters:

pipeline (dp.Measurement) – The measurement to check.

Raises:

InvalidQueryException – If the pipeline is not a measurement.

lomas_server.dp_queries.dp_libraries.opendp.reconstruct_measurement_pipeline(pipeline: str) Measurement[source]

Reconstruct OpenDP pipeline from json representation.

Parameters:

pipeline (str) – The JSON string encoding of the pipeline.

Raises:

InvalidQueryException – If the pipeline is not a measurement.

Returns:

The reconstructed pipeline.

Return type:

dp.Measurement

lomas_server.dp_queries.dp_libraries.opendp.set_opendp_features_config(opendp_config: OpenDPConfig)[source]

Enable opendp features based on config See https://github.com/opendp/opendp/discussions/304

Parameters:

opendp_config (OpenDPConfig) – OpenDP configurations

lomas_server.dp_queries.dp_libraries.smartnoise_sql module

class lomas_server.dp_queries.dp_libraries.smartnoise_sql.SmartnoiseSQLQuerier(private_dataset: PrivateDataset)[source]

Bases: DPQuerier

Concrete implementation of the DPQuerier ABC for the SmartNoiseSQL library.

cost(query_json: SNSQLInpCost) tuple[float, float][source]

Estimate cost of query

Parameters:

query_json (BaseModel) – The JSON request object for the query.

Raises:

ExternalLibraryException – For exceptions from libraries external to this package.

Returns:

The tuple of costs, the first value

is the epsilon cost, the second value is the delta value.

Return type:

tuple[float, float]

query(query_json: SNSQLInp, nb_iter: int = 0) dict[source]

Perform the query and return the response.

Parameters:
  • query_json (BaseModel) – The JSON request object for the query.

  • nb_iter (int, optional) – Number of trials if output is Nan. Defaults to 0.

Raises:
Returns:

The dictionary encoding of the resulting pd.DataFrame.

Return type:

dict

lomas_server.dp_queries.dp_libraries.smartnoise_sql.set_mechanisms(privacy: Privacy, mechanisms: dict[str, str]) Privacy[source]

Set privacy mechanisms on the Privacy object.

For more information see: https://docs.smartnoise.org/sql/advanced.html#overriding-mechanisms

Parameters:
  • privacy (Privacy) – Privacy object.

  • mechanisms (dict[str, str]) – Mechanisms to set.

Returns:

The updated Privacy object.

Return type:

Privacy

lomas_server.dp_queries.dp_libraries.smartnoise_synth module

lomas_server.dp_queries.dp_libraries.utils module

lomas_server.dp_queries.dp_libraries.utils.querier_factory(lib: str, private_dataset: PrivateDataset) DPQuerier[source]

Builds the correct DPQuerier instance.

Parameters:
  • lib (str) – The library to build the querier for. One of DPLibraries.

  • private_dataset (PrivateDataset) – The dataset to query.

Raises:

InternalServerException – If the library is unknown.

Returns:

The built DPQuerier.

Return type:

DPQuerier

Module contents