Repository navigation
Reuse pre-calibration SSI and Medicaid pass values after calibration - #1778
Conversation
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>
juaristi22
left a comment
There was a problem hiding this comment.
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>
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:uncapped_ssi(_ssi_person_uncapped_amount): once before calibration, to assign SSI take-up, and once on the calibrated export frame, forus_ssi_take_up.jsonand the SSI delivery check;is_medicaid_eligible(_medicaid_person_eligibility): once before calibration, to assign Medicaid take-up, and once on the export frame, forus_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:
medicaid_claiming_tax_unit_idpoints 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
microcosm.build.us_runtime.household_pass_inputs):variable_dependency_closure), the variable itself included, since a stored column replaces a formula;tax_liability_if_itemizingcomputesincome_taxin a branch),get_holderreads (has_tinreadshas_itin),all_of_variableslists and the generated state flags;defined_forvariable;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:_mainruns exactly eleven steps between the two SSI passes, and the export frame is the calibrated-weight copy ofbase_frame.uncapped_ssiinput. Every SSI household is reused.takes_up_snap_if_eligibleand the other-health outputshealth_insurance_premiums,health_insurance_premiums_without_medicare_part_bandis_self_employedare Medicaid inputs, so the households they change are rerun.engine_workflow/us/test_us_post_calibration_take_up_inputs.py, on the tool's own passes with seven households in batches:household_weight, which only weights the returned array.engine_contract/us/test_us_household_pass_inputs.py: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:_mainrecords each first pass from the frame and values it ran on;Run time
Not changed
_ssi_person_uncapped_amountand_medicaid_person_eligibilitykeep their signatures. The local-area tool's calls are unchanged.take_up_final_diagnosticsstage, and amedicaid_final_diagnosticsstage.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