From 0a484308bdd83367009dc77300a2a24399043cdd Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:17:42 +0400 Subject: [PATCH 1/6] Test that formulas removing a temporary branch calculate when it was never kept policyengine-core's read-only simulations (not yet released) give a new branch for a name they have not registered and do not keep it in simulation.branches, so del simulation.branches[name] raises KeyError. The test gives a simulation a get_branch that keeps no new branch and checks the marginal tax rates, the capital gains rate and the employer Social Security and Medicare income tax revenues against plain values. Co-Authored-By: Claude Opus 5.5 --- .../core/test_unkept_temporary_branches.py | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 policyengine_us/tests/core/test_unkept_temporary_branches.py diff --git a/policyengine_us/tests/core/test_unkept_temporary_branches.py b/policyengine_us/tests/core/test_unkept_temporary_branches.py new file mode 100644 index 00000000000..d9ac053978b --- /dev/null +++ b/policyengine_us/tests/core/test_unkept_temporary_branches.py @@ -0,0 +1,163 @@ +"""Formulas that remove a temporary branch calculate when it was never kept. + +``marginal_tax_rate`` and its component rates (through +``marginal_earnings_change``), ``marginal_tax_rate_on_capital_gains``, +``employer_ss_tax_income_tax_revenue`` and +``employer_medicare_tax_income_tax_revenue`` each create a branch of the +simulation with ``get_branch``, calculate in it, then remove it from +``simulation.branches``. policyengine-core's read-only simulations +(``Simulation.make_read_only``, not yet released) give a new branch for a name +they have not registered and do not keep it in ``branches``, so +``del simulation.branches[name]`` raised ``KeyError`` on them. + +The released core keeps every branch ``get_branch`` creates, so these tests +give chosen simulations a ``get_branch`` that removes each new branch from +``branches`` before returning it, as a read-only simulation keeps none. Each +formula must give the value it gives on a plain simulation of the same +household, after creating its branch on the simulation that keeps none. + +Cost: each case builds two one-person simulations; the reform case also +applies a parametric reform to each, the largest part of the file's cost. +""" + +import numpy as np +import pytest +from policyengine_core.reforms import Reform +from policyengine_core.simulations import Simulation as CoreSimulation + +from policyengine_us import Simulation + +YEAR = 2024 + + +def one_person_household(**person_inputs): + """A California household of one 40-year-old with ``person_inputs`` in YEAR.""" + person = {"age": {YEAR: 40}} + person.update({name: {YEAR: value} for name, value in person_inputs.items()}) + return { + "people": {"person": person}, + "tax_units": {"tax_unit": {"members": ["person"]}}, + "spm_units": {"spm_unit": {"members": ["person"]}}, + "families": {"family": {"members": ["person"]}}, + "marital_units": {"marital_unit": {"members": ["person"]}}, + "households": { + "household": {"members": ["person"], "state_code": {YEAR: "CA"}} + }, + } + + +# Including employer payroll taxes in income makes the employer revenue +# formulas branch; with it off they return zero without branching. +EMPLOYER_PAYROLL_TAX_IN_INCOME = { + "gov.contrib.crfb.tax_employer_payroll_tax.in_effect": { + "2020-01-01.2100-12-31": True + }, + "gov.contrib.crfb.tax_employer_payroll_tax.percentage": { + "2020-01-01.2100-12-31": 1.0 + }, +} + + +@pytest.fixture +def stop_keeping_new_branches(monkeypatch): + """Return a function that stops a simulation keeping branches it creates. + + After ``stop_keeping_new_branches(simulation)``, ``simulation.get_branch`` + with a name it has not registered still creates and returns a branch, but + removes it from ``simulation.branches`` first, as a read-only simulation + keeps no branch it creates. The branch itself keeps the branches it + creates, as a read-only simulation's branches do. The function returns the + list of names of branches the simulation created and did not keep, which + grows as it calculates. + """ + unkept_branch_names = [] + simulations_keeping_no_new_branches = [] + core_get_branch = CoreSimulation.get_branch + + def get_branch_keeping_none(self, name="branch", clone_system=False): + creating = name != self.branch_name and name not in self.branches + branch = core_get_branch(self, name, clone_system) + keeps_none = any( + self is simulation for simulation in simulations_keeping_no_new_branches + ) + if creating and keeps_none: + del self.branches[name] + unkept_branch_names.append(name) + return branch + + monkeypatch.setattr(CoreSimulation, "get_branch", get_branch_keeping_none) + + def stop_keeping(simulation): + simulations_keeping_no_new_branches.append(simulation) + return unkept_branch_names + + return stop_keeping + + +def test_the_test_simulation_keeps_no_branch_it_creates(stop_keeping_new_branches): + simulation = Simulation(situation=one_person_household(employment_income=50_000)) + registered_before = dict(simulation.branches) + unkept_branch_names = stop_keeping_new_branches(simulation) + first = simulation.get_branch("temporary") + second = simulation.get_branch("temporary") + assert first is not second + assert first.parent_branch is simulation + assert simulation.branches == registered_before + assert unkept_branch_names == ["temporary", "temporary"] + nested = first.get_branch("nested") + assert first.branches == {"nested": nested} + + +@pytest.mark.parametrize( + "situation, parameter_changes, branch_name_of_variable", + [ + pytest.param( + one_person_household( + employment_income=50_000, long_term_capital_gains=20_000 + ), + None, + { + "marginal_tax_rate": "mtr_for_adult_1", + "state_marginal_tax_rate": "state_mtr_for_adult_1", + "marginal_tax_rate_on_capital_gains": "adult_1_cg_rise", + }, + id="current law", + ), + pytest.param( + one_person_household(employment_income=50_000), + EMPLOYER_PAYROLL_TAX_IN_INCOME, + { + "employer_ss_tax_income_tax_revenue": "without_employer_ss", + "employer_medicare_tax_income_tax_revenue": ( + "without_employer_medicare" + ), + }, + id="employer payroll tax in income", + ), + ], +) +def test_formulas_give_their_plain_values_when_their_branches_are_not_kept( + stop_keeping_new_branches, situation, parameter_changes, branch_name_of_variable +): + def build_simulation(): + if parameter_changes is None: + return Simulation(situation=situation) + reform = Reform.from_dict(parameter_changes, country_id="us") + return Simulation(situation=situation, reform=reform) + + plain = build_simulation() + plain_values = { + variable: plain.calculate(variable, YEAR) + for variable in branch_name_of_variable + } + + simulation = build_simulation() + registered_before = dict(simulation.branches) + unkept_branch_names = stop_keeping_new_branches(simulation) + for variable, branch_name in branch_name_of_variable.items(): + value = simulation.calculate(variable, YEAR) + # A zero would also come from a formula that returned before branching. + assert np.all(plain_values[variable] != 0), variable + np.testing.assert_array_equal(value, plain_values[variable], err_msg=variable) + assert branch_name in unkept_branch_names, variable + assert simulation.branches == registered_before From 008df8f97a2e2a2740e9b387e9660fac920f5811 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:23:26 +0400 Subject: [PATCH 2/6] Remove temporary branches with branches.pop(name, None) The marginal tax rate helper, the capital gains marginal tax rate and the employer Social Security and Medicare income tax revenue formulas deleted their branch with del simulation.branches[name]. A simulation that keeps no branch it creates, such as one of policyengine-core's planned read-only simulations, raised KeyError there. pop(name, None), which six other formulas already use, removes the branch when the simulation kept it. Co-Authored-By: Claude Opus 5.5 --- .../variables/gov/simulation/capital_gains_responses.py | 2 +- .../ssa/revenue/employer_medicare_tax_income_tax_revenue.py | 2 +- .../gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py | 2 +- .../variables/household/marginal_tax_rate_helpers.py | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/policyengine_us/variables/gov/simulation/capital_gains_responses.py b/policyengine_us/variables/gov/simulation/capital_gains_responses.py index 1d1e384a435..dd14c5d8365 100644 --- a/policyengine_us/variables/gov/simulation/capital_gains_responses.py +++ b/policyengine_us/variables/gov/simulation/capital_gains_responses.py @@ -216,5 +216,5 @@ def formula(person, period, parameters): # pragma: no cover increase = household_net_income_higher_gains - household_net_income mtr_values += where(mask, 1 - increase / where(mask, stored_rise, 1), 0) - del simulation.branches[branch_name] + simulation.branches.pop(branch_name, None) return mtr_values diff --git a/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py b/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py index 6e7171b9a37..e179ee9a715 100644 --- a/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py +++ b/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py @@ -52,7 +52,7 @@ def formula(tax_unit, period, parameters): pass tax_without_medicare = branch.tax_unit("income_tax", period) - del sim.branches["without_employer_medicare"] + sim.branches.pop("without_employer_medicare", None) # Medicare revenue = tax with full reform - tax without Medicare return max_(tax_full - tax_without_medicare, 0) diff --git a/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py b/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py index bb9297e8b97..7437b9d923b 100644 --- a/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py +++ b/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py @@ -52,7 +52,7 @@ def formula(tax_unit, period, parameters): pass tax_without_ss = branch.tax_unit("income_tax", period) - del sim.branches["without_employer_ss"] + sim.branches.pop("without_employer_ss", None) # SS revenue = tax with full reform - tax without SS return max_(tax_full - tax_without_ss, 0) diff --git a/policyengine_us/variables/household/marginal_tax_rate_helpers.py b/policyengine_us/variables/household/marginal_tax_rate_helpers.py index 8cb95a033f6..adeb2ed082e 100644 --- a/policyengine_us/variables/household/marginal_tax_rate_helpers.py +++ b/policyengine_us/variables/household/marginal_tax_rate_helpers.py @@ -83,7 +83,8 @@ def create_perturbed_branch(simulation, period, branch_name, increments): Args: simulation: The simulation to branch from. period: The period whose inputs rise. - branch_name: Name of the branch; the caller deletes it when done. + branch_name: Name of the branch; when done, the caller removes it + from ``simulation.branches`` if the simulation kept it. increments: Person-level increase for each raised variable. Returns: @@ -183,7 +184,7 @@ def marginal_earnings_change(person, period, parameters, measure, branch_prefix) alt = measure(branch.person) change += where(mask, (alt - base) / delta, 0) measured |= mask - del simulation.branches[branch_name] + simulation.branches.pop(branch_name, None) return change, measured From 02ac53c68315efa074ac7fa1435156a3109c4ab5 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:04:06 +0400 Subject: [PATCH 3/6] Test that formulas refuse to calculate in a branch with their branch name In a branch named as a formula names the branch it creates (mtr_for_adult_1, adult_1_cg_rise, without_employer_ss, without_employer_medicare), get_branch returns the simulation being calculated. The formula then raised that simulation's inputs or neutralized variables in its system. del simulation.branches[name] raised KeyError afterwards; pop(name, None) does not, so the result was wrong. The formulas must refuse before changing anything. state_marginal_tax_rate leaves the value test: it goes through the same statement as marginal_tax_rate. Co-Authored-By: Claude Opus 5.5 --- .../core/test_unkept_temporary_branches.py | 107 ++++++++++++------ 1 file changed, 71 insertions(+), 36 deletions(-) diff --git a/policyengine_us/tests/core/test_unkept_temporary_branches.py b/policyengine_us/tests/core/test_unkept_temporary_branches.py index d9ac053978b..62aba88c6de 100644 --- a/policyengine_us/tests/core/test_unkept_temporary_branches.py +++ b/policyengine_us/tests/core/test_unkept_temporary_branches.py @@ -108,50 +108,48 @@ def test_the_test_simulation_keeps_no_branch_it_creates(stop_keeping_new_branche assert first.branches == {"nested": nested} -@pytest.mark.parametrize( - "situation, parameter_changes, branch_name_of_variable", - [ - pytest.param( - one_person_household( - employment_income=50_000, long_term_capital_gains=20_000 - ), - None, - { - "marginal_tax_rate": "mtr_for_adult_1", - "state_marginal_tax_rate": "state_mtr_for_adult_1", - "marginal_tax_rate_on_capital_gains": "adult_1_cg_rise", - }, - id="current law", - ), - pytest.param( - one_person_household(employment_income=50_000), - EMPLOYER_PAYROLL_TAX_IN_INCOME, - { - "employer_ss_tax_income_tax_revenue": "without_employer_ss", - "employer_medicare_tax_income_tax_revenue": ( - "without_employer_medicare" - ), - }, - id="employer payroll tax in income", - ), - ], -) +# Each case: the household, the parameter changes it is simulated under, and +# for each formula the name it gives the branch it creates. +CASES = [ + pytest.param( + one_person_household(employment_income=50_000, long_term_capital_gains=20_000), + None, + { + "marginal_tax_rate": "mtr_for_adult_1", + "marginal_tax_rate_on_capital_gains": "adult_1_cg_rise", + }, + id="current law", + ), + pytest.param( + one_person_household(employment_income=50_000), + EMPLOYER_PAYROLL_TAX_IN_INCOME, + { + "employer_ss_tax_income_tax_revenue": "without_employer_ss", + "employer_medicare_tax_income_tax_revenue": "without_employer_medicare", + }, + id="employer payroll tax in income", + ), +] + + +def build_simulation(situation, parameter_changes): + if parameter_changes is None: + return Simulation(situation=situation) + reform = Reform.from_dict(parameter_changes, country_id="us") + return Simulation(situation=situation, reform=reform) + + +@pytest.mark.parametrize("situation, parameter_changes, branch_name_of_variable", CASES) def test_formulas_give_their_plain_values_when_their_branches_are_not_kept( stop_keeping_new_branches, situation, parameter_changes, branch_name_of_variable ): - def build_simulation(): - if parameter_changes is None: - return Simulation(situation=situation) - reform = Reform.from_dict(parameter_changes, country_id="us") - return Simulation(situation=situation, reform=reform) - - plain = build_simulation() + plain = build_simulation(situation, parameter_changes) plain_values = { variable: plain.calculate(variable, YEAR) for variable in branch_name_of_variable } - simulation = build_simulation() + simulation = build_simulation(situation, parameter_changes) registered_before = dict(simulation.branches) unkept_branch_names = stop_keeping_new_branches(simulation) for variable, branch_name in branch_name_of_variable.items(): @@ -161,3 +159,40 @@ def build_simulation(): np.testing.assert_array_equal(value, plain_values[variable], err_msg=variable) assert branch_name in unkept_branch_names, variable assert simulation.branches == registered_before + + +@pytest.mark.parametrize("situation, parameter_changes, branch_name_of_variable", CASES) +def test_formulas_refuse_to_calculate_in_a_branch_with_their_branch_name( + situation, parameter_changes, branch_name_of_variable +): + """In a branch with the name a formula gives its branch, it changes nothing. + + There ``get_branch`` returns the simulation being calculated, so raising + its inputs or neutralizing variables in its system would change that + simulation, and its result would be wrong. + """ + simulation = build_simulation(situation, parameter_changes) + for variable, branch_name in branch_name_of_variable.items(): + branch = simulation.get_branch(branch_name) + system = branch.tax_benefit_system + neutralized_before = { + name + for name, definition in system.variables.items() + if definition.is_neutralized + } + inputs_before = { + name: branch.calculate(name, YEAR).copy() + for name in ("employment_income_before_lsr", "long_term_capital_gains") + } + with pytest.raises(ValueError, match=branch_name): + branch.calculate(variable, YEAR) + neutralized_after = { + name + for name, definition in system.variables.items() + if definition.is_neutralized + } + assert neutralized_after == neutralized_before, variable + for name, value in inputs_before.items(): + np.testing.assert_array_equal( + branch.calculate(name, YEAR), value, err_msg=f"{variable}: {name}" + ) From 764b28a3ee55518c3d57c98cd95c21e10dcf0581 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:06:57 +0400 Subject: [PATCH 4/6] Refuse to change a branch that is the simulation being calculated Add get_branch_to_change, which raises ValueError when get_branch returns the simulation itself (asked for the simulation's own branch name). The marginal tax rate helper's perturbed branch and the employer Social Security and Medicare revenue formulas use it, so a formula calculated in a branch with its branch name stops before raising that simulation's inputs or neutralizing variables in its system. Co-Authored-By: Claude Opus 5.5 --- policyengine_us/tools/branched_simulation.py | 21 +++++++++++++++++++ ...mployer_medicare_tax_income_tax_revenue.py | 5 ++++- .../employer_ss_tax_income_tax_revenue.py | 3 ++- .../household/marginal_tax_rate_helpers.py | 3 ++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/policyengine_us/tools/branched_simulation.py b/policyengine_us/tools/branched_simulation.py index 83e9bfc43ef..f604fe1a713 100644 --- a/policyengine_us/tools/branched_simulation.py +++ b/policyengine_us/tools/branched_simulation.py @@ -11,6 +11,27 @@ def get_stored_variables(simulation: Simulation) -> list: return stored_variables +def get_branch_to_change( + simulation: Simulation, branch_name: str, clone_system: bool = False +) -> Simulation: + """Return ``simulation.get_branch(branch_name)``, never ``simulation``. + + For a formula that changes its branch's inputs or tax-benefit system. + ``get_branch`` returns the simulation itself when asked for the + simulation's own branch name, so the formula would change the simulation + it is calculating and give a wrong result. Raise ``ValueError`` instead, + before anything changes. + """ + branch = simulation.get_branch(branch_name, clone_system=clone_system) + if branch is simulation: + raise ValueError( + f"This simulation is the branch {branch_name!r}, the name the" + " formula gives the branch it changes. Calculate it in a" + " simulation with another branch name." + ) + return branch + + class BranchedSimulation: def __init__(self, population: Population): self.simulation = population.simulation diff --git a/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py b/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py index e179ee9a715..5ea45c07f2f 100644 --- a/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py +++ b/policyengine_us/variables/gov/ssa/revenue/employer_medicare_tax_income_tax_revenue.py @@ -1,4 +1,5 @@ from policyengine_us.model_api import * +from policyengine_us.tools.branched_simulation import get_branch_to_change class employer_medicare_tax_income_tax_revenue(Variable): @@ -37,7 +38,9 @@ def formula(tax_unit, period, parameters): tax_full = tax_unit("income_tax", period) # === Branch: Tax WITHOUT employer Medicare (neutralize source) === - branch = sim.get_branch("without_employer_medicare", clone_system=True) + branch = get_branch_to_change( + sim, "without_employer_medicare", clone_system=True + ) # Neutralize the source variable - reform formula will pick up 0 for Medicare branch.tax_benefit_system.neutralize_variable("employer_medicare_tax") diff --git a/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py b/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py index 7437b9d923b..5665389c09f 100644 --- a/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py +++ b/policyengine_us/variables/gov/ssa/revenue/employer_ss_tax_income_tax_revenue.py @@ -1,4 +1,5 @@ from policyengine_us.model_api import * +from policyengine_us.tools.branched_simulation import get_branch_to_change class employer_ss_tax_income_tax_revenue(Variable): @@ -37,7 +38,7 @@ def formula(tax_unit, period, parameters): tax_full = tax_unit("income_tax", period) # === Branch: Tax WITHOUT employer SS (neutralize source) === - branch = sim.get_branch("without_employer_ss", clone_system=True) + branch = get_branch_to_change(sim, "without_employer_ss", clone_system=True) # Neutralize the source variable - reform formula will pick up 0 for SS branch.tax_benefit_system.neutralize_variable("employer_social_security_tax") diff --git a/policyengine_us/variables/household/marginal_tax_rate_helpers.py b/policyengine_us/variables/household/marginal_tax_rate_helpers.py index adeb2ed082e..c7f9e253d65 100644 --- a/policyengine_us/variables/household/marginal_tax_rate_helpers.py +++ b/policyengine_us/variables/household/marginal_tax_rate_helpers.py @@ -1,5 +1,6 @@ from policyengine_us.model_api import * from policyengine_core.periods import period as make_period +from policyengine_us.tools.branched_simulation import get_branch_to_change from policyengine_us.tools.period_branch import drop_inherited_values from policyengine_us.variables.gov.simulation.behavioral_response_measurements import ( NEUTRALIZED_BEHAVIORAL_RESPONSE_VARIABLES, @@ -100,7 +101,7 @@ def create_perturbed_branch(simulation, period, branch_name, increments): for variable in HELD_BEHAVIORAL_RESPONSE_VARIABLES if not variables[variable].is_neutralized } - branch = simulation.get_branch(branch_name) + branch = get_branch_to_change(simulation, branch_name) for variable in variables: if variable not in input_variables: branch.delete_arrays(variable) From ff3768d2a6454c0172a47571d1e25c8a85926e92 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:07:09 +0400 Subject: [PATCH 5/6] Add changelog fragment for removing temporary branches with pop Co-Authored-By: Claude Opus 5.5 --- changelog.d/read-only-simulation-branch-removal.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/read-only-simulation-branch-removal.fixed.md diff --git a/changelog.d/read-only-simulation-branch-removal.fixed.md b/changelog.d/read-only-simulation-branch-removal.fixed.md new file mode 100644 index 00000000000..5716cf5b7ca --- /dev/null +++ b/changelog.d/read-only-simulation-branch-removal.fixed.md @@ -0,0 +1 @@ +The marginal tax rates, `marginal_tax_rate_on_capital_gains`, `employer_ss_tax_income_tax_revenue` and `employer_medicare_tax_income_tax_revenue` now remove their temporary branch with `simulation.branches.pop(name, None)`, so they calculate on a simulation that keeps no branch it creates, such as policyengine-core's planned read-only simulations, instead of raising `KeyError`. Calculated in a branch with the name they give their own branch, they now raise `ValueError` before changing that branch's inputs or system. From 7fceae5fa6da5fafab6fc09d2b4ac7d357226081 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:25:31 +0400 Subject: [PATCH 6/6] Document the ValueError create_perturbed_branch raises Co-Authored-By: Claude Opus 5.5 --- .../variables/household/marginal_tax_rate_helpers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/policyengine_us/variables/household/marginal_tax_rate_helpers.py b/policyengine_us/variables/household/marginal_tax_rate_helpers.py index c7f9e253d65..fa36ebdc6e1 100644 --- a/policyengine_us/variables/household/marginal_tax_rate_helpers.py +++ b/policyengine_us/variables/household/marginal_tax_rate_helpers.py @@ -90,6 +90,11 @@ def create_perturbed_branch(simulation, period, branch_name, increments): Returns: The branch simulation. + + Raises: + ValueError: ``branch_name`` is the simulation's own branch name, so + ``get_branch`` would return the simulation itself (see + ``get_branch_to_change``). """ # US wrappers also register explicit set_input calls after construction, # including identification and other inputs set on the measuring branch.