Skip to content

Move all stochastic randomness to data package for deterministic country package#7326

Merged
MaxGhenis merged 6 commits intomainfrom
migrate-random-to-data-v2
Feb 7, 2026
Merged

Move all stochastic randomness to data package for deterministic country package#7326
MaxGhenis merged 6 commits intomainfrom
migrate-random-to-data-v2

Conversation

@baogorek
Copy link
Collaborator

@baogorek baogorek commented Feb 5, 2026

Summary

  • Remove all random() calls and seed variables from the country package
  • Takeup variables (ACA, SNAP, Medicaid) are now formula-less with default_value=True
  • WIC uses draw variables (wic_takeup_draw, wic_nutritional_risk_draw) instead of random()
  • SSI resource test uses only actual policy logic (no more probabilistic branch)
  • Add state-specific Medicaid takeup rates (53%-99% range, 51 jurisdictions)
  • Add Section 1931 deprivation rules for non-expansion states (12 states)
  • Add Head Start and Early Head Start takeup variables

Supersedes #6635 and #7317. Fixes #7316.

Files changed

Deleted (3 seed variables)

  • aca_take_up_seed.py, snap_take_up_seed.py, medicaid_take_up_seed.py

Simplified (3 takeup variables - formula removed, default True)

  • takes_up_aca_if_eligible.py, takes_up_snap_if_eligible.py, takes_up_medicaid_if_eligible.py

Created (6 new files)

  • takes_up_head_start_if_eligible.py, takes_up_early_head_start_if_eligible.py
  • wic_takeup_draw.py, wic_nutritional_risk_draw.py
  • is_single_parent_household.py, requires_deprivation.yaml

Rewritten (3 files - no more random())

  • would_claim_wic.py, is_wic_at_nutritional_risk.py, meets_ssi_resource_test.py

Updated (4 files)

  • head_start.py and early_head_start.py (multiply by takeup)
  • is_parent_for_medicaid_nfc.py (Section 1931 deprivation check)
  • takeup_rate.yaml (state-specific Medicaid rates)

Test plan

  • WIC tests: 42 passed
  • Medicaid tests: 145 passed
  • SNAP tests: 205 passed
  • SSI tests: 132 passed
  • ACA + Head Start tests: 150 passed
  • No random() calls remain in any variable file
  • Black formatting passes
  • Full test suite

Merge order

PolicyEngine/policyengine-us-data#451 must be merged FIRST, then this PR.

Related

…try package

Remove all random() calls and seed variables from the country package.
Takeup variables (ACA, SNAP, Medicaid) are now formula-less with default True.
WIC uses draw variables instead of random(). SSI resource test uses only
policy logic. Add state-specific Medicaid rates, Section 1931 deprivation
rules, Head Start/Early Head Start takeup variables.

Supersedes #6635, #7317. Fixes #7316.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.56%. Comparing base (901599b) to head (a46b5a8).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
...s/variables/gov/hhs/head_start/early_head_start.py 0.00% 2 Missing ⚠️
...gine_us/variables/gov/hhs/head_start/head_start.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main    #7326       +/-   ##
============================================
- Coverage   100.00%   86.56%   -13.44%     
============================================
  Files            3       12        +9     
  Lines           54      134       +80     
  Branches         1        0        -1     
============================================
+ Hits            54      116       +62     
- Misses           0       18       +18     
Flag Coverage Δ
unittests 86.56% <91.66%> (-13.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
baogorek and others added 4 commits February 6, 2026 14:02
Remove draw variables; would_claim_wic and wic_nutritional_risk_imputed are
now simple data-read bools. is_wic_at_nutritional_risk gates imputed risk on
having a valid WIC category.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…data-read

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These parameters are now exclusively in policyengine-us-data.
No formula in the country package references them anymore since
all takeup variables use default_value=True.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

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

All test suites pass. Codecov failures are non-blocking (Head Start takeup multiplication lines). Takeup parameters cleaned up — now exclusively in us-data.

@MaxGhenis MaxGhenis merged commit 2d0ddb7 into main Feb 7, 2026
7 of 9 checks passed
@MaxGhenis MaxGhenis deleted the migrate-random-to-data-v2 branch February 7, 2026 00:40
MaxGhenis added a commit that referenced this pull request Feb 7, 2026
- Add takes_up_ssi_if_eligible with default_value=True
- Apply takeup multiplier in ssi.py for microsimulation
- Follows new pattern from PR #7326 (no random() in country package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Feb 7, 2026
- Add takes_up_ssi_if_eligible with default_value=True
- Apply takeup multiplier in ssi.py for microsimulation
- Follows new pattern from PR #7326 (no random() in country package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Feb 7, 2026
- Add takes_up_ssi_if_eligible with default_value=True
- Apply takeup multiplier in ssi.py for microsimulation
- Follows new pattern from PR #7326 (no random() in country package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Feb 7, 2026
- Add takes_up_ssi_if_eligible with default_value=True
- Apply takeup multiplier in ssi.py for microsimulation
- Follows new pattern from PR #7326 (no random() in country package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Feb 7, 2026
* Add liquid asset variables for SSI modeling

Adds three input variables imputed from SIPP in policyengine-us-data:
- bank_account_assets: checking, savings, money market
- stock_assets: stocks and mutual funds
- bond_assets: bonds and government securities

Updates ssi_countable_resources to calculate from these asset categories,
enabling realistic asset-based eligibility testing for SSI.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Use adds pattern for ssi_countable_resources

Replace formula with adds attribute referencing parameter file that lists
the asset sources. This separates policy logic (which assets count) from
variable implementation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix references to use POMS sections that explicitly list countable resources

The USC only lists exclusions, not what counts. POMS SI 01140.xxx
explicitly defines bank accounts, stocks, and bonds as countable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add spm_unit_cash_assets aggregation from person-level assets

spm_unit_cash_assets now sums bank_account_assets, stock_assets, and
bond_assets across the SPM unit. This flows through to IL AABD and
MA EAEDC which use spm_unit_cash_assets.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Use actual imputed assets for SSI resource test

Remove microsimulation bypass that used random pass rate. Now that
liquid assets are imputed from SIPP, the resource test can use real
calculated values.

- Remove pass_rate.yaml parameter (no longer needed)
- Update README to reflect new methodology
- meets_ssi_resource_test now always uses ssi_countable_resources

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add SSI takeup variable and apply in benefit calculation

- Add takes_up_ssi_if_eligible with default_value=True
- Apply takeup multiplier in ssi.py for microsimulation
- Follows new pattern from PR #7326 (no random() in country package)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Trigger CI

* Trigger CI

* Add POMS references to asset variables

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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.

Medicaid enrollment modeling inaccuracies: state-specific takeup rates and Section 1931 deprivation rules

2 participants