Skip to content

Reuse pre-calibration SSI and Medicaid pass values after calibration - #1778

Merged
anth-volk merged 9 commits into
mainfrom
claude/us-post-calibration-ssi-medicaid-reuse-96d382
Nov 27, 2026
Merged

anth-volk merged 9 commits into
mainfrom
claude/us-post-calibration-ssi-medicaid-reuse-96d382

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

What this changes

The US release tool (tools/build_us_fiscal_refresh_release.py) ran policyengine-us over every household twice for two person-level arrays:

  • December uncapped_ssi (_ssi_person_uncapped_amount): once before calibration, to assign SSI take-up, and once on the calibrated export frame, for us_ssi_take_up.json and the SSI delivery check;
  • is_medicaid_eligible (_medicaid_person_eligibility): once before calibration, to assign Medicaid take-up, and once on the export frame, for us_medicaid_take_up.json.

Each pre-calibration pass now keeps its per-person values and a 128-bit digest of each household's rows. After calibration:

  • a household whose digest is unchanged takes its earlier values, matched by person ID;
  • policyengine-us runs on the households whose digest changed, one batch of households at a time;
  • it also runs on one batch of unchanged households, spread over the frame, as a check; if any value differs from the recorded one, every household is run again;
  • the Medicaid reuse runs every household instead when a positive medicaid_claiming_tax_unit_id points outside its own household.

The values passed on are byte-identical to a fresh pass on the export frame, so build outputs do not change. The reuse counts are printed and sent with the build's telemetry; no release file records them.

What a household's digest covers

  • Each of its rows in every entity table: entity ID, membership and role columns, and the row's place among its household's rows.
  • Every column policyengine-us can read for the variable (microcosm.build.us_runtime.household_pass_inputs):
    • the engine's static dependency graph of the variable (variable_dependency_closure), the variable itself included, since a stored column replaces a formula;
    • plus every engine variable named in a string in a listed formula's class source, code constants or closure, with its own graph. This covers branch simulations (tax_liability_if_itemizing computes income_tax in a branch), get_holder reads (has_tin reads has_itin), all_of_variables lists and the generated state flags;
    • plus each defined_for variable;
    • repeated until nothing new is added. December SSI: 114 variables. Medicaid eligibility: 2,743.
  • A column that reads as its default when absent contributes only where a stored value differs from that default. This applies to inputs without a formula whose default is non-numeric, boolean or zero. Writing the default is therefore no change.

Neither variable reads a weight or a population-wide sum, so new weights and L0's dropped households change no remaining value.

Why these passes can be reused (tests)

  • engine_contract/us/test_us_post_calibration_take_up_inputs.py:
    • _main runs exactly eleven steps between the two SSI passes, and the export frame is the calibrated-weight copy of base_frame.
    • No column written between the SSI passes is an uncapped_ssi input. Every SSI household is reused.
    • Between the Medicaid passes, takes_up_snap_if_eligible and the other-health outputs health_insurance_premiums, health_insurance_premiums_without_medicare_part_b and is_self_employed are Medicaid inputs, so the households they change are rerun.
    • SNAP take-up reaches Medicaid eligibility only through the work-requirement formulas, which are off in 2024.
  • engine_workflow/us/test_us_post_calibration_take_up_inputs.py, on the tool's own passes with seven households in batches:
    • every column the in-between steps write leaves December SSI byte-identical;
    • the premium attribution changes a self-employed adult's 2024 Medicaid eligibility;
    • calibrated weights and an L0 selection leave both arrays byte-identical by person ID;
    • reused values equal fresh passes;
    • a trace of every variable the engine calculates or looks up while computing each pass finds nothing outside the input list except household_weight, which only weights the returned array.
  • engine_contract/us/test_us_household_pass_inputs.py:
    • the input list and the rule for absent columns;
    • a pinned set of five behavioral-response variables that module-level helpers read outside the list. A simulation without a reform does not compute them; an engine whose helpers read anything else fails until reviewed.
  • engine_free/shared/test_household_pass_reuse.py: the helper with a stand-in engine. It covers which changes rerun a household, absent and stored defaults, stored computed columns, swapped values, reordered rows, moved tax units, -0.0, wider storage, new households, batching, the check and refusals.
  • engine_free/us/test_us_post_calibration_pass_reuse_tool.py: the tool's wrappers (refusal, telemetry reports and a telemetry failure, unbatched reruns).
  • engine_free/us/test_us_fiscal_refresh_builder.py::test_main_writes_diagnostics_before_post_calibration_gate_failure:
    • _main records each first pass from the frame and values it ran on;
    • both reuses run on the export frame with their own pass functions;
    • a quarantined Medicaid evaluation reuses nothing.

