Repository navigation
Record two parameter reads that bypass the formula's parameters argument - #11251
Merged
Merged
Conversation
The legacy fallback of foreign_earned_income_exclusion reads the per-capita AGI index from the system's own tree, so no tracer records either read. The test expects both reads on the formula's trace node, in the calculating simulation's tracer and under its branch name. It fails until the formula records them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fallback reads the per-capita AGI index from the system's tree, which no tracer sees. When the simulation is traced, record both reads in its tracer under its branch name, with the instants and values it used, as core records the index reads of its own uprating. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ny_ctc_pre_2024 reads the federal CTC phase-out threshold from its branch's pinned tree. Only the tracer the pin copies from its source root records that read today: in the 2020 recomputed-AGI case it carries the other branch's name, and a pin without the copied tracer records nothing. The tests expect the read on the formula's trace node under the calculating simulation's branch name in both cases, with untraced results unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the simulation is traced, wrap the branch's pinned tree in core's per-call tracing view with the calculating simulation's tracer and branch name, as core wraps a formula's parameters argument. The read no longer depends on the tracer a pin copies from its source root, and in the 2020 recomputed-AGI case it now carries the calculating simulation's branch name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No current route builds a pin without the copied tracer; the test clears the fields itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A traced simulation records each parameter read on the trace node of the variable whose formula made it. Planned work will use that record to reuse a baseline run's values in a reform run, for every variable the reform can't affect. A read the tracer misses would let a reform reuse a value it changed. Core records the reads a formula makes through its
parametersargument. Two formulas read parameters another way:foreign_earned_income_exclusion. When only an earlier year's amount is entered, with no Form 2555 detail inputs, the formula carries that amount forward by the per-capita AGI index. It reads the index withget_parameter(simulation.tax_benefit_system.parameters, ...)and core's_uprating_index_value, and no tracer recorded either read.ny_ctc_pre_2024. The formula reads the federal CTC phase-out threshold from the pinned pre-TCJA tree of itspre_tcja_ctcbranch. The read was already recorded, but only becausepin_spm_policycopies the source root's tracing fields (trace,tracer,branch_name) into the pinned root.TracingParameterNode, with its own simulation's tracer and branch name. Core wraps theparametersargument the same way.Both changes use only what released core provides:
TracingParameterNode(added in PolicyEngine/policyengine-core#574) andFullTracer.record_parameter_access. Thepolicyengine-core>=3.37.2requirement is unchanged. Both changes also work with core at the head of #664 (88dd8e41). Untraced simulations run the same code as before.Measurements
These are local measurements on macOS. Other processes kept the load average at 19–27.
Recorded reads come from traced calculations of
household_net_income,income_tax,state_income_tax,ny_ctc_pre_2024andforeign_earned_income_exclusion. "Pairs" counts distinct (variable, parameter) pairs.main→ branchmain→ branchny_recomputed_federal_agi_for_child_credit→defaultforeign_earned_income_exclusion,calibration.gov.cbo.income_by_source.adjusted_gross_income_per_capita)mainand the branch, traced and untraced, on both cores, over 3 runs of each version.household_net_incomefor these households takes 1–9 s.Test plan
Each new test failed before its fix: the tests are committed before the changes.
test_foreign_earned_income_exclusion_leaves.py::test_traced_legacy_carry_records_both_index_reads(main simulation and a named branch). It runs in theremaininggroup.test_pinned_tbs_sharing.py::test_the_ny_credit_records_its_pinned_read_under_its_own_branchand::test_the_ny_credit_records_its_pinned_read_without_a_tracer_on_the_pin. They run in thecore-heavygroup, with the other pinned-system tests.All four tests pass on core 3.37.2 and on Separate Additional Medicare Tax parameters by payroll / self-employment #664 (
88dd8e41). Only these tests were run locally, by node ID.They are Python tests because YAML tests can't inspect traces.
YAML tests from an external source: not applicable (no policy change)
Source-conflict register entry: not applicable
make format(ruff format and ruff check)Changelog fragment in
changelog.d/Self-review
The author and the reviewer are both Claude sessions, so this is a self-review.
One adversarial review round, by a separate reviewer, found no bug in the diff. It reported two limitations that exist on
mainand that this PR doesn't change:pre_tcja_ctcbranch's own reads, are recorded at the requested instant with the 2017 value. A reform of the 2017 entry changes the result, but no recorded read names a 2017 instant. A reuse step that matches a reform's changes by parameter path finds the dependency; one that matches by path and instant would not.axiom: n/a: tracing only; no policy, parameter or result change
🤖 Generated with Claude Code