Collect Medicaid eligibility from the ACA source batches instead of a second full-population pass#339
Draft
daphnehanse11 wants to merge 1 commit into
Draft
Conversation
eefdd92 to
6b0ea78
Compare
… second full-population pass The medicaid_take_up stage re-ran the entire batched Microsimulation sweep (~68 batches at the default batch size) immediately after the ACA source loop tore down identical per-batch simulations, solely to read person-level is_medicaid_eligible. The ACA writeback only touches takes_up_aca_if_eligible and selected_marketplace_plan_benchmark_ratio, neither of which appears in is_medicaid_eligible's transitive dependency closure (verified against policyengine-us), so the eligibility array is now scattered out of the ACA batch simulations via an on_batch_simulation callback and handed to _with_medicaid_take_up_outputs, which keeps the dedicated batched pass only as a fallback. Also extracts the batching skeleton (GC suspension, full-batch reuse, forced collection between batches) that was copied four times into a shared _for_each_household_batch helper used by the ACA loop, the Medicaid eligibility fallback, and both reform-validation loops. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
f12aad8 to
a545c2d
Compare
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.
Implements the deferred efficiency finding from the #334 review: the
medicaid_take_upstage re-ran a full-population batched Microsimulation sweep (~68 batches at the default 5k-household batch size) immediately after the ACA source loop tore down identical per-batch simulations, solely to read person-levelis_medicaid_eligible. Eliminating the second pass saves roughly 15–45 minutes of wall clock and the repeated multi-GB simulation churn per release build.Note
Stacked on #334 (
medicaid-chip-take-up) — the function being refactored only exists there. Retarget tomainonce #334 merges.What changed
_aca_source_tax_unit_table_batched(and its wrappers up through_with_aca_marketplace_source_outputs) accept anon_batch_simulation(batch_frame, batch_simulation)callback invoked while each batch simulation is alive. The release flow passes a new_BatchedPersonEligibilityCollector, which calculatesis_medicaid_eligibleper batch and scatters it into a full-population person array byperson_idposition._with_medicaid_take_up_outputsaccepts the precomputed array and keeps the dedicated batched pass only as a fallback; thesimulation is not Nonefast paths are preserved.takes_up_aca_if_eligibleandselected_marketplace_plan_benchmark_ratio. Verified against installed policyengine-us that neither appears inis_medicaid_eligible's transitive dependency closure (468 variables, includingadds/subtracts), so computing eligibility on the pre-writeback batch simulations is behavior-preserving. The collector tracks coverage and raises on partial coverage rather than shipping silent all-False rows; a never-invoked collector yieldsNone, which triggers the fallback pass._for_each_household_batch(frame, batch_size=…, describe=…, fn=…)helper.Blast radius
Beyond the ACA and Medicaid loops, the two reform-validation batch loops were also rewritten onto the shared helper:
_BatchedReformValidationSimulation._calculate_total(validation-measure scoring) and_reform_household_income_tax(JCT reform target materialization). Their per-batch bodies are unchanged — same dataset construction, reform application, cache invalidation, and household-position writeback — but they now share the skeleton, so a bug in the helper would touch all four passes.Tests
_with_medicaid_take_up_outputsuses a precomputed array without triggering the batched pass (asserted via diagnostics eligible weight).packages/populace-buildsuite passes (519 tests); ruff check/format clean.🤖 Generated with Claude Code