Run time

  • Saved: in the five October–November release runs, the pre-calibration December SSI step took 1.1–5.8 minutes, and the Medicaid step 7.2–12.6 minutes. The SSI reuse removes nearly all of the second SSI pass.
  • Unknown: the Medicaid saving depends on how many households the SNAP take-up and other-health steps change. The SNAP step writes a flag for every SPM unit, and the other-health step replaces premiums on PUF-sourced rows, so it may be a large share. The first build with this change prints the counts.
  • Cost: digesting is about 15–22 s per Medicaid digest on a 350,000-household synthetic frame (two per build), and a few seconds for SSI.

Not changed

  • _ssi_person_uncapped_amount and _medicaid_person_eligibility keep their signatures. The local-area tool's calls are unchanged.
  • No release file, manifest or target changes. Telemetry gains reports on the running take_up_final_diagnostics stage, and a medicaid_final_diagnostics stage.

Side finding, not fixed here

Medicaid take-up flags are assigned from eligibility computed before the other-health step. The final Medicaid diagnostics measure them against eligibility computed after it. The two differ for people whose premium attribution moves them across a Medicaid income limit.

Testing

Only the tests this PR adds or changes were run, each by node ID; all pass. No full suite and no build were run.

🤖 Generated with Claude Code

anth-volk and others added 8 commits November 27, 2026 02:13
The US release tool computes December uncapped_ssi and is_medicaid_eligible
before calibration and again on the calibrated export frame. These tests
record which columns written between the two passes are inputs of each
variable:

- engine_contract: the engine's static dependency graph of each variable
  against the columns each stage between the passes writes, plus a check
  that _main runs exactly those stages between the passes. No in-between
  column reaches December uncapped_ssi. SNAP take-up and three
  other-health-insurance outputs are inputs of is_medicaid_eligible; SNAP
  take-up only through the work-requirement formulas, which are off in
  2024. Neither graph reads a weight or a population aggregate.
- engine_workflow: the release tool's own batched passes on seven
  households. Every in-between column leaves December uncapped_ssi
  byte-identical, SNAP take-up leaves Medicaid eligibility byte-identical,
  and the other-health premium attribution changes one self-employed
  adult's 2024 Medicaid eligibility. Calibrated weights and an L0
  household selection leave both arrays byte-identical by person ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The post-calibration December SSI and Medicaid eligibility passes are to
take each household's pre-calibration values when its input columns are
unchanged, and run policyengine-us only on the other households plus one
batch of unchanged ones as a check.

- engine_free/shared/test_household_pass_reuse.py: the country-neutral
  helper (microcosm.build.household_pass_reuse) with a stand-in engine:
  which changes rerun a household, absent inputs reading as defaults,
  stored computed columns, weights and dropped households, and a failed
  check rerunning every household.
- engine_contract/us/test_us_household_pass_inputs.py: the US input list
  is every engine variable in the pass variable's dependency graph, with
  the rule for which absent columns read as their default.
- engine_workflow/us: the release tool's _household_pass_record and
  _reuse_household_pass on seven households match fresh passes byte for
  byte.
- engine_free/us/test_us_fiscal_refresh_builder.py: _main records both
  pre-calibration passes and takes the post-calibration values from the
  reuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The US release tool ran policyengine-us over every household twice for
December uncapped_ssi and is_medicaid_eligible: once before calibration
and again on the calibrated export frame. Each pre-calibration pass now
keeps its per-person values and a 128-bit digest of each household's
rows (IDs, membership, row order and every column in the engine's static
dependency graph of the variable). After calibration a household whose
digest is unchanged takes its earlier values by person ID; policyengine-us
runs on the changed households and on one batch of unchanged households
as a check, and on every household if that check disagrees.

- microcosm.build.household_pass_reuse: the country-neutral helper.
- microcosm.build.us_runtime.household_pass_inputs: the input columns of
  a policyengine-us pass, and which absent columns read as defaults.
- tools/build_us_fiscal_refresh_release.py: _household_pass_record and
  _reuse_household_pass; _with_medicaid_take_up_outputs hands its
  eligibility to a recorder; _medicaid_diagnostics_for_existing_output
  takes the reused eligibility. The local-area tool's calls are
  unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The Medicaid input list missed variables the engine reads through a
  branch simulation (tax_liability_if_itemizing computes income_tax),
  get_holder (has_tin reads has_itin), all_of_variables and defined_for
  state flags. The list now adds every engine variable named in a string
  in a listed class's source, with its own dependency graph, and each
  defined_for variable, until nothing new appears. A real-engine test
  checks every variable the engine reads while computing each pass on
  the test frame is listed.
