Repository navigation
Key the URL dataset cache on the uprating inputs, and let parameter changes that reach them re-uprate the data - #2405
Merged
Merged
Conversation
…hanges that reach them re-uprate the data The cache held datasets already extended and uprated with whichever parameters loaded the URL first. A macro scenario built first left its uprated incomes for its own baseline and every later simulation; built second, it got current-law data. Datasets are now cached only when the parameters the uprating reads are current law's; any other simulation builds its own. A scenario applied after data load, which includes every reform dict, wrote its parameter changes after the data was built, so a changed growth rate moved the triple lock and the indices but not the incomes in the data. Changes that change what the uprating reads are now written before the data is built. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… document it MOCK datasets only. Both cache orders on hf:// and gs://, no economic assumptions, one shared extension under current law, reform dict versus the before-load route, the after-build timing of ordinary reforms, a property over growth rates and years, the fingerprint's sensitivity to every read input, and a read-recording guard that the fingerprint covers everything the extension reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 14, 2026
A situation, a DataFrame and a multi-year dataset are taken as given, so their scenarios keep the after-build timing without building a probe system to compare uprating inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… system The fingerprint tests built a tax-benefit system while the tests were collected, which the collection-lifetime check rejects; they now read the module's system. The uprating probe rebuilt parameters on a whole new system, loading every variable; it now rebuilds them on a shallow copy of the simulation's own system (CountryTaxBenefitSystem.parameters_with). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parameters_with rebuilt on a shallow copy that shared the system's tree, so a failing rebuild restored that tree onto the copy and its cache reset emptied the system's node caches. The copy now holds its own clone of the tree, so the system is untouched either way and the tree returned is never the system's own. The docstring says when the memo serves the real application, and the changelog names dated parameter changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-data # Conflicts: # docs/book/usage/scenarios.md # policyengine_uk/simulation.py
…-data # Conflicts: # docs/book/usage/scenarios.md # policyengine_uk/simulation.py
MaxGhenis
marked this pull request as ready for review
October 15, 2026 02:58
4 tasks done
MaxGhenis
added a commit
that referenced
this pull request
Oct 15, 2026
MaxGhenis
added a commit
that referenced
this pull request
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (verified on main 714b143 by running code with the cached Enhanced FRS 2023-24)
_url_dataset_cacheholdshf://andgs://datasets already extended and uprated with whichever parameters loaded the URL first. It is keyed by the URL alone, plus the CGT projection.Scenario(parameter_changes={"…yoy_growth.obr.average_earnings": {"year:2027-01-01:1": 0.2}}, applied_before_data_load=True). With it:.baselineand every later plain simulation got 20% employment-income growth in 2027 (should be 2.4%);no_economic_assumptionswas exposed the same way.reform=dict. A reform dict onaverage_earningsmoved the triple lock and the indices, but incomes in the data still grew 2.4%.Fix
uprating_input_paths()anduprating_input_fingerprint(parameters)indata/economic_assumptions.py. The first lists exactly what the dataset uprating reads; the second digests those parameters' full timelines plus the CGT projection metadata. The read set includesgov.dft.rail.ridership_indexand generated indices, not onlyyoy_growth..baseline/ later baselinereform={AE: {"year:2027-01-01:1": 0.2}}With #2407 (merged into this branch). #2407 splits a scenario sum by data-load timing.
_dataset_cache_keykeeps Run each part's modifier at its own time in a sum of scenarios #2407's before-load check (a before-load structural reform can change how the data is read, such as an enum order, without changing any parameter) and adds this PR's uprating fingerprint check after it.#2417. On the URL-cache route of #2417, #2407's before-load check already keeps a
no_economic_assumptionssimulation out of the cache. This PR adds a second guard, because the scenario's uprating fingerprint differs from current law's. The other routes in that issue, where callers overwriteself.datasetafter the reset copy, are unchanged here.Reproducer: policyengine_uk/tests/test_uprating_inputs_reach_data.py::test_a_macro_scenario_and_current_law_get_their_own_data
Reproducer: policyengine_uk/tests/test_uprating_inputs_reach_data.py::test_a_growth_reform_dict_projects_the_data_as_the_before_load_route
Invariants (tested in
test_uprating_inputs_reach_data.py, MOCK datasets only).baselineincluded. This is tested in both orders, forhf://andgs://, and forno_economic_assumptions.Tests
test_simulation_dataset_sources.py+test_variable_module_release.py, at acb8cc5 (before the P3 fixes and merges)test_simulation_dataset_sources.py,test_variable_module_release.py,test_process_time_reforms.py,test_dated_reform_routes.py,test_no_economic_assumptions.py,test_scenario_sum_timing.pyReview
Round 1 (independent Opus 5.5 review on a Subfleet lane, at de78bb8): requested changes. Its one blocking finding:
test_variable_module_release.py::test_no_system_dies_before_the_freeze. The tests now read the module's system and clone its parameters.It also noted, as non-blocking, that the probe built a whole new system (every variable loaded) for each dataset reform. The probe now rebuilds on a shallow copy of the simulation's own system (
CountryTaxBenefitSystem.parameters_with), which leaves that system untouched; a test checks this.Both fixes are in 3eaa753. The reviewer otherwise confirmed:
hf://andgs://with the real FRS (macro 0.2000, its baseline and other simulations 0.0240);Round 2 (confirming review at acb8cc5): APPROVE.
parameters_withleft the original system untouched in six starting states.Its three P3 notes are fixed in a84a386:
parameters_with([])returns a copy.Since then. The branch merges #2404 (5b09051) and #2407 (2581da7).
Companion: #2404, the parameter side (calendar-year bare years and generated series), merged as 655b594 and merged into this branch.
Round 3 (confirming review at 2581da7): APPROVE. It checked:
Left as non-blocking:
axiom: n/a: infra
🤖 Generated with Claude Code