Repository navigation
Description
What is wrong
Under no_economic_assumptions, Simulation.dataset can hold the projected (uprated) dataset, while the simulation calculates from the frozen copy.
build_from_multi_year_datasetcopies the dataset, appliesreset_growthfactor_upratingto the copy, loads its inputs, and setsself.datasetto that frozen copy (L900-L902, L926).- Its callers then overwrite
self.datasetwith the original, un-reset object: data/filter_dataset.py:44readssim.dataset[year], as can any caller that readssim.dataset.
Reproduction on main (MOCK data: one synthetic household)
URL-cache path. The URL cache key is the source URL alone, so a default run's projected dataset is reused by a later no_economic_assumptions run. The cache is seeded with extend_single_year_dataset(single, system.parameters) under a fake hf:// key, with no download. Then Simulation(dataset=url, scenario=no_economic_assumptions) gives:
employment_income calc=[30000.0, 30000.0, 30000.0] sim.dataset=[30000.0, 31020.0, 32431.53]
household_weight calc=[1000.0, 1000.0, 1000.0] sim.dataset=[1000.0, 1003.8, 1011.54]
rent calc=[12000.0, 12000.0, 12000.0] sim.dataset=[12000.0, 12247.97, 12800.59]
The years are 2025, 2026 and 2028. The values come from a tree whose simulation.py build paths match main b89a771.
Without the cache, no_economic_assumptions on a single-year dataset shows no gap today: the scenario applies before load, so the projection is already frozen.
With #2407. Once #2407 keeps the scenario's timing, no_economic_assumptions plus an after-load growth change ({"gov.economic_assumptions.yoy_growth.obr.average_earnings": {"year:2027-01-01:1": 0.2}}) also diverges. In the #2407 review's reproduction, sim.dataset employment income was 30,000 / 30,000 / 36,000 / 36,000 for 2025-28, while employment_income_before_lsr stayed 30,000.
Fix
- Drop the five overwrites, since
build_from_multi_year_datasetalready setsself.dataset. _restore_cgt_extension_provenancereads the private annotation from the dataset object it is passed, which is the original, notself.dataset. Dropping the overwrites therefore loses no provenance, but keep that call on the original.- Add MOCK tests for each build path (single-year object, file, hf:// cache, gs:// cache, generic
Dataset): underno_economic_assumptions,sim.dataset[y]equals the calculated inputs for every uprated variable and year. - Add a property test asserting the same for random growth changes.
Related: #2406 and #2407 (scenario timing), #2405 (keying the URL cache on the uprating inputs, which would also remove the cache-reuse route above).
Found by #2407's review (round 2), routed by its session. The UK hub reproduced the URL-cache route on main-equivalent code.
Activity
juaristi22 commentedon Oct 24, 2026
Closing as implemented on main by #2571 (commit 61dba6b). All five wrapper assignments now occur before build_from_multi_year_dataset, so that loader retains the frozen dataset it actually loaded under no_economic_assumptions. The original fix PR #2421 also confirms that main superseded its runtime change. Verified the current build paths in simulation.py, including retention of the original object for CGT provenance.
Current implementation: simulation.py.