Repository navigation
List a US dataset's columns in input_variables, so marginal tax rates, cliff gaps and labor-supply responses match policyengine-us - #783
Merged
Conversation
Three tests that fail before the change (#781): after a run with a reform, the reform simulation and its baseline list every stored dataset column in input_variables; a retiree's cliff_gap is 0 and marginal_tax_rate equals policyengine-us's; and the labor-supply response equals policyengine-us's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PolicyEngineUSLatest.run constructs the country simulation empty and stores the dataset's columns afterwards, but policyengine-core fills input_variables only at construction. policyengine-us formulas that calculate in a copy of the simulation (marginal_tax_rate, and through it cliff_gap and the behavioral responses) delete every value whose variable is not listed, so the copies lost every dataset input. _build_simulation_from_dataset now records the live ID names and dataset columns it stores with _record_input_variables, for the reform simulation and its baseline (#781). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found that the capital-gains response deletes only unlisted variables that have a formula, so its copies never lost the dataset's inputs; that the reform simulation's list always held the five behavioral-response inputs policyengine-us adds; that policyengine-core's derivative does not read input_variables; and that the test module's docstring described the first test wrongly. Wording only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gelog exact The input_variables test checked no labor-supply output, so it runs with a reform that only raises the 12 % rate, which takes 18 s instead of 85 s. It also checks that the reform simulation keeps the five inputs policyengine-us adds to the list. The changelog now names the household each measured value belongs to, says which inputs were already listed, and describes the trust-fund variables as covering Social Security and Medicare. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
December 2, 2026 16:16
anth-volk
added a commit
to PolicyEngine/policyengine-sim-api
that referenced
this pull request
Dec 2, 2026
Both policyengine[models] pins in the executor (its dependencies and the modal-simulation-image group) and uv.lock move from 6.20.4 to 6.20.5, which lists a US dataset's stored columns in input_variables (PolicyEngine/policyengine.py#783). Its bundle changes only version labels: policyengine-core, policyengine-us, policyengine-uk and the data releases are unchanged. The Stage 12 cliff test now gives policyengine-us's cliff gap and share for both households. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #781
What changes
_build_simulation_from_dataset(src/policyengine/tax_benefit_models/us/model.py) collects the live ID names and dataset columns it stores withset_input. It then adds them to the country simulation'sinput_variableswithlegacy_inputs._record_input_variables, the helper the legacy input renames and the SPM declarations already use.runcalls_build_simulation_from_datasetfor the reform's baseline and then for the reform simulation, so both lists are updated. policyengine-core gives each its own list.62d8eb98, Add canonical SPM selection, receipts and native loading to the wrapper #515),PolicyEngineUSLatest.runconstructs the policyengine-usMicrosimulationempty (situation={}) and stores the dataset afterwards.input_variablesonly inSimulation.__init__, so the baseline's list was empty. The reform's list held only the five behavioral-response inputs policyengine-us always adds, such asemployment_income_before_lsr.marginal_tax_ratecalculates in a copy of the simulation after deleting every value whose variable is not listed. Its copies therefore lost age, state, county, Social Security and every other dataset input.changelog.d/781.fixed.md. No other path changes:create_datasetsconstructs itsMicrosimulationwith the dataset passed in.Effect on results
For a one-adult household in Wake County, North Carolina, in 2026 (policyengine-us 2.2.2, policyengine-core 3.34.10):
Simulation(situation=...)marginal_tax_ratecliff_gapmarginal_tax_rateemployment_income_behavioral_responseThe federal, state and FICA marginal rates,
marginal_tax_rate_including_health_benefitsand the Social Security trust-fund revenue variables delete unlisted values the same way, so they change too. They have no tests of their own here: the first test below checks the list they all read.Tests
New module
tests/test_us_dataset_input_variables.py. Each test runs one adult throughSimulation(dataset=...)from in-memory tables, with no downloads.test_reform_and_baseline_list_every_stored_dataset_column_as_an_input: after a run with a reform that raises the 12 % rate, the reform simulation and its baseline both list every stored ID and dataset column ininput_variables, and the reform keeps the five inputs policyengine-us adds.test_retiree_cliff_gap_and_marginal_tax_rate_match_policyengine_us: the retiree'scliff_gapis 0, andmarginal_tax_rateequals policyengine-us's for the same inputs, computed in the test.test_labor_supply_response_matches_policyengine_us: the worker's labor-supply response under the reform equals policyengine-us's.Local results, each test run by node ID:
1fd0f4f, before the change, all three fail on their assertions:cliff_gapis 22,644.95.459bba3all three pass.84ddfe6switched the first test to a reform that only changes the rate (18 s instead of 85 s) and added the check on the five inputs. With that file, the first test fails on its assertion on1fd0f4f(22 columns missing) and passes on84ddfe6.ruff formatandruff checkare clean on the changed files. mypy reports eight errors inus/model.py, all on lines this PR doesn't change; mypy is informational in this repository's CI.towncrier checkpasses.Out of scope
employment_incomerather thanemployment_income_before_lsrgets no labor-supply response through this path, for a separate reason. policyengine-us moves such values only when the dataset is passed at construction. Certified Populace US data stores the_before_lsrnames.Review
Two rounds of adversarial review before this PR was opened. The second found no bugs, so there was no third.
459bba3): no high- or medium-priority bugs; two low-priority ones.e813c88: the changelog overstated two things._record_input_variableshad claimed that policyengine-core'sderivativereads the list, and the new docstring in_build_simulation_from_datasetand the test module's docstring had claimed more than the code and tests do.Simulation.idare still reused bySimulation.ensure(), because the US output loader keeps no record that would mark them as calculated before this fix. Fixing it needs a new record in saved US output files and a check on load.e813c88): no bugs.84ddfe6: the changelog now names the household each measured value belongs to, and the first test is faster and also checks the five added inputs.Bugs left: the low-priority saved-output one above.
Merge order
This is tracker task D5 · 11 of the API v2 migration. It builds on
main, not on another PR's branch. Every earlier task is complete. PolicyEngine/policyengine-api#4377 (D5 · 9: API v1 on .py 6.20.4) has merged, and being merged is enough: it changes only API v1's .py pin, and this PR needs nothing it deploys. Once released, the simulation service and API v1 take the new version in their own PRs.🤖 Generated with Claude Code