Repository navigation
Record scale, child-list and undated parameter reads in the tracer - #664
Conversation
Build on the per-formula TracingParameterNode view from #574. The trace now records tax-scale reads with a description of the schedule, reads of which children a node has, parameters a formula reads before choosing an instant, and the parameters core reads for adds, subtracts and uprating. Each trace node also records whether its formula ran. Rebuilt from #543. The tree-level tracing state that PR added is dropped, because #574 replaced it. Co-authored-by: PavelMakarchuk <pavel.ma99@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An output now counts as covered in a file only after the formula it uses at that period has run and the output calculated without an error. A value masked by defined_for, given as an input, or from an output that raised no longer hides later tests. The selection moves into trace_yaml_tests, which reports how many tests it skipped. The fingerprint now covers the whole package and the traced tests. YAML files holding one mapping and .yml files are read as the runner reads them. The filter on gov.abolitions paths is gone, because core's abolition check is not traced. The command, trace_microdata and the selection's effect on edges now have tests. Co-authored-by: PavelMakarchuk <pavel.ma99@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Attributes of an undated parameter such as values_list, children and clone are now recorded at that node's path for all instants, and looking for a child that is absent records the node. dependency-map counts excluded tests and unreadable files, follows nested period mappings, ignores hidden files in the fingerprint, rejects a missing tests root and says when it skipped tests. Co-authored-by: PavelMakarchuk <pavel.ma99@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A country simulation that traces its own parameter root sends core's abolition check through the tracing node, once per variable. Recording absent children for key look-ups stored every abolition name each time, so only attribute look-ups are recorded now. dependency-map leaves gov.abolitions reads out again, because they reach the trace the same way. Co-authored-by: PavelMakarchuk <pavel.ma99@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A key look-up that finds no child should be recorded at the missing path, without the names of the node's other children, so core's abolition check records only the variable's own switch. dependency-map should leave out only that switch, and keep a formula's read of another variable's switch. These tests fail until the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A key look-up that finds no child is recorded again, now at the missing child's path with no value, so a formula that falls back on a default is a reader of the parameter that would change it. Core's abolition check therefore records only the variable's own switch, without the names of the other switches. dependency-map leaves out only that switch, gov.abolitions.<variable>, and keeps a formula's read of another variable's switch: policyengine-us's SSI income helpers make such reads, and turning those switches on changes the reading variable. The tracing node now documents how absent children are recorded, and the docstrings no longer say that key look-ups are not recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A country package can trace its own parameter root. Core's abolition check then reached the trace, once per variable, and dependency-map had to leave those reads out. These tests expect the check to record nothing, whether the switch exists, is missing, or there is no gov node. They also expect trace_microdata to record reads made through a root the package traces with the tracer it hands over, and a miss looked up with a str-based enum member to be recorded at the member's string value. These tests fail until the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…acer Core's abolition check now reads the parameter tree without a tracing view, so a country package that traces its own parameter root no longer records one read, or one miss, per calculated variable. In policyengine-us that removed the extra objects that caused a second full garbage collection in traced household calculations. dependency-map no longer needs to leave abolition switches out: every recorded switch read is a formula's. dependency-map's tracing setup kept replacing the simulation's tracer after a country package had handed it to its own parameter root, so reads through that root went to a tracer nobody read. The same tracer now drops values instead. A key that is a str-based enum member is recorded at its string value, the path the look-up uses. The docstrings and changelog say which look-ups that find nothing are recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES (head c968e968b7)
Summary
The tracer changes are correct for the cases that I checked. A traced US household records every (variable, parameter) pair that master core records, except each variable's own abolition switch. The PR intends that removal. The trace also records 474 new pairs. Untraced runs are not slower. Traced runs are faster. The full core test suite passes at head, on head merged with current master, and on head merged with master and #570.
One item blocks approval. The PR removes core's own abolition check from traces. A policyengine-us test asserts that check, so it fails on policyengine-us main with this core. Core CI does not run that test, so CI is green.
#664 and #570 merge cleanly in either order, and the two orders give the same tree. The combined tests pass. One edge case appears only when both PRs are in: a traced formula can raise where the untraced formula does not (see the first suggestion below).
Findings
CRITICAL
None.
SHOULD ADDRESS
1. A policyengine-us test fails with this core. policyengine_core/simulations/simulation.py:1721 now reads the abolition switch through _untraced(...). A country package that traces its own parameter root (policyengine-us does) therefore no longer records gov.abolitions.<variable> for each calculated variable. policyengine-us main (eae2e2775f) asserts these reads in policyengine_us/tests/core/test_spm_simulation_isolation.py:253-261:
expected = {
"gov.abolitions.spm_unit_fpg",
"gov.abolitions.spm_unit_size",
...
}
assert set(first_accesses) == expected
Failure case: test_traced_simulations_record_their_own_parameter_accesses[2033] and [2034] fail with "Extra items in the right set: 'gov.abolitions.spm_unit_size', 'gov.abolitions.spm_unit_fpg'". They pass with master core. policyengine-us requires policyengine-core>=3.36.0, so the first core release that contains this PR breaks policyengine-us CI. The core "Test Core and country packages" job runs only the smoke tests, so it did not catch this. The PR body does not mention the failure.
Fix: open a policyengine-us PR that changes the test, and link it from this PR. To pass with old and new core, the test can compare only the reads that are not gov.abolitions.*. Merge it before the core release, as #570 did with policyengine-uk#2926.
SUGGESTION
1. With #570, a traced attribute miss resolves every sibling. policyengine_core/tracers/tracing_parameter_node_at_instant.py:261 calls _record_absent_child_read, which calls _record_children_read (line 316). Line 323 runs list(node_at_instant._children). Under #570, _children resolves every child of the node. A child that fails to build then raises inside the traced run only. #570 says that such a child "fails when it is read, not when the node is built, so the node's other children can be read".
Failure case (country template, a node with a child x and a child bad whose _get_at_instant raises; the formula returns p.x + getattr(p, "missing", 10)):
| Core | Untraced | Traced |
|---|---|---|
| master | error | error |
| master + #664 | error | error |
| master + #570 | 11.0 | 11.0 |
| master + #570 + #664 | 11.0 | RuntimeError |
No current policyengine-us code reaches this case. The US trace with #570 and #664 is the same as with #664 alone (4,465 pairs, no difference), and the 623 partner tests pass traced. The same line also makes each traced attribute miss resolve the whole node, which takes away part of the laziness that #570 adds. A possible fix: on an attribute miss, record the node path without the child-name list, or catch errors from the child listing on that path.
2. Remove the downstream workarounds after the release. policyengine-app-v2 app/scripts/build-parameter-dependency-map.py and us-cliffs-2017 scripts/audit_parameters.py monkeypatch get_traced_child, _get_at_instant or the undated view to record scale reads and undated calls. With this PR they record those reads twice (once with None, once with the scale description). Both scripts put names into sets, so the result does not change. An issue in each repository can say that the workarounds are no longer necessary.
3. Scope. The PR adds the dependency-map command (about 1,340 lines with its tests) together with the tracer fix. A separate PR for the command would make each review smaller. This is optional, because the PR keeps the command in a separate commit and has a separate changelog fragment.
What I checked
- PR, issues and history. I read the PR body, the linked issues #541 and #542, and the history of #570 and #660. The PR has no comments and no reviews. The head commit was pushed on 2026-11-19 at 3:45pm EST. CI ran from 4:02pm EST on 2026-11-19, before #660 merged at 4:13pm EST. The PR body tested #570 at
c9bbd7e8. The current #570 head isf2451292d5(pushed 4:33pm EST on 2026-11-19). I tested with the current heads. - Diff, line by line. I read all changes in
simulation.py,full_tracer.py,simple_tracer.py,trace_node.py,tracing_parameter_node_at_instant.py,__init__.py, the command parser andtools/dependency_map.py, and the changed test intest_tracing_parameter_isolation.py.- Scale reads record
{type, thresholds, rates|amounts}with plain Python numbers. Undated reads (values_list,children,clone) record the node path with periodeternityand no value. Child-list reads record the node path with the child names. Key misses record the missing path with no value. formula_ranis a new dataclass field with a default, at the end. Positional construction does not change. The flat trace and the computation log do not show it._record_parameter_readforadds,subtractsand uprating runs only whenself.traceis true.
- Scale reads record
- Trace format. For one CA family of four (
household_net_income,ssi,eitc,ctc,snapfor 2026), the computation log has 23,403 lines with master core and with #664 core. The flat trace has 9,298 keys with both. The performance graph builds with both. Traced and untraced values are equal. Parameter reads go from 22,307 to 6,087. Serialized flat-trace JSON goes from 3.57 MB to 3.23 MB. Duplicate reads in one node go from 1,014 to 873 (repeated reads, as on master). Strict JSON (allow_nan=False) fails with both cores because parameter values already holdinf. Scale descriptions add 10 more parameters with infinite thresholds, so this is not new. - Lost and new edges. Pairs (variable, period, parameter): 10,494 with master core, 4,465 with #664 core. All 6,503 lost pairs are the variable's own
gov.abolitions.<variable>. No other pair is lost. 474 pairs are new (scale reads, undated calls such asgov.ssa.uprating(...),values_listreads in the Social Security COLA helpers). - Tracer consumers. I read the consumers that
gh search codefound: policyengine.pyderivations/trace.py, policyengine-servercomputation_trees.py, policyengine-ukutils/dependencies.py, policyengine-app-v2build-parameter-dependency-map.py, ccdf-calculatorscripts/policy_index.py, microcosmvalidation_input_coverage.py, computation-tree-explainerapp.pyand us-cliffs-2017audit_parameters.py. None readsTraceNodefields by position. None needs a numeric parameter value. Those that read parameter names use only the part before<. - Overhead. Country template, 150 simulations by 3 monthly and 3 yearly variables, 3 rotating rounds with fresh processes (best of 5 in each): untraced 0.237 to 0.243 s on master and 0.238 to 0.244 s with #664 (no difference). US household (
household_net_incomeandmarginal_tax_rate, best of 3 warm runs, 2 rounds): untraced 1.43 to 1.49 s on master and 1.42 s with #664. Traced 2.50 to 2.52 s on master and 1.65 to 1.67 s with #664. - Core test suite. Master
e556c9e7: 3,980 passed. Head: 3,962 passed. Head merged with master: 4,066 passed. Master with #570: 4,219 passed. Master with #570 and #664: 4,305 passed. Each run also had the 4 knowntest_release_tagging.pyfailures (notomllibin the local setup) and nothing else. The country-template YAML tests pass (39) in all five. The HDF5 lock flake did not occur. - Merge with #570. No file is changed by both PRs. #570 then #664 and #664 then #570 both merge without conflict and give the same tree. The merge order does not matter.
- policyengine-us
main(eae2e2775f). 803 tests fromtest_pinned_tbs_sharing.py, the parameter and reform tests, and the tracer, SPM-isolation and Social Security tests: 803 passed with master core; 801 passed and 2 failed with #664 core, and the same with #664 and #570 (the failures are in SHOULD ADDRESS 1).test_pinned_tbs_sharing.pypasses. The 623 partner tests pass with master core, #664 core, and #664 with #570 core, both untraced and traced (-v). I did not edit partner test files. - Changelog, mergeable state and CI. Two fragments at the top level of
changelog.d/:dependency-map.added.mdandtracer-parameter-reads.fixed.md. GitHub showsMERGEABLEandCLEAN. All 19 checks pass.ruff format --checkpasses.
Not verified
dependency-mapover the whole US test suite, and--population microdata.- policyengine-uk tests with this core.
- policyengine-api (the search found no direct tracer consumer there; the code search hit the GitHub rate limit once, so the consumer list may be incomplete).
- A traced US microsimulation.
- Windows.
…builds no sibling Fails now: the read is recorded at the node with every child's name, and listing those names builds every child, so a child that fails to build raises in the traced run only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was recorded at the node with the names of all its children. Since nodes at an instant build each child on first read (#570), listing those names built every child, so a child that fails to build raised in a traced formula that never read it, and each traced miss built the whole node. The read is now recorded as a key look-up that finds nothing is: at the missing child's path, with no value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fails now: the miss is recorded at the dotted path, which can be a real parameter's path, and replaces that parameter's value in the flat trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The look-up does not descend into the name, so it finds nothing whatever the parameters hold. Recorded at the dotted path, the read could match a real parameter and replace its value in the flat trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Changes since the review of SHOULD ADDRESS 1: the policyengine-us test. PolicyEngine/policyengine-us#11248 changes SUGGESTION 1: an attribute miss with #570. Current SUGGESTION 2: the downstream workarounds. Issues are open in each repository: PolicyEngine/policyengine-app-v2#1598 and PolicyEngine/us-cliffs-2017#9. SUGGESTION 3: scope. This stays one PR. Also changed. An adversarial review covered the #570 merge and the attribute-miss change. It found no wrong value, no read recorded against the wrong simulation, and no tracing view left in a node that other simulations read. It did find one problem: a look-up by a dotted name ( Checks at
|
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at 88dd8e4
The blocker from my last review is resolved. policyengine-us#11248 merged on 2026-11-25 at 11:58am EST, and the isolation test passes with this head. The new commits fix the attribute-miss case with #570 and the dotted-name case correctly. But a second policyengine-us test fails with this core. I missed it in my last review: the same code was already at c968e968. A one-line guard in core fixes it.
Verdict: REQUEST_CHANGES
Earlier items
Item (review at c968e968b7) |
Status at 88dd8e41d5 |
|---|---|
SHOULD ADDRESS 1: test_spm_simulation_isolation.py:253-261 in policyengine-us fails with this core |
Resolved. policyengine-us#11248 changes the test and merged (e93d9b4b). With this head, the file passes on policyengine-us main (28 passed). The file as it was before #11248 still fails (2 failed, [2033] and [2034]). So #11248 had to merge first, and it did. The PR body now has a "Merge order" section. |
| SUGGESTION 1: with #570, a traced attribute miss builds every sibling | Resolved. tracing_parameter_node_at_instant.py:285-296 now records the miss at the missing child's path and does not list the children. The new test test_attribute_look_up_that_finds_no_child_builds_no_other_child uses my failure case. Traced and untraced both return 1, and the broken child is never built. |
| SUGGESTION 2: downstream workarounds | Done. policyengine-app-v2#1598 and us-cliffs-2017#9 are open. |
| SUGGESTION 3: scope | Kept as one PR, with dependency-map in its own commit and changelog fragment. Acceptable. |
| Interaction with #570 | #570 is in master. master (0d66b304) is merged into the branch (68c45a60) with no manual conflict resolution. |
Should address
1. A second policyengine-us test fails with this core. policyengine_core/simulations/simulation.py:1956-1963 (in _calculate, the uprating branch) calls self._record_parameter_read(uprating_parameter.name, ...) on every run. The trace check is inside _record_parameter_read (line 2412), so the arguments are evaluated also when the simulation is not traced.
policyengine-us policyengine_us/tests/core/_social_security_state_backend.py builds a stand-in Simulation. It copies a fixed list of core methods by name (lines 625-660), sets self.trace = False (line 365), and gives a stand-in uprating index that has no .name. With this head, _calculate reaches the new call and fails.
Failure case: policyengine_us/tests/core/test_social_security_input_state_machine.py::TestSocialSecurityInputStateMachine::runTest. Hypothesis finds this sequence: configure_cache(('blacklist', {'social_security_retirement'})), then set_input(component='social_security_retirement', period='2023', route='simulation', amount=0, ...), then a later calculation that uprates.
- Expected (core
master0d66b304): 1 passed (2 of 2 runs). - Actual (this head): 1 failed (3 of 3 runs), with
AttributeError: 'DelegatingSimulation' object has no attribute '_record_parameter_read'.
policyengine-us CI runs this file in its Rest Python groups (make test-other-python-rest-*, which includes tests/core). So the first core release with this PR breaks policyengine-us CI. Core CI does not run it.
Fix: in core, wrap the two uprating calls in if self.trace:. I tried this on this head. The state-machine test then passes (2 of 2 runs) with no policyengine-us change. It also skips the .name look-ups in untraced runs. The adds and subtracts calls (lines 2441-2500) can take the same guard for consistency. A fix only in policyengine-us is harder: adding _record_parameter_read to the copied-method list is not enough, because the test then fails with AttributeError: 'function' object has no attribute 'name'.
What I checked
- New diff.
68c45a60is a clean merge ofmaster. After it, the code change is only inpolicyengine_core/tracers/tracing_parameter_node_at_instant.py, plus tests intests/core/test_tracer_parameter_reads.py.- An attribute miss (
getattrwith a default,hasattr) now goes through_record_missing_key_read, the same path as a key miss. Dunder names stay unrecorded. - A dotted name (
getattr(node, "a.b", 0),node["a.b"]) records nothing. NeitherParameterNodeAtInstant.__getattr__nor__getitem__descends into a dotted name, so this look-up never finds a child. The new test confirms that the real value at the dotted path stays in the flat trace. - A non-dotted miss path cannot match a real child of the same node, because the look-up failed. So it cannot replace a recorded value.
- The
dependency_map.pydocstring and the changelog fragment match the new behavior.
- An attribute miss (
- Core tests at head (Python 3.12). Full suite: 4,316 passed, 4 skipped, 3 xfailed, 0 failed. Country-template YAML tests: 39 passed.
- policyengine-us
main(d8b1deb520, includes #11248) with this head.tests/core/test_spm_simulation_isolation.py: 28 passed. The pre-#11248 version of the file: 2 failed, 26 passed, with "Extra items in the right set" forgov.abolitions.spm_unit_fpgandgov.abolitions.spm_unit_size.- All of
policyengine_us/tests/core: 3,949 passed, 4 failed. One failure is Should address 1. The other 3 (test_capital_gains_response_forms.pyfloat32 round trip, 2 tests, andtest_medicare_cost_part_d_premium.py::test_medicare_cost_bounds_and_irmaa_slope) also fail with coremaster. They come from a newer local pytest (9.2.0, the lock file has 8.4.2), which rejects afloat32tolerance inpytest.approx. They are not from this PR.
- Abolition reads. This PR changes only the trace of core's own check (
simulation.py:1733-1741, now read through_untraced). The check itself and its result do not change. Core createsgov.abolitions.<variable>for each variable (tax_benefit_system.py:239-268). policyengine-us calls this insystem.py:177, and policyengine-us code reads the switches directly intools/social_security_periods.py:51,71,119andvariables/gov/ssa/ssi/eligibility/income/_annual_input.py:22. - Rebase and CI.
masteris an ancestor of the head, so no commit onmasteris missing. GitHub showsMERGEABLEandCLEAN. All 19 checks pass on88dd8e41. The run started on 2026-11-25 at 10:43am EST.
Fails now: adds, subtracts and uprating call _record_parameter_read on every run, and only the method checks whether the simulation is traced. A stand-in simulation without that method, as in policyengine-us's Social Security state tests, then fails; inside adds and subtracts a bare except turns the error into a missing-parameter error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The trace check was inside _record_parameter_read, so every run called it and read the parameter's name. policyengine-us's Social Security state tests build a stand-in simulation that copies only some core methods and has an uprating index without a name, and failed. The callers now check self.trace first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Changes since the review of Should address 1: the policyengine-us Social Security state test. The new test removes Checks at
The description has the same update. |
PavelMakarchuk
left a comment
There was a problem hiding this comment.
Review at c277a33
The Should address item from my last review is resolved. All five core read sites (two uprating, and the list and parameter-held forms of adds and subtracts) now call _record_parameter_read only when the simulation is traced. Traced runs still record these reads, and the policyengine-us Social Security state test now passes with no policyengine-us change.
Verdict: APPROVE
Earlier items
Item (review at 88dd8e41d5) |
Status at c277a33c6f |
|---|---|
SHOULD ADDRESS 1: test_social_security_input_state_machine.py in policyengine-us fails with AttributeError on _record_parameter_read |
Resolved. simulation.py:1956, 2447, 2466, 2487 and 2511 gate each call on if self.trace:. The state-machine test passes in 5 of 5 runs with this head. With the 88dd8e41 code it fails in 2 of 2 runs, so the test still reaches this path. |
Suggestion in that item: also guard adds and subtracts |
Done, in the same commit. |
| Earlier review items (isolation test, attribute miss with #570, downstream issues, scope) | Still resolved. test_spm_simulation_isolation.py passes (28 passed). No code for those items changed in the new commits. |
What I checked
- New diff (
88dd8e41..c277a33c). Onlypolicyengine_core/simulations/simulation.pyandtests/core/test_tracer_parameter_reads.pychange.- Each of the five calls is now inside
if self.trace:. The value read and the uprating,addsandsubtractsarithmetic do not change. The parameter's.nameis now read only when traced. _record_parameter_readwas the only newself.<method>(call insimulation.pyagainstmaster(0d66b304). So an untraced run makes no core method call thatmasterdoes not make.- The docstring at
simulation.py:2410-2417says why the callers gate the call. ruff format --checkpasses on both files. No changelog change is needed: the fix stays inside the existingtracer-parameter-reads.fixed.mdchange.
- Each of the five calls is now inside
- The tracer feature is not weakened. The traced tests for these reads are unchanged and pass:
test_parameter_in_an_adds_list_is_recorded,test_parameter_in_a_subtracts_list_is_recorded,test_parameter_holding_the_adds_list_is_recorded,test_parameter_holding_the_subtracts_list_is_recorded,test_uprating_records_the_index_at_both_instants,test_uprating_records_the_value_held_before_the_index_startsandtest_core_reads_in_a_branch_carry_the_branch_name. When I turned the five guards intoif False:, all 7 of these tests failed. So they still catch a lost read. - New test.
test_untraced_simulation_does_not_call_the_read_recorder(tests/core/test_tracer_parameter_reads.py:885) covers all five cases. With the88dd8e41version ofsimulation.py, all 5 cases fail. With this head, they pass. - Core tests at head (Python 3.12).
tests/core/test_tracer_parameter_reads.py: 64 passed. Full suite: 4,317 passed, 4 skipped, 3 xfailed, 4 failed. The 4 failures are intest_release_tagging.py(the git tag script). They fail the same way withmasteron my machine, and they pass in CI, so they are not from this PR. Country-template YAML tests: 39 passed. - policyengine-us
main(d8b1deb520) with the locked pytest (8.4.2), this head against coremaster.test_social_security_input_state_machine.py: 5 of 5 passed with this head, 5 of 5 passed withmaster.test_spm_simulation_isolation.py: 28 passed with each.- All of
policyengine_us/tests/core: 3,954 passed, 2 failed with each. The same 2 tests fail with both: the Hypothesis teststest_dependent_above_the_line_deductions_invariants.py::test_dependent_deductions_stay_off_the_filers_return_2020and_2025(amn_homestead_credit_refund_household_incomemismatch). They are not from this PR. - The 3
float32pytest.approxfailures from my last review do not occur with pytest 8.4.2. This confirms that they came from pytest 9.2.0, not from this PR.
- CI and merge state. All 19 checks pass on
c277a33c. The run started on 2026-11-25 at 4:12pm EST. GitHub showsMERGEABLEandCLEAN.masteris an ancestor of the head.
Fixes #541. Fixes #542.
Replaces #543 by Pavel Makarchuk, rebuilt on the per-formula parameter view from #574, following the review of 2026-10-27.
Merge order
PolicyEngine/policyengine-us#11248 must merge before the first core release that contains this PR.
test_traced_simulations_record_their_own_parameter_accessesin policyengine-us expectsgov.abolitions.spm_unit_fpgandgov.abolitions.spm_unit_sizein each traced simulation's recorded parameters. Those names come from core's abolition check, which this PR no longer records, so the test fails with this branch. PolicyEngine/policyengine-us#11248 changes the test to leave out each variable's check of its own abolition switch; it passes with coremasterand with this branch.What changes
A traced simulation now records these reads on the node of the variable being calculated:
_children, iterating,in), at the node's own path;getattr(parameters(period).taxes, "future_rate", 0),hasattr(...), orparameters(period).taxes["future_rate"]caught by the formula, at the missing child's path with no value. It builds none of the node's other children;parameters.gov.irs.credits.eitc(period).masterrecords none of these, and US uses them in the federal EITC eligibility formulas among others;values_list,children,clone,brackets), at that node's path with periodeternity;adds,subtractsand uprating. Core makes these calls only when the simulation is traced.Each trace node also records whether its formula ran (
formula_ran).Core's abolition check now reads the parameter tree without a tracing view. When a country package traces its own parameter root, as
policyengine_us.Simulationdoes, the check used to add one read per calculated variable, which made up most of the reads in a US trace. It now adds none.policyengine-core dependency-map -c <package>writes which variables read each parameter and which variables feed which. An output now counts as covered in a file only after the formula it uses at that period has run and the output calculated without an error. Every recorded read becomes an edge, a formula's read of an abolition switch included. The command keeps the tracer that a country package hands to its own parameter root when tracing is switched on, so reads through that root reach the map.Relationship to #543
Kept:
describe_tax_scale,TracingChildren,_record_parameter_read, and thedependency-mapcommand. The command is a separate commit with Pavel as author. Rebuilt commits carry aCo-authored-bytrailer.Dropped, because #574 already does this:
ParameterNode.set_tracing, the tracer write in theSimulation.tracesetter, the save and restore of tracing state in_run_formula, the tree updates inget_branch, and the at-instant cache change.parameter_node.pyis unchanged.Changed from #543:
trace_yaml_tests, withskippedandexcludedcounts;.ymlfiles and nested period mappings are read as the runner reads them;test_tracing_parameter_node_reads_through_to_the_nodefrommasterchanges, becauseview.taxesis now a tracing view ofparameters.taxes.Verification
master(0d66b304, which includes #570) merged into this branchhousehold_net_income, one three-person US household: (variable, parameter) reads recorded, leaving outgov.abolitions, on1936f11bmaster, 1,201 here, none lostmarginal_tax_rate,household_net_incomeandssi, one three-person CA household, against1936f11bWith #570 in both (
master0d66b304against8f7ee588): one CA household,household_net_incomethenmarginal_tax_ratefor 2026, 6 fresh processes per version in rotating order on a shared machine (medians):masterAll 11,495 (variable, parameter, period, branch) pairs
masterrecords outside core's own abolition checks are still recorded, including 462 formula reads of other variables' switches. 1,510 pairs are new. Results were identical in every run.Before #570 was merged, traced US calculations, 5 runs per version, run in rotating order on a shared machine (medians):
masterhousehold_net_income, CA family of four: timemarginal_tax_rate, one TX adult: time866c25casurtax_rateis read bymd_capital_gains_surtax,credits.ctc.phase_out.ratebymd_ctcandcredits.cdcc.ratebyco_cdccTwo adversarial review rounds ran. Round 2 found no missing read and no changed value, but found that a round 1 fix made US traces very large. A third review, of that fix (
1936f11b), confirmed it and found two more bugs, both fixed here with tests:dependency-mapleft out everygov.abolitionsread, including another variable's switch. US SSI income helpers read such switches, and turning one on changes the reading variable.A fourth round reviewed those fixes. It found that recording core's abolition check as a miss for every variable slowed traced US household calculations by about 24%, through an extra full garbage collection, and that
dependency-mapreplaced the tracer a country package had handed to its parameter root, so reads through that root never reached the map. Both are fixed here, by taking core's check out of traces and by keeping that tracer, together with the path of a key that is astr-based enum member. The fixes from the fourth round have had no further adversarial review.Pavel's review of
c968e968found that, with #570, a traced attribute look-up that finds no child listed the node's children, which builds every child, so a child that fails to build raised in the traced run only. That look-up is now recorded at the missing child's path, as a key look-up is, and builds no other child.A fifth adversarial review covered that change and the merge with #570. It found no wrong value, no read recorded against the wrong simulation, and no tracing view left in a node that other simulations read; with a child that fails to build, no traced read path builds more children than the untraced one. It found that a look-up by a dotted name was recorded at the dotted path, which can be a real parameter's, and replaced that parameter's value in the flat trace. Such a look-up now records nothing, with a test. Its other findings are minor and listed under the known limits.
Pavel's review of
88dd8e41found thatadds,subtractsand uprating called the read recorder, and read the parameter's name, on every run, traced or not. policyengine-us'stest_social_security_input_state_machine.pybuilds a stand-in simulation that copies only some core methods and has an uprating index without a name, so it failed with this core. Core now makes those calls only when the simulation is traced (c277a33c, with the failing test first ine2535982). With policyengine-usmain(b3edc044),TestSocialSecurityInputStateMachine::runTestfails in 2 of 2 runs on88dd8e41and passes in 2 of 2 runs onc277a33c.Not run: the full test suite, which is left to CI;
dependency-mapover the whole US suite;trace_microdataon US microdata.Default
dependency-mapselection compared with--every-testEach state's baseline test directory only, on current
policyengine-us:The default can still miss a formula below an output whose own formula has run. Other test directories should supply many of the paths in the last column, but that was not measured. The command says when it skipped tests and points to
--every-test.Reads this PR does not record
gov.abolitions.<variable>). A formula's read of a switch is recorded.simulation.tax_benefit_system.parametersrather than the formula'sparametersargument. In US:foreign_earned_income.py,tools/marital_units.py,ny_ctc_pre_2024.pyandbehavioral_response_measurements.py.get_childand a bracket position past the end of a scale.Known limits left open
These came from review. None is reached by current
policyengine-uscode:2017.5, or a test file that is not UTF-8, stopsdependency-map;testsdirectory gets a traceback;vars(),dir()andrepr()on a tracing view differ from the plain node or record nothing;.namewhen read at an instant.From the fifth review. The first is not reached by the policyengine-us formulas that read
_children; the other two were not checked against policyengine-us:_childrenview keeps the child names from its first use, so afteradd_childon that node at an instant,lenandinmiss the new child, and the view has nocopy()and does not supportreversed();_typfrompandas.isna(node), are recorded as missing children (taxes._typ). Before, the same look-ups were recorded at the node with its child names;AttributeErrorwhile it is built is recorded as a missing child with no value. Traced and untraced results agree.🤖 Generated with Claude Code