Repository navigation
Keep the traced-simulation isolation test valid without core's abolition-check reads - #11248
Conversation
…ion-check reads PolicyEngine/policyengine-core#664 stops recording core's own abolition check, which supplied the test's only reads through a simulation's own parameter root. The test now leaves out each trace node's read of its own variable's abolition switch, and a variable-only test reform adds root_read_probe, which reads a parameter through the root, so the test still notices a private root that records nothing. The test also fills the shared root's cache for the period first, and checks that each private root keeps its branch name and shared-tree mark and that each traced system has its own system-level at-instant cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 47659db
This PR makes test_traced_simulations_record_their_own_parameter_accesses pass with released core and with PolicyEngine/policyengine-core#664. It does not make the test weaker. With released core 3.37.2, the new test catches every breakage of isolate_parameter_tracing that I tried. The old test caught only some of them.
Verdict: APPROVE
Suggestions
1. Keep failure output short for the root identity checks. policyengine_us/tests/core/test_spm_simulation_isolation.py:342 (assert first_root is not second_root) is older than this PR, but it prints the whole parameter tree when it fails. I saw this when I made isolate_parameter_tracing trace the shared root in place: the failure message started with assert calibration:\n gov:\n aca:\n ... and filled the screen. The PR already reads branch_name into local names for this reason (lines 347-350). The same pattern, for example assert id(first_root) != id(second_root), would help at line 342.
2. Update the cost table in the PR body. The table calls 3.36.0 "the installed release". Core 3.37.2 was released on 2026-11-24 at 8:55am EST, and CI for this PR installed 3.37.2. The test passes with 3.37.2 (see below), so only the body text is out of date.
What I checked
-
The test still checks isolation. The filter at lines 69-94 removes only
gov.abolitions.<variable>from that variable's own trace node. A read of another variable's switch still counts. The expected set keeps the threespm_unit_fpgformula reads. The newroot_read_probeadds one dated read through the simulation's own root. The check that the first trace does not grow (line 338) is unchanged. -
Pass on each core. The whole file (28 tests), on the PR head and on the PR head merged with current
main(116d7ba267, which needs core 3.37.2):Core mainbefore this PRThis PR This PR merged with main3.36.0 28 passed 28 passed not run ( mainneeds 3.37.2)3.37.2 (latest release, same as core master) 28 passed 28 passed 28 passed policyengine-core#664 head c968e9682 failed, 26 passed 28 passed 28 passed 3.37.2 with policyengine-core#664 merged 2 failed, 26 passed 28 passed 28 passed The two failures are
[2033]and[2034]of this test, as reported on policyengine-core#664. -
Fail when isolation breaks. I changed
isolate_parameter_tracinginpolicyengine_us/spm.pyin a local copy of the PR merged withmain, one change at a time, and ran both cases of the test (old version and this PR):Change to isolate_parameter_tracingOld test, core 3.37.2 This PR, core 3.37.2 This PR, with core#664 No change pass pass pass Trace the shared root in place (no private copy) fail fail fail Private root keeps the shared at-instant cache fail fail fail tracenot set on the private rootfail fail fail Private root marked as not shared pass fail fail System-level at-instant cache not replaced pass fail fail branch_namenot setpass fail fail Function does nothing fail fail fail With core#664, the old test fails in every row, so it cannot detect anything. Removing only the
mark_tree_shared(private)call does not change behavior, becausecopy(root)already copies the shared mark. The test cannot detect that change, and it does not need to. -
Other core tests with core#664.
policyengine_us/tests/coreon this PR merged withmain, with 3.37.2 plus core#664: 3,950 passed, 6 failed. No failure is in the changed file. Four of them (intest_capital_gains_response_forms.py,test_run_selective_tests.pyandtest_medicare_cost_part_d_premium.py) fail the same way with released 3.37.2 in my local setup, and CI passes them. A Hypothesis state-machine test passed when I ran it again. -
Docstring. It matches
isolate_parameter_tracinginpolicyengine_us/spm.py. Core 3.36.0 and 3.37.2 do not write the tracer onto the root in_run_formula, as the new text says. -
Changelog.
changelog.d/test-isolation-without-core-abolition-reads.fixed.mdis at the top level and has one sentence. -
CI and merge. All 38 checks pass. The
Full Suite - SPMjob installed core 3.37.2 and ran both cases (PASSED). GitHub showsMERGEABLE. The branch merges with currentmainwithout conflict. No other open PR changes this test file orpolicyengine_us/spm.py.
DTrim99
left a comment
There was a problem hiding this comment.
Program review
Base repository: PolicyEngine/policyengine-us
PR number: 11248
Reviewed head SHA: 47659db
Merge base SHA: b3edc04
Mode: full
Scope: changed behavior and affected dependencies
Source manifest: /private/tmp/policyengine-command-runs/ea33c0bb2b64/pr-11248-review-sources.json
Review status: COMPLETE
Source Documents
No source documents registered; see scope and validation.
Critical
None.
Should Address
None.
Suggestions
S1 — code-1 (SUGGESTION): two comments in spm.py still describe the old core behaviour (OPEN)
- Location:
policyengine_us/spm.py:554-556and:570-574(docstring of
isolate_parameter_tracing), and:895-896(comment inapply_reform). These lines
are not in the diff. - Problem: They say that core writes the tracer, trace flag and branch name onto the
root, "in_run_formula". The PR corrects exactly this claim in the test docstring
("which core stopped doing"). Core 3.36.0_run_formulanow wraps the tree in a
per-callTracingParameterNodeand never assignsparameters.traceor
parameters.tracer(checked by grep of the installedsimulation.py). - Impact: None on behaviour. The production docstring now contradicts the corrected
test docstring. - Optional fix: Reword these lines in this PR or a follow-up.
No other defects found.
Evidence Gaps
No material gaps reported.
Notes
- This PR changes one test and no model code, so it had one code reviewer and no source review.
- The rewritten test is not vacuous. With
isolate_parameter_tracingbroken in 8 ways (the 5 the PR lists, plus every root recording into the first simulation's tracer, the helper doing nothing, and the shared root traced in place), the test fails in both periods on core 3.36.0, 3.37.2 and the policyengine-core#664 head (c968e968). Unbroken, it passes on all three. - The filter is narrow. It drops a name only when it is the recording trace node's own
gov.abolitions.{variable}switch. A formula reading other variables' switches, through itsparametersargument and through the root, still has both reads counted. The check that the first trace did not grow still compares the unfiltered list. - The probe doesn't leak. After the test, the shared system has no
root_read_probevariable or abolition child, a fresh simulation doesn't see it, the shared root is still untraced, and parameter values are unchanged. The private core attributes the test reads exist with the same meaning on all three cores; a later rename would raise rather than pass silently.
Validation Summary
Local: the changed test file passes 28/28 on core 3.36.0 and 28/28 on core 3.37.2, imports from the snapshot. Breakage and leak checks ran on 3.36.0, 3.37.2 and the policyengine-core#664 head. CI at 47659db: 38/38 succeeded.
Timing
setup seconds: 45.00s; code role seconds: 1244.00s; parallel review seconds: 1244.00s; adjudication seconds: 0.00s; elapsed seconds: 1325.00s
Review Severity
APPROVE. Open findings: 0 critical, 0 should address, 1 suggestions.
No linked issue. This test change is needed before PolicyEngine/policyengine-core#664 is released.
What and why
test_traced_simulations_record_their_own_parameter_accessescompared each traced simulation's full set of recorded parameter names with five expected names. Two of them,gov.abolitions.spm_unit_fpgandgov.abolitions.spm_unit_size, came from core's own abolition check, which core reads before each calculation. PolicyEngine/policyengine-core#664 reads that check from the untraced tree, so it is no longer recorded, and the test fails with that pull request's core for both periods.Those two names were also the test's only reads made through the simulation's own parameter root,
simulation.tax_benefit_system.parameters(period), rather than through a formula'sparametersargument. The two kinds of read reach a tracer in different ways:parametersargument for each formula call with the calculating simulation's tracer, so dated reads through it land in the right tracer whatever the root holds.isolate_parameter_tracingsets it: on the shared tree, it gives each traced simulation and branch its own copy of the root. The SSI annual-input helper reads this way.Dropping the abolition names alone would leave the test unable to notice a private root that records nothing. So the test now:
root_read_probe, whose formula readsgov.hhs.fpg.first_person.CONTIGUOUS_USthrough the simulation's own root, and expects that name in each simulation's trace;The docstring now describes the two kinds of read and the case the test covers: simulations that share the imported tree. It no longer says that core writes the tracer onto the root on each formula call, which core stopped doing.
Test plan
make formatchangelog.d/Both cases of the changed test,
[2033]and[2034], selected by node ID:0d66b304c968e968gov.abolitionsnames are missingEach breakage of
isolate_parameter_tracingbelow was applied with a scratch pytest plugin. With only the filtered name comparison and the checks the test already had, it passed under every one of them. With this PR, it fails in both cases on both cores:traceleft off)Not covered, as before this PR: a traced simulation that owns its tree, whose root is marked in place; and reads through the root that name no instant, which neither core records.
Cost
Local macOS runs of the test before this PR (
origin/main) and with it, from scratch copies with the same pytest root, two rounds each. Time is the test call per case; memory is the pytest process's peak.0d66b304The differences are within the variation between runs. On Linux CI, the latest main run (45245929428, job
Full Suite - SPM) shows the test at 0.28 s per case. This PR does not change which CI group runs the file (make test-other-python-spm). CI peak memory was not checked.axiom: n/a: test-only change, no policy change
🤖 Generated with Claude Code