lomas_server.dp_queries.dp_libraries package
Submodules
lomas_server.dp_queries.dp_libraries.diffprivlib module
- class lomas_server.dp_queries.dp_libraries.diffprivlib.DiffPrivLibQuerier(private_dataset: PrivateDataset)[source]
Bases:
DPQuerier
Concrete implementation of the DPQuerier ABC for the DiffPrivLib library.
- cost(query_json: DiffPrivLibInp) 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]
- fit_model_on_data(query_json: DiffPrivLibInp) tuple[Pipeline, DataFrame, DataFrame] [source]
Perform necessary steps to fit the model on the data
- Parameters:
query_json (BaseModel) – The JSON request object for the query.
- Raises:
ExternalLibraryException – For exceptions from libraries external to this package.
- Returns:
the fitted model on the training data x_test (pd.DataFrame): test data feature y_test (pd.DataFrame): test data target
- Return type:
fitted_dpl_pipeline (dpl model)
- query(query_json: DiffPrivLibInp) Dict [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.
InvalidQueryException – If the budget values are too small to perform the query.
- Returns:
The dictionary encoding of the resulting pd.DataFrame.
- Return type:
dict
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:
ExternalLibraryException – For exceptions from libraries external to this package.
InternalServerException – For any other unforseen exceptions.
InvalidQueryException – The pipeline does not contain a “measurement”, there is not enough budget or the dataset does not exist.
- 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:
ExternalLibraryException – For exceptions from libraries external to this package.
InvalidQueryException – If the budget values are too small to perform the query.
- 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: