Skip to content

Run the .py release that lists a US dataset's inputs in input_variables - #1175

Merged
anth-volk merged 8 commits into
mainfrom
v2plan/d5-12-sim-py-dataset-inputs
Dec 3, 2026
Merged

anth-volk merged 8 commits into
mainfrom
v2plan/d5-12-sim-py-dataset-inputs

Conversation

@anth-volk

@anth-volk anth-volk commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1174

Summary

Update .py (policyengine) from 6.20.4 to 6.20.5 in the simulation service. 6.20.5 (PolicyEngine/policyengine.py#783) lists every column it stores from a US dataset in the simulation's input_variables. Both policyengine[models] pins in the executor (the project's dependencies and the modal-simulation-image group) and uv.lock move to 6.20.5; they are identical to the automated update's in #1181. The executor's Docker image and every Modal image install from that lock.

6.20.5 contains only that change. Its bundle manifest changes only version labels: policyengine-core 3.34.10, policyengine-us 2.2.2, policyengine-uk 2.179.2 and the US and UK data releases are the same as in 6.20.4.

From 6.0.0 to 6.20.4, .py builds a US simulation from a dataset by creating the country simulation empty and then storing each dataset column with set_input. policyengine-core lists input_variables only at construction, so the list names none of the dataset's columns. policyengine-us's marginal_tax_rate recalculates each household's net income in copies of the simulation that keep only the values in input_variables. The copies therefore lose age, location, Social Security and every other dataset input, and cliff_gap counts the income they lose as a cliff. This affects the cliff gap and cliff share of Stage 12's cliff calculation (API v2) and of the v1 calculation's include_cliffs. The fixed release makes those copies keep every dataset input, so the cliff values match policyengine-us's for the same household.

Tests

New: test_stage12_cliff_dataset_inputs. Each case builds one household as a .py US dataset held in memory and runs it through the steps a Stage 12 cliff worker takes:

  1. resolve_cliff_output_plan;
  2. the .py Simulation(dataset=…, policy=normalise_policy(…)) that build_stage12_simulation builds;
  3. apply_output_plan, then run();
  4. validate_output_frames and cliff_totals_from_frames.

The expected values are policyengine-us's own, calculated in the test from a situation for the same household and policy, so no country-model version's numbers are written into it. The worker calls ensure(), which adds only loading and saving stored outputs around the same run(). Both households live in Wake County, North Carolina, in 2026.

Case What it covers .py 6.20.4 policyengine-us 2.2.2
Retiree, 67, $15,000 earnings, $24,000 Social Security, current law a run with no policy gap $22,644.95, share 1.0 gap $0, share 0
Parent, 30, $50,000 earnings, children 3 and 6, Child Tax Credit base raised to $3,000 a reform run, which .py builds alongside a baseline; a household that really is on a cliff gap $6,824.68, share 1.0 gap $460.95, share 1.0
  • The parent case also checks two things. It requires that policyengine-us still gives that household a cliff gap, so the case can't quietly become a second zero-gap check. And it requires that the tax unit's ctc equals policyengine-us's ($6,000 under the reform), so a policy that never reached .py fails.
  • The failing test came first. On .py 6.20.4, each case run by its node ID fails at the cliff gap assertion with the values above, after the ctc comparison passes. CI on the test commits showed the same two failures and nothing else (3,114 executor tests passed).
  • After the raise, both pass on .py 6.20.5, each run by its node ID: the cliff gaps and shares equal policyengine-us's ($0 and $460.95).
  • Run time: both cases together take about 75 s locally, most of it the reform case.
  • No network, credentials, Modal, Hugging Face or GCP is needed.
  • Ruff format and lint, the rules registry, the quality checks and uv lock --check pass. The test module is outside the executor's Pyright scope.

Review

Two rounds of adversarial review by a read-only reviewer.

Round 1 found one medium bug, now fixed. The changelog fragment said API v2's requests carry API v1's .py version. They don't: they run on the v2 default worker (next section). Its quality findings are fixed too:

  • The parent case now runs under a reform, to cover .py's reform build.
  • The test checks that the parent is still on a cliff.
  • The fragment now gives the example's place and year, and mentions labor-supply responses and stored results.

Round 2 found no bugs. Its quality findings are fixed:

  • The ctc comparison shows the reform took effect.
  • The docstring says every compared value comes from .py's reform simulation.
  • The fragment's wording on behavioral responses and refusals is no stronger than the evidence.

No bugs are left. Not covered here: the baseline simulation .py builds alongside a reform; the .py change's own tests cover it.

What deploying this does

  • API v2. API v2's reports, re-runs and household calculations name no .py version. They run on the v2 version manifest's default worker (economy_workers.default_economy_worker), and this deploy's publish_stage12_v2_default job moves that default to the new release after every check. Each request also needs API v1's catalog for exactly that version (read_catalog_rows). API v1 publishes that catalog only when it deploys the version (this service's 0.17.0 changelog). So from this deploy until API v1 deploys the same release, API v2 refuses new reports, re-runs and household calculations with unknown_catalog_version. App v3 still sends its requests to API v1, so only direct callers of API v2 are affected.
  • API v1. API v1 sends its own installed .py version with each economy request, so its reports move to the release only when API v1 raises its own pin. That is D5 · 13 in the migration plan: run API v1 on the .py release that records dataset inputs (Run API v1 on .py 6.20.5, which records US dataset inputs policyengine-api#4381).
  • API v1's deploys. They check that API v1's pinned .py version equals this service's policyengine.latest at /versions. Once this deploys and staging's latest is the new release, API v1 master deploys stop at that check until API v1's raise merges. That PR should therefore be reviewed and ready before this one merges.
  • Stored results. Results already stored for 6.20.4 are not recalculated. The Stage 12 cache identity includes the .py version, and runs are recorded per .py version, so requests on the new release calculate anew.

What the merge waits for

Earlier task Must reach Why
D5 · 1 to D5 · 7 complete (done, cancelled, or merged and deployed) earlier in the same part of the migration plan; already reached
D5 · 8: the simulation service runs .py 6.20.4 (#1169) merged this PR builds on main after it and changes the same pin after it; already reached
D5 · 9: API v1 runs .py 6.20.4 (PolicyEngine/policyengine-api#4377) deployed this deploy moves the service's latest past 6.20.4; if it did so before that PR's deploy passed its version check, that deploy would stop; already reached
D5 · 10: why API v2's cliff calculation gives most adults a cliff gap (investigation) done already reached
D5 · 11: .py lists a US dataset's inputs in input_variables (PolicyEngine/policyengine.py#783) deployed: its release on PyPI this PR pins that release; 6.20.5 is on PyPI, already reached

This PR builds on main, not on another task's branch; main is merged in.

Deployment and environment variables

No environment variable, secret, workflow, Dockerfile or Modal secret is added or changed. Once the pin is raised, the images install the new release from uv.lock.

.py's update workflow opened its own PR for 6.20.5, #1181, with the same pins and lock. This PR supersedes it.

🤖 Generated with Claude Code

anth-volk and others added 8 commits December 2, 2026 00:05
One household at a time, built as a .py US dataset, runs through the
service's cliff calculation (the planned cliff columns, .py's
Simulation(dataset=...), and the weighted totals) and must give the cliff
gap and share policyengine-us calculates for the same household given as
a situation. On .py 6.20.4 a retiree with Social Security gets a gap of
$22,644.95 instead of $0, and a parent of two on a real cliff $5,224.68
instead of $460.95: .py lists none of the dataset's columns in
input_variables, so marginal_tax_rate's copies lose them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.20.5 is the version the .py release that lists a US dataset's inputs in
input_variables is expected to have; the pin and lock move to it once it
is on PyPI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1. The parent of two now runs under a raised Child Tax Credit,
which .py builds from the dataset twice (the reform and its baseline), so
the test covers the reform side API v2 also calculates cliffs for. The
test also checks that policyengine-us still gives that household a cliff
gap, so a later model change can't turn the case into a second zero-gap
check unnoticed. On .py 6.20.4 the parent's gap is $6,824.68 instead of
$460.95.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1. API v2's requests name no .py version: they run on the v2
default worker, which this deployment moves, and need API v1's catalog for
that version, which API v1 publishes only when it deploys it. The fragment
now says API v2 refuses new calculations with unknown_catalog_version until
then, gives the example's place and year, and says labor-supply responses
change too and stored results are not recalculated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2. policyengine-us gives the parent the same cliff gap with
and without the raised credit, so the cliff comparison alone would pass
if the policy never reached .py. The test now also compares the tax
unit's ctc, a column the cliff plan already stores, and the docstring says
every compared value comes from .py's reform simulation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2. The fragment now names new reports, re-runs and household
calculations as what API v2 refuses until API v1 publishes the 6.20.5
catalog, and says labor-supply and capital-gains responses may change,
since neither has been measured with the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 2, 2026 21:51
@anth-volk
anth-volk merged commit 48fcb7a into main Dec 3, 2026
29 of 30 checks passed
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.

Run the .py release that lists a US dataset's inputs in input_variables

1 participant