- Reruns of changed households select one batch of households at a
  time instead of copying every changed household into one frame.
- The check households are spread evenly over the frame rather than
  taken from its start, so pools built from several source blocks are
  checked in each block.
- The reuse counts are also sent with the running
  take_up_final_diagnostics telemetry stage; a telemetry failure there
  only prints a warning. The warning text says what a failed check means.
- The Medicaid pass record is released after its reuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The engine-free _main test's stand-ins now check that each record is
  made from the frame and values of its first pass, that both reuses run
  on the export frame, and that each recompute is its own pass function.
  A copy of the tool with any of those three wired wrong passed before.
- A reuse runs its rerun batches as one family: the pass functions' full
  garbage collection runs once at the end instead of once per batch.
- The Medicaid reuse reports under its own medicaid_final_diagnostics
  telemetry stage, so a failed SSI delivery check (which closes the
  running stage) is not followed by a reopened take_up_final_diagnostics.
  Each reuse reports its stage before it starts and with the counts after.
- Each input column is prepared once for both digest halves.
- A dry run, which stops before calibration, builds no records.
- Docstring corrections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A record or a reuse can carry a reason the frame's households are not
  independent; the reuse then runs the whole frame. The Medicaid reuse
  gives one when a positive medicaid_claiming_tax_unit_id does not
  resolve within the person's own household, at record time for the
  first-pass frame and at reuse time for the export frame
  (_medicaid_claim_crossing, over _assert_medicaid_claiming_tax_units_local).
- The input list also reads strings among each listed formula's code
  constants and closure values, which covers formulas generated at
  import without a class source (the state flags read state_code_str).
- Module-level helper functions are not followed; a contract test pins
  the five behavioral-response variables they read outside the list, so
  an engine whose helpers read anything else fails until reviewed.
- An unbatched build (no positive batch size) reruns in one selection.
- Engine-free tests for the tool's wrappers: the refusal, the telemetry
  reports and a telemetry failure, and the unbatched rerun.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Engine-free tests that _one_family_garbage_collection collects once
  at the end, restores its flag after nesting and after an exception,
  and that a reuse of several rerun batches runs one full collection.
- The _main stand-ins record each reuse refusal; the test checks the
  Medicaid record is judged on the first-pass frame and the reuse on
  the export frame. Copies of the tool that skip the flag restore, or
  pass no refusal, now fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_us_runtime_module_classification_is_complete requires every
us_runtime module to be a registered population operator or a reviewed
non-registry module. household_pass_inputs lists the engine columns a
household pass reads from the installed policyengine-us; it reads no
frame and treats no population.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk requested a review from juaristi22 November 27, 2026 14:14
@anth-volk
anth-volk marked this pull request as ready for review November 27, 2026 14:14

@juaristi22 juaristi22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 6a80c29b4: on a 24-household frame of my own, setting all 847 policyengine-us inputs outside the December SSI list, or the 420 outside the Medicaid list, to random non-default values leaves both arrays byte-identical, while changing a listed input moves them. After an income change in three households, two dropped households, new weights and reversed person rows, the tool's reuse returns the same bytes as a fresh pass, batched and unbatched. The 45 new tests (the engine ones on policyengine-us 2.2.1) and the 471 builder tests pass here. Nothing to raise in this PR as it stands.

For whichever of this and #1776 merges second, two things to carry across beyond the textual conflict: #1776 moves the passes' full collection into household_batches.collect_pass_garbage, so the _FAMILY_GARBAGE_DEFERRED check has to move with it, or every rerun selection ends in a full collection; and since each rerun hands a pass one batch's selection of households, under #1776 the recompute lambdas should pass refuse_population_aggregates=True, as the local-area build does.

main moved the release tool's batch loop, garbage-collection helpers and
Medicaid claiming-link check into microcosm.build.us_runtime.household_batches
and gave the pass functions a refuse_population_aggregates argument.

- Imports: both sides kept (household_batches and household_pass_inputs).
- The tool's garbage-collection block follows main. The deferral that gives
  a reuse's rerun batches one full collection moves into household_batches
  as one_pass_garbage_collection, which collect_pass_garbage checks.
- _medicaid_claim_crossing calls the package's
  assert_medicaid_claiming_tax_units_local.
- The reuse's recompute calls pass refuse_population_aggregates=True for a
  selection of rerun households (part of the population) and keep the
  pass's own rule for the whole export frame, as the old second pass did.
- Tests follow the package names; the _main stand-ins check which refusal
  each rerun passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit 8784a1f into main Nov 27, 2026
12 checks passed
@anth-volk
anth-volk deleted the claude/us-post-calibration-ssi-medicaid-reuse-96d382 branch November 27, 2026 21:25
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.

2 participants