From 09b7aad5f26171f615f9c4d75a8de50c9e65c1bb Mon Sep 17 00:00:00 2001 From: Vadym Doroshenko <53558779+dvadym@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:55:07 +0200 Subject: [PATCH] Update version to 0.2.1rc5 and remove hard dependency to dp_accounting (#485) --- analysis/parameter_tuning.py | 6 ++++-- pipeline_dp/__init__.py | 2 +- pipeline_dp/budget_accounting.py | 12 ++++++++++++ pyproject.toml | 3 +-- setup.cfg | 2 +- setup.py | 5 ++--- tests/budget_accounting_test.py | 5 ++--- tests/dp_engine_test.py | 10 ++++++++-- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/analysis/parameter_tuning.py b/analysis/parameter_tuning.py index fc77b289..26d837b8 100644 --- a/analysis/parameter_tuning.py +++ b/analysis/parameter_tuning.py @@ -142,8 +142,10 @@ def _find_candidate_parameters( if calculate_sum_per_partition_param: if hist.linf_sum_contributions_histogram.bins[0].lower >= 0: logging.warning( - "max_sum_per_partition should not contain negative sums because min_sum_per_partition tuning is not supported yet and therefore tuning for max_sum_per_partition works only when linf_sum_contributions_histogram does not negative sums" - ) + "max_sum_per_partition should not contain negative sums because" + " min_sum_per_partition tuning is not supported yet and " + "therefore tuning for max_sum_per_partition works only when " + "linf_sum_contributions_histogram does not negative sums") if calculate_l0_param and calculate_linf_count: l0_bounds, linf_bounds = _find_candidates_parameters_in_2d_grid( diff --git a/pipeline_dp/__init__.py b/pipeline_dp/__init__.py index b5f882c0..a15a32a1 100644 --- a/pipeline_dp/__init__.py +++ b/pipeline_dp/__init__.py @@ -38,4 +38,4 @@ from pipeline_dp.pipeline_backend import PipelineBackend from pipeline_dp.pipeline_backend import SparkRDDBackend -__version__ = '0.2.1rc4' +__version__ = '0.2.1rc5' diff --git a/pipeline_dp/budget_accounting.py b/pipeline_dp/budget_accounting.py index c23a646f..4b93f22f 100644 --- a/pipeline_dp/budget_accounting.py +++ b/pipeline_dp/budget_accounting.py @@ -32,6 +32,11 @@ pass +def _check_pldlib_imported() -> bool: + import sys + return "dp_accounting.pld.privacy_loss_distribution" in sys.modules + + @dataclass class MechanismSpec: """Specifies the parameters for a DP mechanism. @@ -446,6 +451,13 @@ def __init__(self, super().__init__(total_epsilon, total_delta, num_aggregations, aggregation_weights) + if not _check_pldlib_imported(): + raise ImportError("dp_accounting library is not imported. It is" + "required for using PLD budget accounting. " + "Please install dp_accounting library or use" + "NaiveBudgetAccountant instead of " + "PLDBudgetAccountant") + self.minimum_noise_std = None self._pld_discretization = pld_discretization diff --git a/pyproject.toml b/pyproject.toml index 44569f50..89c51329 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pipeline-dp" -version = "0.2.1rc4" +version = "0.2.1rc5" description = "" authors = ["Chinmay Shah ", "Vadym Doroshenko "] license = "Apache-2.0" @@ -9,7 +9,6 @@ license = "Apache-2.0" python = "^3.8, < 3.12" python-dp = "^1.1.4" numpy = "^1.20.1" -dp_accounting = "^0.4.2" [tool.poetry.dev-dependencies] yapf = "^0.32.0" diff --git a/setup.cfg b/setup.cfg index 57a835bd..abd1dd6a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.1rc4 +current_version = 0.2.1rc5 commit = True tag = True diff --git a/setup.py b/setup.py index 22df5388..e2f682fd 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,7 @@ install_requires = \ ['numpy>=1.20.1,<2.0.0', 'python-dp>=1.1.4', - 'scipy>=1.7.3,<2.0.0', - 'dp_accounting>=0.4.2' + 'scipy>=1.7.3,<2.0.0' ] @@ -22,7 +21,7 @@ def read(fname): setup_kwargs = { 'name': 'pipeline-dp', - 'version': '0.2.1rc4', + 'version': '0.2.1rc5', 'description': 'Framework for applying differential privacy to large datasets using batch processing systems', 'author': 'Chinmay Shah', 'author_email': 'chinmayshah3899@gmail.com', diff --git a/tests/budget_accounting_test.py b/tests/budget_accounting_test.py index 753dafe0..2592d20c 100644 --- a/tests/budget_accounting_test.py +++ b/tests/budget_accounting_test.py @@ -196,9 +196,8 @@ def test_not_enough_aggregations(self, use_num_aggregations): budget_accountant.compute_budgets() -@unittest.skipIf( - sys.version_info.major == 3 and sys.version_info.minor == 8, - "There are some problems with dp_accounting library in python 3.8") +@unittest.skipIf(sys.version_info.major == 3 and sys.version_info.minor <= 8, + "dp_accounting library only support python >=3.9") class PLDBudgetAccountantTest(unittest.TestCase): def test_noise_not_calculated(self): diff --git a/tests/dp_engine_test.py b/tests/dp_engine_test.py index 72ff7312..b7612886 100644 --- a/tests/dp_engine_test.py +++ b/tests/dp_engine_test.py @@ -1094,8 +1094,8 @@ def run_e2e_private_partition_selection_large_budget(self, col, backend): return col @unittest.skipIf( - sys.version_info.major == 3 and sys.version_info.minor == 8, - "There are some problems with dp_accounting library in python 3.8") + sys.version_info.major == 3 and sys.version_info.minor <= 8, + "dp_accounting library only support python >=3.9") @parameterized.parameters(False, True) def test_run_e2e_count_public_partition_local(self, pld_accounting): Accountant = pipeline_dp.PLDBudgetAccountant if pld_accounting else pipeline_dp.NaiveBudgetAccountant @@ -1224,6 +1224,9 @@ def test_min_max_sum_per_partition(self): self.assertLen(output, 1) self.assertAlmostEqual(output[0][1].sum, -3, delta=0.1) + @unittest.skipIf( + sys.version_info.major == 3 and sys.version_info.minor <= 8, + "dp_accounting library only support python >=3.9") def test_pld_not_supported_metrics(self): with self.assertRaisesRegex( NotImplementedError, @@ -1237,6 +1240,9 @@ def test_pld_not_supported_metrics(self): engine.aggregate([1], aggregate_params, self._get_default_extractors(), public_partitions) + @unittest.skipIf( + sys.version_info.major == 3 and sys.version_info.minor <= 8, + "dp_accounting library only support python >=3.9") def test_pld_not_support_private_partition_selection(self): with self.assertRaisesRegex( NotImplementedError,