Skip to content

Adapt to policyengine-core 3.41's on-demand current-law copy - #11730

Closed
DTrim99 wants to merge 1 commit into
mainfrom
core-current-law-on-demand-compat
Closed

DTrim99 wants to merge 1 commit into
mainfrom
core-current-law-on-demand-compat

Conversation

@DTrim99

@DTrim99 DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

What's failing on main

The main push run 47182438303 at f8b3ea5 failed in two jobs:

  • Full Suite - SPM (make test-other-python-spm): two failures in policyengine_us/tests/core/test_spm_system.py
    • test_a_reform_simulations_baseline_arm_rejects_the_same_county_input: DID NOT RAISE SPMInputError
    • test_subsampling_records_the_counties_each_arm_then_reads: KeyError: (2024, '36061')
  • Full Suite - Rest (Python shard 3): test_social_security_input_state_machine.py::TestSocialSecurityInputStateMachine::runTest raises AttributeError: 'DelegatingSimulation' object has no attribute '_current_law_source'

Cause

The full-suite jobs run uv lock --upgrade-package policyengine-core before installing, so they test the newest compatible core rather than the locked 3.40.0. policyengine-core 3.41.0 (core PR #675) stopped branching a reform simulation's baseline arm in __init__. Core now builds the current-law copy the first time something asks for it, through a new _build_current_law_simulation hook. Simulation.baseline becomes a deprecated alias that builds the copy when read. CI now resolves 3.42.0. No policyengine-us commit since the last green full suite touches this code.

Fix

SPM county rejection and the subsampling county record (policyengine_us/spm.py). SPMSimulationMixin.__init__ used to find the baseline arm in branches and record, on that arm's own SPM provider, which counties were supplied as numbers rather than text. Under core 3.41 the copy doesn't exist yet when __init__ runs. In this package, migrate_social_security_inputs builds it later by reading baseline. The copy's provider, created before any input arrived, therefore never recorded the mistyped county, and the baseline arm accepted it. The mixin now overrides core's _build_current_law_simulation hook. The override gives every copy core builds what construction gave the baseline arm: it drops holders built for the reform's variables, binds the rest to the copy's policy, primes that policy's parameter tracing, and records the copy's counties. The guarantee is unchanged: a reform simulation's current-law arm rejects the same county input before it computes anything. Both tests pass unchanged.

Social Security state machine (policyengine_us/tests/core/_social_security_state_backend.py). The backend runs selected, unmodified core method bodies on a small fixture Simulation. Core 3.41's clone and get_branch now call _current_law_source(), construct _CurrentLawSource, and read the _supplied_current_law class default. The backend now loads _current_law_source and _CurrentLawSource when core has them, matching how it already handles refuse_on_read_only and the fallback-cache methods. It also copies every class-level default that core declares on Simulation and the fixture doesn't set itself, so a default a later core adds won't break the fixture. The test and its assertions are unchanged.

Version pin

Kept at policyengine-core>=3.40.0, with uv.lock left at 3.40.0. Both changes do nothing on 3.40: core 3.40 never calls the hook, and the backend additions are skipped when core lacks them. With the pin kept, the locked jobs test 3.40.0 and the jobs that resolve the latest core test 3.42.0, so CI covers both. Raising the floor would force core's new current-law behavior on every install, which deserves its own PR.

Not changed here: policyengine-us still reads simulation.baseline (now a deprecated alias with no warning) in migrate_social_security_inputs and several formulas. _rebuild_baseline_branch assigns the rebuilt arm back to baseline, so on 3.41+ the copy is still built during construction and kept as an assigned copy, which core never makes read-only. Moving to the declared current-law calls (current_law_simulation(), compares_with_current_law) is a separate follow-up.

Tests run

Locally on macOS with core 3.42.0, resolved as CI does with uv lock --upgrade-package policyengine-core:

  • The 3 failing tests: all pass (before the fix: 3 failures reproduced).
  • SPM suite (make test-other-python-spm files: test_spm_policy_family.py, test_spm_simulation_isolation.py, test_spm_system.py): 116 passed.
  • policyengine_us/tests/core/ and other Python tests that touch reform baselines or current law: in progress; this section will be updated.
  • ruff format and ruff check: clean.

axiom: n/a: test and core-compatibility plumbing, no policy rule change

🤖 Generated with Claude Code

Core 3.41.0 no longer branches a reform simulation's baseline arm in
__init__; it builds the current-law copy through
_build_current_law_simulation when something first asks for it. The SPM
mixin's __init__ therefore never saw the copy, so the copy's provider never
recorded counties supplied as numbers, and the baseline arm accepted them.
Override the hook to give the copy what construction gave the baseline arm:
drop holders built for the reform, rebind to the copy's policy, prime its
parameter tracing and record its counties.

The Social Security input test backend executes selected Core method bodies
on a fixture class. Core 3.41's clone and get_branch read
_current_law_source, _CurrentLawSource and the _supplied_current_law class
default; load them when Core has them, and take every class-level default
Core declares that the fixture does not set.

Both changes are no-ops on core 3.40, so the pin stays at >=3.40.0.

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

DTrim99 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #11729, which fixes the same three core 3.41.0 failures (the two SPM county tests and the Social Security input state machine) and passed the full suite.

@DTrim99 DTrim99 closed this Dec 3, 2026
@DTrim99
DTrim99 deleted the core-current-law-on-demand-compat branch December 3, 2026 21:05
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.

1 participant