Skip to content

Canonicalise alias paths in Scenario.apply - #2418

Merged
MaxGhenis merged 1 commit into
mainfrom
scenario-apply-canonical-paths
Oct 15, 2026
Merged

MaxGhenis merged 1 commit into
mainfrom
scenario-apply-canonical-paths

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #2404, from its round-4 review (finding R4-1).

Scenario.apply(simulation), used on an already-built simulation, keyed its parameter_changes by the literal paths it was given. A deprecated gov.simulation.labor_supply_responses.* path therefore edited only the alias copy, which no formula reads. Since #2404, a scenario that had been summed (Scenario() + scenario) already carried canonical paths and did change the parameter. So the result depended on whether the scenario had been summed.

Scenario(parameter_changes={labor_supply_responses.income_elasticity: 0.3}).apply(sim) main this branch
unsummed: labour_supply_responses.income_elasticity 0.0 0.3
summed (Scenario() + …) 0.3 0.3

Main's figures come from the round-4 reviewer's reproduction (r4_apply_alias.py).

Fix: apply now iterates _canonical_paths(self.parameter_changes). That is the same canonicalisation, and the same in-order merge of a path with its alias, that Scenario.__add__ and Simulation already use. Dict values in apply are nested sub-paths, and merging them in order is unchanged.

Reproducer: policyengine_uk/tests/test_process_time_reforms.py::test_scenario_apply_changes_the_parameter_an_alias_path_copies

Local run at a4fa613: test_process_time_reforms.py + test_dated_reform_routes.py, 148 passed (-n 2).

axiom: n/a: infra

🤖 Generated with Claude Code

Scenario.apply on a built simulation edited only the deprecated
labor_supply_responses copy, which formulas do not read, unless the
scenario had been summed (Scenario.__add__ canonicalises since #2404). It
now keys its changes by canonical paths too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis marked this pull request as ready for review October 15, 2026 09:12
@MaxGhenis
MaxGhenis added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 107de81 Oct 15, 2026
16 checks passed
@MaxGhenis
MaxGhenis deleted the scenario-apply-canonical-paths branch October 15, 2026 09:39
MaxGhenis added a commit that referenced this pull request Oct 15, 2026
…ards

Brings in #2277, #2391, #2402, #2404, #2405, #2407, #2411, #2413, #2415,
#2418, #2419 and #2420. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Oct 15, 2026
…2277) into uc-hb-split-shared-cap-lha-rules

No conflicts; no benefit cap, LHA, UC or HB file changed on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant