code: def test_compute_budgets(self):
      @dataclass
      class ComputeBudgetMechanisms:
          count: int
          expected_noise_std: float
          mechanism_type: MechanismType
          weight: float
          sensitivity: float
          expected_mechanism_epsilon: float = None
          expected_mechanism_delta: float = None
  
      @dataclass
      class ComputeBudgetTestCase:
          name: str
          epsilon: float
          delta: float
          expected_pipeline_noise_std: float
          mechanisms: []
  
      testcases = [
          ComputeBudgetTestCase(
              name="generic",
              epsilon=0.22999925338484556,
              delta=1e-5,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=1,
                      expected_noise_std=6.41455078125,
                      mechanism_type=MechanismType.GENERIC,
                      weight=1,
                      sensitivity=1,
                      expected_mechanism_epsilon=0.2204717161227536,
                      expected_mechanism_delta=9.585757904781109e-06,
                  )
              ],
              expected_pipeline_noise_std=6.41455078125,
          ),
          ComputeBudgetTestCase(
              name="generic_multiple",
              epsilon=0.6599974547358093,
              delta=1e-5,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=3,
                      expected_noise_std=6.71649169921875,
                      mechanism_type=MechanismType.GENERIC,
                      weight=1,
                      sensitivity=1,
                      expected_mechanism_epsilon=0.21055837268995567,
                      expected_mechanism_delta=3.190290677321479e-06,
                  )
              ],
              expected_pipeline_noise_std=6.71649169921875,
          ),
          ComputeBudgetTestCase(
              name="standard_laplace",
              epsilon=4,
              delta=0,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=2,
                      expected_noise_std=0.7071067811865476,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=1,
                      sensitivity=1,
                  )
              ],
              expected_pipeline_noise_std=0.7071067811865476,
          ),
          ComputeBudgetTestCase(
              name="standard_laplace_weights",
              epsilon=4,
              delta=0,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=2,
                      expected_noise_std=0.7071067811865476,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=2,
                      sensitivity=1,
                  )
              ],
              expected_pipeline_noise_std=1.4142135623730951,
          ),
          ComputeBudgetTestCase(
              name="standard_laplace_sensitivities",
              epsilon=3,
              delta=0,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=2,
                      expected_noise_std=2.82842712474619,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=1,
                      sensitivity=3,
                  )
              ],
              expected_pipeline_noise_std=0.9428090415820634,
          ),
          ComputeBudgetTestCase(
              name="laplace_mechanisms",
              epsilon=0.168,
              delta=1e-3,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=10,
                      expected_noise_std=49.872,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=1,
                      sensitivity=1,
                  )
              ],
              expected_pipeline_noise_std=49.872,
          ),
          ComputeBudgetTestCase(
              name="gaussian_mechanisms",
              epsilon=0.115,
              delta=1e-3,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=10,
                      expected_noise_std=50.25,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=1,
                      sensitivity=1,
                  )
              ],
              expected_pipeline_noise_std=50.25,
          ),
          ComputeBudgetTestCase(
              name="multiple_noise_kinds",
              epsilon=0.240,
              delta=1e-3,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=5,
                      expected_noise_std=49.73,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=1,
                      sensitivity=1,
                  ),
                  ComputeBudgetMechanisms(
                      count=5,
                      expected_noise_std=49.73,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=1,
                      sensitivity=1,
                  ),
                  ComputeBudgetMechanisms(
                      count=5,
                      expected_noise_std=49.73,
                      mechanism_type=MechanismType.GENERIC,
                      weight=1,
                      sensitivity=1,
                      expected_mechanism_epsilon=0.02838875378244,
                      expected_mechanism_delta=0.00010439193305478515,
                  ),
              ],
              expected_pipeline_noise_std=49.73,
          ),
          ComputeBudgetTestCase(
              name="multiple_weights",
              epsilon=1.873,
              delta=1e-5,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=4,
                      expected_noise_std=10,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=2,
                      sensitivity=1,
                  ),
                  ComputeBudgetMechanisms(
                      count=4,
                      expected_noise_std=5,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=4,
                      sensitivity=1,
                  ),
              ],
              expected_pipeline_noise_std=20,
          ),
          ComputeBudgetTestCase(
              name="multiple_sensitivities",
              epsilon=0.246,
              delta=1e-5,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=6,
                      expected_noise_std=40.048,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=1,
                      sensitivity=2,
                  ),
                  ComputeBudgetMechanisms(
                      count=2,
                      expected_noise_std=80.096,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=1,
                      sensitivity=4,
                  ),
              ],
              expected_pipeline_noise_std=20.024,
          ),
          ComputeBudgetTestCase(
              name="multiple_weights_and_sensitivities",
              epsilon=0.719,
              delta=1e-5,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=4,
                      expected_noise_std=10,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=4,
                      sensitivity=2,
                  ),
                  ComputeBudgetMechanisms(
                      count=6,
                      expected_noise_std=40,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=2,
                      sensitivity=4,
                  ),
              ],
              expected_pipeline_noise_std=20,
          ),
          ComputeBudgetTestCase(
              name="multiple_weights_and_sensitivities_variants",
              epsilon=0.822,
              delta=1e-6,
              mechanisms=[
                  ComputeBudgetMechanisms(
                      count=4,
                      expected_noise_std=20.01,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=4,
                      sensitivity=2,
                  ),
                  ComputeBudgetMechanisms(
                      count=6,
                      expected_noise_std=80.04,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=2,
                      sensitivity=4,
                  ),
                  ComputeBudgetMechanisms(
                      count=1,
                      expected_noise_std=80.04,
                      mechanism_type=MechanismType.GAUSSIAN,
                      weight=3,
                      sensitivity=6,
                  ),
                  ComputeBudgetMechanisms(
                      count=5,
                      expected_noise_std=15,
                      mechanism_type=MechanismType.LAPLACE,
                      weight=8,
                      sensitivity=3,
                  ),
              ],
              expected_pipeline_noise_std=40.02,
          ),
      ]
  
      for case in testcases:
          accountant = PLDBudgetAccountant(
              case.epsilon, case.delta, 1e-2
          )
          actual_mechanisms = []
          for mechanism in case.mechanisms:
              for _ in range(0, mechanism.count):
                  actual_mechanisms.append(
                      (
                          mechanism.expected_noise_std,
                          mechanism.expected_mechanism_epsilon,
                          mechanism.expected_mechanism_delta,
                          accountant.request_budget(
                              mechanism.mechanism_type,
                              weight=mechanism.weight,
                              sensitivity=mechanism.sensitivity,
                          ),
                      )
                  )
          self.assertEqual(
              len(actual_mechanisms),
              len(accountant._mechanisms),
              f"failed test {case.name} expected len {len(actual_mechanisms)} "
              f"got len {len(accountant._mechanisms)}",
          )
          if case.delta > 0:
              compare_pld = accountant._compose_distributions(
                  case.expected_pipeline_noise_std
              )
              actual_epsilon = compare_pld.get_epsilon_for_delta(
                  case.delta
              )
              self.assertAlmostEqual(
                  case.epsilon,
                  actual_epsilon,
                  delta=1e-3,
                  msg=f"failed test {case.name} expected epsilon "
                  f"{case.epsilon} got {actual_epsilon}",
              )
          accountant.compute_budgets()
          self.assertAlmostEqual(
              first=case.expected_pipeline_noise_std,
              second=accountant.minimum_noise_std,
              delta=1e-2,
              msg=f"failed test {case.name} expected pipeline noise "
              f"{case.expected_pipeline_noise_std} "
              f"got {accountant.minimum_noise_std}",
          )
          for mechanism_expectations in actual_mechanisms:
              (
                  expected_mechanism_noise_std,
                  expected_mechanism_epsilon,
                  expected_mechanism_delta,
                  actual_mechanism,
              ) = mechanism_expectations
              self.assertAlmostEqual(
                  first=expected_mechanism_noise_std,
                  second=actual_mechanism.noise_standard_deviation,
                  delta=1e-2,
                  msg=f"failed test {case.name} expected mechanism noise "
                  f"{expected_mechanism_noise_std} "
                  f"got {actual_mechanism.noise_standard_deviation}",
              )
              if (
                  actual_mechanism.mechanism_type
                  == MechanismType.GENERIC
              ):
                  self.assertAlmostEqual(
                      first=expected_mechanism_epsilon,
                      second=actual_mechanism._eps,
                      delta=1e-3,
                      msg=f"failed test {case.name} expected mechanism epsilon "
                      f"{expected_mechanism_epsilon} "
                      f"got {actual_mechanism._eps}",
                  )
                  self.assertAlmostEqual(
                      first=expected_mechanism_delta,
                      second=actual_mechanism._delta,
                      delta=1e-3,
                      msg=f"failed test {case.name} expected mechanism delta "
                      f"{expected_mechanism_delta} "
                      f"got {actual_mechanism._delta}",
                  )
  
imports: import sys
  import unittest
  from dataclasses import dataclass
  from pipeline_dp.budget_accounting import MechanismSpec
  from pipeline_dp.aggregate_params import MechanismType
  from pipeline_dp.budget_accounting import NaiveBudgetAccountant
  from pipeline_dp.budget_accounting import PLDBudgetAccountant
  from absl.testing import parameterized
label_desc: Use image node_id 8 for calling the PLDBudgetAccountantTest obj's underlying member method code with example usage: obj.test_compute_budgets() without return types