You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Supplied-input helpers misread provenance after build_from_populations with another simulation's populations #2747
supplied_input, supplied_input_periods and supplied_by in policyengine_uk/utils/supplied_inputs.py decide provenance from the simulation's own _user_input_keys. After Simulation.build_from_populations(other.populations), the populations' holders come from the other simulation, but the record still describes the old ones (core keeps it: PolicyEngine/policyengine-core#605). So the helpers can call another simulation's formula result supplied, and miss a value that simulation supplied.
Probe on main (2d437eb), one adult with £30,000 employment income, period 2026 (supplied_input(person, "adjusted_net_income", 2026), then adjusted_net_income and net_income):
Case
supplied_input
adjusted_net_income
net_income
Fresh, nothing supplied
None
30,000
30,000
Fresh, 50,000 supplied
50,000
50,000
50,000
This simulation supplied 50,000; populations from one that calculated it
30,000 (a formula result)
30,000
30,000
Nothing supplied here; populations from one that supplied 50,000
None
50,000
30,000
In the last case net_income ignores the supplied adjusted net income that the variable itself reads. The third case returns a formula result as supplied, against the helper's docstring, though the output here happens to match.
The model reaches build_from_populations only with fresh populations (build_from_situation, build_from_dataset), so only a caller that passes another simulation's populations hits this.
Likely fix. Core's Holder._is_input(period, branch) answers from the input record of the simulation the holder was built in, which moves with the populations. #2234 uses it for Housing Benefit's override check (stored_as_input), after a Sol review found the same failure there. The other helpers would also need the model-value records (set_model_value) of the holder's own simulation, since build_from_populations forgets this simulation's.
Probe: probe.py and its output in the UK hub's records; it runs in a few seconds without a dataset.
#2234 now fixes this and closes it on merge (Fixes #2747). The likely fix in the issue body, asking the holder, fixed only the Housing Benefit check, and a review then found that clones and branches of the rebuilt simulation lost the provenance again.
The new fix moves the records with the holders. Simulation.build_from_populations calls adopt_population_records, which binds each holder from another simulation to this one. It keeps that simulation's input and model-value records for the values the holder still stores, drops the values that simulation calculated, and forgets this simulation's records of values the rebuild removed. supplied_input, supplied_input_periods and supplied_by read the simulation's record, so they now answer for the new holders, as do clones and branches.
test_input_records.py pins this issue's last two rows:
test_rebuilt_populations_keep_an_input_supplied_to_their_simulation: supplied_input returns 50,000 and net_income is 50,000.
test_rebuilt_populations_keep_a_value_their_simulation_calculated: supplied_input returns None and net_income is 30,000.
Activity
Move input records with the holders of rebuilt populations
MaxGhenis commentedon Oct 29, 2026
#2234 now fixes this and closes it on merge (
Fixes #2747). The likely fix in the issue body, asking the holder, fixed only the Housing Benefit check, and a review then found that clones and branches of the rebuilt simulation lost the provenance again.The new fix moves the records with the holders.
Simulation.build_from_populationscallsadopt_population_records, which binds each holder from another simulation to this one. It keeps that simulation's input and model-value records for the values the holder still stores, drops the values that simulation calculated, and forgets this simulation's records of values the rebuild removed.supplied_input,supplied_input_periodsandsupplied_byread the simulation's record, so they now answer for the new holders, as do clones and branches.test_input_records.pypins this issue's last two rows:test_rebuilt_populations_keep_an_input_supplied_to_their_simulation:supplied_inputreturns 50,000 andnet_incomeis 50,000.test_rebuilt_populations_keep_a_value_their_simulation_calculated:supplied_inputreturns None andnet_incomeis 30,000.Both fail at d5c96d9 and pass at 6e090ed. The holder binding itself is now PolicyEngine/policyengine-core#636.
Copy another simulation's populations at a rebuild instead of sharing…