Skip to content

Record two parameter reads that bypass the formula's parameters argument - #11251

Merged
anth-volk merged 6 commits into
mainfrom
record-unrecorded-parameter-reads
Nov 27, 2026
Merged

anth-volk merged 6 commits into
mainfrom
record-unrecorded-parameter-reads

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

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 parameters argument. Two formulas read parameters another way:

  1. 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 with get_parameter(simulation.tax_benefit_system.parameters, ...) and core's _uprating_index_value, and no tracer recorded either read.
  2. ny_ctc_pre_2024. The formula reads the federal CTC phase-out threshold from the pinned pre-TCJA tree of its pre_tcja_ctc branch. The read was already recorded, but only because pin_spm_policy copies the source root's tracing fields (trace, tracer, branch_name) into the pinned root.
    • In 2020 cases where New York's recomputed federal AGI differs from federal AGI, the read carried the name of the recomputed-AGI branch, not the calculating simulation's.
    • When the simulation is traced, the formula now wraps the pinned tree in core's TracingParameterNode, with its own simulation's tracer and branch name. Core wraps the parameters argument the same way.

Both changes use only what released core provides: TracingParameterNode (added in PolicyEngine/policyengine-core#574) and FullTracer.record_parameter_access. The policyengine-core>=3.37.2 requirement 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_2024 and foreign_earned_income_exclusion. "Pairs" counts distinct (variable, parameter) pairs.

Household Core Reads, main → branch Pairs, main → branch Difference
NY head of household and child, 2024 3.37.2 22,513 → 22,513 2,674 → 2,674 None
Same, 2020, $300 charitable deduction 3.37.2 30,599 → 30,599 2,618 → 2,618 One read's branch name, ny_recomputed_federal_agi_for_child_credit → default
MA, $10,000 exclusion entered for 2025, calculated for 2026 3.37.2 20,640 → 20,642 2,485 → 2,486 2 index reads and 1 pair added: (foreign_earned_income_exclusion, calibration.gov.cbo.income_by_source.adjusted_gross_income_per_capita)
The same three households #664 6,325, 8,852, 5,211 → +0, +0, +2 1,387, 1,368, 1,200 → +0, +0, +1 Same differences
  • Results: all five variables are identical on main and the branch, traced and untraced, on both cores, over 3 runs of each version.
  • Run time:
    • Whole traced runs varied up to fourfold between runs of the same code under this load, so they can't show a difference this small.
    • Timed directly, each traced formula call costs 0.7 µs more for the NY read through the tracing view (13.28 µs, against 12.58 µs through the pinned root alone). Recording the two section 911 reads costs 0.65 µs.
    • Traced household_net_income for 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 the remaining group.

    • Local: 0.02 s and 0.01 s per case.
    • The process took 23.9 s and peaked at 1.01 GB RSS, mostly loading the model.
  • test_pinned_tbs_sharing.py::test_the_ny_credit_records_its_pinned_read_under_its_own_branch and ::test_the_ny_credit_records_its_pinned_read_without_a_tracer_on_the_pin. They run in the core-heavy group, with the other pinned-system tests.

    • Each test builds a traced and an untraced simulation and compares their results.
    • Local: 4.9 s and 1.9 s.
    • Run alone, the process took 31.9 s and peaked at 1.71 GB RSS. The group's CI resource report will show the increase within the group.
    • The second test clears the copied tracing fields itself. No current route builds a pin without them, so it guards against a later change that clears them.
  • 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 main and that this PR doesn't change:

  • Pinned values are recorded at the requested instant. The pin copies the 2017 values forward to 2035. So the NY read, and the pre_tcja_ctc branch'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.
  • Index reads before the index starts. Before the index's first value (2015-01-01), the read is recorded at the requested instant with that first value. Core's own uprating records it the same way.

axiom: n/a: tracing only; no policy, parameter or result change

🤖 Generated with Claude Code

anth-volk and others added 6 commits November 25, 2026 23:29
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>
@anth-volk
anth-volk marked this pull request as ready for review November 27, 2026 14:51
@anth-volk
anth-volk merged commit 98e8521 into main Nov 27, 2026
35 checks passed
@anth-volk
anth-volk deleted the record-unrecorded-parameter-reads branch November 27, 2026 19:26
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