Skip to content

Fix policyengine-us for policyengine-core 3.41.0's on-demand current-law copy - #11729

Merged
hua7450 merged 1 commit into
mainfrom
fix-core-341-current-law-copy
Dec 3, 2026
Merged

hua7450 merged 1 commit into
mainfrom
fix-core-341-current-law-copy

Conversation

@hua7450

@hua7450 hua7450 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Why

policyengine-us CI installs the newest policyengine-core on every run. Core 3.41.0 (PolicyEngine/policyengine-core#675, released 2:07 PM ET on Dec 3) changed when a reform simulation's baseline branch is built: Simulation.__init__ no longer builds it, and Core builds it the first time something reads baseline. Since then, three Python tests fail on main (release run 47182438303) and on every PR, with both 3.41.0 and 3.42.0:

  • core/test_spm_system.py::test_a_reform_simulations_baseline_arm_rejects_the_same_county_input: DID NOT RAISE SPMInputError
  • core/test_spm_system.py::test_subsampling_records_the_counties_each_arm_then_reads: KeyError: (2024, '36061')
  • core/test_social_security_input_state_machine.py::TestSocialSecurityInputStateMachine::runTest: AttributeError: 'DelegatingSimulation' object has no attribute '_current_law_source'

What changes

The baseline arm rejects a mistyped county again (policyengine_us/system.py). This is a real behavior fix, not only a test fix.

  • Before Core 3.41.0, Core built the baseline branch inside __init__. SPMSimulationMixin.__init__ then recorded, for each simulation in the family, which counties were supplied as numbers instead of text. The baseline's SPM provider got that record, and _rebuild_baseline_branch kept that provider.
  • Now the branch is built later, when migrate_social_security_inputs reads baseline, after the mixin has already recorded. So the baseline arm accepted a county such as 36_061 that the reform arm rejects.
  • _rebuild_baseline_branch now records the county input types on the rebuilt arm. With an older Core this repeats a record the arm already has, which is harmless.

The state machine test backend (tests/core/_social_security_state_backend.py). The backend runs Core's own clone and get_branch source, which now call _current_law_source and read _supplied_current_law. Like the 3.39.0 fix (PR 11657), each addition applies only when the installed Core has the name:

  • grafts _current_law_source;
  • adds _CurrentLawSource to the backend's namespace;
  • gives the fixture Simulation _supplied_current_law = None, since it supplies no current-law values.

While editing that statement, I also changed sim_methods += tuple(...) to an explicit assignment.

How I found it

  • Diff of Core sources: I compared the Core function bodies the backend borrows between 3.40.1 and 3.42.0. Only clone and get_branch changed in a way that matters, plus a docstring change in _bind_to_tax_benefit_system.
  • PR logs on 3.42.0: they show only the state machine and SPM failures from Core.

Checks

  • ruff format --check passes on both files.
  • Not run locally: the three tests. CI runs them with the newest Core (3.42.0).

axiom: n/a: policyengine-core compatibility fix; no policy change

🤖 Generated with Claude Code

…law copy

Core 3.41.0 (PolicyEngine/policyengine-core#675) stopped building a reform
simulation's baseline branch in Simulation.__init__ and builds it the first
time something reads `baseline`. That broke three tests on main:

- Two SPM tests: the baseline arm accepted a county supplied as a number,
  which the reform arm rejects. The SPM mixin records which counties were not
  text before policyengine-us builds the arm, so the arm's provider never got
  the record. `_rebuild_baseline_branch` now records them on the rebuilt arm.
- The Social Security input state machine test: its backend runs Core's
  clone and get_branch bodies, which now call `_current_law_source` and read
  `_supplied_current_law`. The backend grafts the method and supplies the
  class and attribute when Core has them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hua7450
hua7450 merged commit 036a101 into main Dec 3, 2026
36 checks passed
@hua7450
hua7450 deleted the fix-core-341-current-law-copy branch December 3, 2026 21:01
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