Skip to content

Score post-export baselines in one merged pass and pre-OBBBA law once - #1725

Merged
anth-volk merged 11 commits into
mainfrom
claude/post-export-merged-baseline-sweep-3b4e0c
Nov 26, 2026
Merged

anth-volk merged 11 commits into
mainfrom
claude/post-export-merged-baseline-sweep-3b4e0c

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Post-export scoring now computes the baseline for all five post-export stages in one pass over the written H5's household batches, instead of one pass per stage. Reform validation now scores the pre-OBBBA state once for both OBBBA groups. Data outputs are unchanged byte for byte. Refs microcosm#1595.

What changes

One shared baseline pass (tools/build_us_fiscal_refresh_release.py)

  • Before, each of the five stages ran its own baseline pass over every household batch: the reform-coverage smoke, reform validation, demographics, and the SSI/Social Security and Medicare IRMAA held-out reports. That is 5 × 177 = 885 batch engines on a national export.
  • _open_post_export_scorer now registers the baseline plans recorded before export. When the first registered stage is opened, _HouseholdBatchedPostExportScorer._baseline_for scores the union of those plans in one pass, in ascending period order: 177 batch engines.
  • Each stage is served exactly the keys of its own recorded plan. Merged values are dropped once no stage still to be served planned them.
  • Fallback: if the shared pass raises, every stage scores its own plan as before. A key that only one held-out report planned therefore still fails only that report, with the same error, and its writer still writes the "unavailable" payload.
    • The fallback runs after a full garbage collection and outside the exception handler, so the failed pass's partial arrays are freed first.
    • It also holds when the error's text cannot be formatted.
  • Refusals that still apply:
    • each served baseline refuses keys outside its own plan, including through the new prefetch;
    • a registered stage opened with a plan other than its recorded one is refused, including an empty recorded plan and after a fallback;
    • the batch-order join in _concatenate_post_export_parts, the population-aggregate refusal and the baseline-branch-reader refusal are unchanged, and now run on every engine of the shared pass.
  • Build log: stages served from the shared pass print baseline served from the merged pass. A fallback prints Post-export merged baseline plan failed.

Pre-OBBBA law scored once (packages/microcosm-build/src/microcosm/build/us_runtime/reform_validation.py)

  • stacked_obbba_effects stacks every OBBBA group from the same pre-OBBBA state, in which every provision is reverted.
  • That state used to be simulated once per group: income tax in 2026 (17 provisions) and estate tax in 2026 (1 provision).
  • It is now one simulation. released_weighted_totals asks it for both totals in ascending period order.
  • The release's batched reform offers a new prefetch, which scores several keys in one pass. The engine-free run counts a prefetch as one pass, so the planned count still equals the passes run.
  • A plain policyengine-us Microsimulation has no prefetch, so whole-file callers read the totals one at a time as before.

Guard sweep (tools/sweep_us_post_export_scoring.py)

  • The baseline worker registers its plans, so it scores them in one shared pass, as the release does.
  • Its reform workers still score each recorded request in a pass of its own.

Recorded fields (both approved by Anthony before implementation)

  • Each stage's baseline_passes in the manifests' post_export_scoring block (and the smoke's copy in reform_coverage_smoke.json) stays 1. It now means the one pass the stage's baseline came from, shared unless the shared pass failed. No field was added, so only the build log shows a fallback.
  • Reform validation's reform_passes and reform_systems go from 54 to 53; reform_validation.json is unchanged.
    • tools/probe_us_post_export.py's plan comparison against a release built before this change will report 53 against 54.
  • POST_EXPORT_SCORING_METHOD is unchanged; its comment now says that regrouping keys into fewer passes, with every value byte-identical, keeps it.

Evidence

Before implementing: on the 8-household fixture H5 in 3 batches, one baseline pass over the 97 distinct keys served all 103 per-stage arrays byte-identical (values, weights and dtypes) to the five separate passes, in both key orders.

Byte-identity comparison on the fixture H5, origin/main against this branch:

  • Both runs run every post-export stage the way _certify_us_build does, with a calibration fit covering every in-sample reform.
  • The fixture is 3 batches on policyengine-us 2.2.1.

Results:

  • Output files: reform_coverage_smoke.json, reform_validation.json, demographics.json, us_ssi_social_security_holdout.json, us_medicare_irmaa_holdout.json and the plan record in calibration_diagnostics.json are byte-identical.
  • Served baseline arrays: all 206 match byte for byte, with dtypes. These are the values and weights of all 103 stage keys.
  • Manifests' post_export_scoring block: identical, except reform validation's reform_passes and reform_systems (54 → 53). The planned count also goes from 54 to 53.
  • Passes: 1 baseline pass instead of 5, and 96 reform passes instead of 97.
  • Commits measured: the after-run measured 34be2f7be. Later commits change only the fallback path, tests and docs.

Peak memory (RSS) on the fixture:

  • Baseline phase alone, the phase this change alters. Each run scores every stage's baseline, then stops:
    • main: 3.65, 3.80 and 3.44 GB (three runs);
    • this branch: 2.87 and 3.24 GB (two runs).
  • Full run, one each: main 10.02 GB, this branch 11.08 GB.
    • After the baseline phase, this branch was lower: 1.87 GB against 3.02 GB.
    • The gap opens during the reform passes, whose code this change leaves alone apart from dropping one pass. That memory grows as each reform's tax-benefit system is built (microcosm#456).
    • The after-run shared the machine with other sessions' test runs (load average up to 26 on 10 cores), and macOS compresses memory under pressure. So this single comparison does not settle the full-run peak.
  • Timing: elapsed times varied 2–4× with that load and are not comparable.
  • National export: no national or Modal run was made.

New tests:

  • Engine-free (fake engine):
    • outputs, served arrays and the manifests' block are equal between the shared pass and separate passes;
    • _open_post_export_scorer registers the plans;
    • the plan refusals;
    • merged values are dropped as stages are served;
    • the fallback, including its memory release and an error with no text;
    • the log line;
    • prefetch pass counting;
    • the pre-OBBBA state is one pass (53 with a release fit);
    • the order in which the pre-OBBBA totals are read;
    • the sweep worker's registration.
  • Slow, on policyengine-us:
    • test_merged_baseline_and_shared_pre_obbba_pass_are_byte_identical checks that the shared baseline pass, and one pre-OBBBA pass for both groups, give the bytes of separate passes. One fixture person holds a taxable estate so that estate tax is nonzero.
    • test_shipped_baseline_plans_match_whole_file_policyengine_us now serves the shipped plans from the shared pass.
    • Both tests check from the pass labels that exactly one shared pass ran.
  • test_main_writes_diagnostics_before_post_calibration_gate_failure's fake scorer gains baseline_from_merged_pass.

Only the tests this change added or modified were run, each by node ID; all pass.

Memory and timing

  • The shared pass holds every stage's baseline arrays at once, from the first stage's start until each stage has been served. On the fixture that is 12,027 bytes, against 8,418 for reform validation's plan, which was the largest set held before (about 1.4 times).
  • Each batch engine of the shared pass computes all 97 keys, against at most 75 before.
  • The shared pass runs inside the first stage opened (the smoke unless skipped). The build telemetry's time for that stage now includes every stage's baseline work.

Review

Three rounds of adversarial review by subagents. None found a change to data outputs. Fixes from each round are in their own commits, tests first:

  • Round 1:
    • the fallback ran inside the exception handler;
    • refusal gaps;
    • the log line;
    • period order for whole-file engines;
    • slow tests that could not detect a fallback;
    • zero estate tax on the fixture.
  • Round 2: a fake scorer in an existing builder test lacked the new attribute, which made two of that test's cases write "unavailable"; a full collection was added before the fallback; doc gaps were filled.
  • Round 3: the fallback flag was set after printing the error; the method comment was reworded.

Not in this PR

Docs: the "Post-export scoring" section of docs/us-release-build-rule.md, and changelog.d/1595-post-export-merged-baseline-pass.changed.md.

🤖 Generated with Claude Code

anth-volk and others added 10 commits November 25, 2026 00:17
…ling)

Engine-free tests for microcosm#1595's post-export scoring change:

- the five planned consumers' baselines come from one batch-outer pass
  over the union of their plans, with outputs, served arrays and the
  manifests' post_export_scoring block unchanged;
- _open_post_export_scorer registers the recorded plans;
- each served baseline still refuses keys outside its own plan;
- a consumer opened with a plan other than its registered one is refused;
- merged values are dropped once no unserved consumer planned them;
- a failed merged pass falls back to each consumer's own pass;
- prefetch scores several keys of one reformed simulation in one pass,
  counted once by the dry run;
- reform validation scores the pre-OBBBA state once (53 passes with a
  release fit, from 54);
- the guard sweep's baseline worker registers its plans.

A slow policyengine-us test checks byte identity of the merged baseline
and of the shared pre-OBBBA pass against separate passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Post-export scoring ran one baseline pass over the written H5's household
batches for each of its five stages (the reform-coverage smoke, reform
validation, demographics and the two held-out reports): 885 batch engines
on a national export. The scorer now registers the plans recorded before
export, scores their union in one pass in ascending period order, and
serves each stage exactly its own keys, dropping merged values once no
stage still to be served planned them (177 batch engines). Each served
baseline still refuses keys outside its own plan. A stage opened with a
plan other than its registered one is refused. If the merged pass raises,
every stage scores its own plan as before, so a key that only one
held-out report planned fails that report alone. Each stage's recorded
baseline_passes stays 1.

Reform validation scored the pre-OBBBA state (every OBBBA provision
reverted) once per OBBBA group. It now asks one simulation for both
groups' totals; the batched reform's new prefetch scores them in one
pass, and the dry run counts that pass once. Reform validation's
recorded reform_passes and reform_systems drop from 54 to 53;
reform_validation.json is unchanged.

The guard sweep's baseline worker registers its plans too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The slow tests record each pass's label, so a fallback to separate
  passes fails them, and the fixture gives one person a taxable estate so
  the shared pre-OBBBA pass's estate tax is nonzero.
- A failed merged pass frees its partial values before the fallback pass.
- A consumer is refused a plan other than its recorded one when the
  recorded plan is empty, and after the merged pass has failed.
- The build log says when a consumer's baseline came from the merged pass.
- The served baseline's prefetch refuses keys outside the plan.
- reform validation reads the pre-OBBBA state's groups in ascending period
  order on a simulation without prefetch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The fallback after a failed merged pass runs outside the exception
  handler, so the failed pass's traceback and the per-batch values its
  frame collected are freed before the first consumer's own pass.
- The scorer keeps every registered plan for its refusal, so a consumer
  whose recorded plan was empty, or any consumer after a failed merged
  pass, is refused a plan other than its recorded one.
- A consumer served from the merged pass says so in its build log
  summary; its recorded baseline_passes stays 1.
- The served baseline accepts prefetch, refusing keys outside its plan,
  as the dry run's recorder accepts it.
- reform validation reads the pre-OBBBA state's groups in ascending
  period order, so a simulation without prefetch never computes an
  earlier period after a later one.
- The build rule doc says how a fallback shows in the build log, that
  the merged pass holds every stage's baseline arrays at once, that the
  smoke's telemetry stage time now includes every stage's baseline
  work, and which plans the sweep tool's merged pass covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The release harness's fake scorer gives its consumers
  baseline_from_merged_pass, which _score_post_export_consumer now reads;
  without it the two held-out reports in the green harness runs wrote
  "unavailable".
- A failed merged pass's partial values held in a reference cycle are
  freed before the fallback pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A full garbage collection runs before the fallback pass, so a failed
  merged pass's values held in a reference cycle are freed first.
- The build rule doc says the merged pass runs in the first stage opened
  (the smoke unless skipped), that its batch engines compute every
  stage's keys, that a failed merged pass costs its time on top of every
  stage's own pass, and that tools/probe_us_post_export.py still scores
  each stage's baseline separately.
- The changelog notes that the probe tool's plan comparison against a
  release built before this change reports reform validation's 53
  against 54.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A merged-pass error whose text cannot be formatted still leads to each
consumer's own pass, and the merged pass is not tried again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A failed merged pass is marked failed before its error is printed,
  and an error whose text cannot be formatted prints its type, so the
  fallback holds and the merged pass is not tried again.
- POST_EXPORT_SCORING_METHOD's comment says a regrouping of keys into
  fewer passes that leaves every value byte-identical keeps the method.
- The test helper module's docstring names the merged pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source-spine blindness check treats an unannotated parameter as a
possible table and refuses an index into it, so the lambda key failed
test_runtime_population_operators_are_source_spine_blind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts resolved by keeping both sides:
- _BatchedPostExportReform keeps main's finished-reform refusal and its
  removal of each reform's rule modules, and this branch's prefetch, which
  scores several keys of one reform in one pass;
- the scorer keeps main's open-reform tracking and this branch's registered
  baseline plans;
- the test helper _scorer takes both baseline_plans and variables_dir;
- both branches' new tests are kept. The slow pre-OBBBA test reads the
  shared pass's values before opening the next reform, since opening it now
  finishes the earlier one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@juaristi22 juaristi22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 44e418562. The shared baseline pass and the single pre-OBBBA pass leave every scored value unchanged, and the branch merges cleanly with current main. Nothing on our side blocks it.

A quick check on order: is this still going in after #1722? The two conflict in tools/build_us_fiscal_refresh_release.py and docs/us-release-build-rule.md, and #1722's recorder has no prefetch, so the rebase needs to add one that counts the pre-OBBBA state as a single pass and to re-pin #1722's planned reform-validation count.

What I checked

  • Each stage gets exactly its recorded keys, merged values are dropped once no remaining stage needs them, and a failed shared pass falls back to per-stage passes.
  • _assert_reform_keeps_baseline_responses now runs once per period instead of once per key. It reads only the period, so it refuses the same reforms.
  • The dry run counts a prefetch as one pass, as the scorer runs it.
  • None of the 75 commits main has gained since your base touch the post-export code, reform_validation.py, the sweep or the lock.
  • 135 engine-free tests and the two slow byte-identity tests on policyengine-us 2.2.1 pass locally, and CI is green.

The next national build will show the shared pass's peak, since each batch engine now computes 97 baseline keys instead of at most 75; that needn't hold up the merge.

#1722's engine-free dry run records every request through
_RecordingPostExportSimulation and counted one reform pass per request.
This branch's prefetch scores several keys of one reformed simulation in
one pass, so the merged recorder takes prefetch too:
- it records the keys not asked before in ascending period order, as
  _BatchedPostExportReform.prefetch computes them, and counts the call as
  one pass (_dry_run_post_export returns that count);
- it refuses a prefetch of a reformed simulation after the next one opened,
  as it refuses a calculate.

Re-pins for the shared pre-OBBBA state, which reform validation now reads
for both OBBBA groups from one simulation in one pass: the planned
reform-validation count on #1722's fixture goes from 64 to 63 for the same
64 requests, and the descriptor test allows that one shared pass and
simulation. The recorded output digests are unchanged. A new test covers
the dry run's prefetch order, count and refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk

Copy link
Copy Markdown
Contributor Author

Thanks for the review. #1722 merged first, so this PR took it in (855a37d): the dry run's recorder now takes prefetch, records its new keys in ascending period order and counts the call as one pass, and #1722's planned reform-validation count is re-pinned from 64 to 63 for the same 64 requests. The output digests #1722 pinned are unchanged. On the peak: agreed. The post-export section of docs/us-release-build-rule.md records the larger key count (97 against 75), and the next build's telemetry will show the shared pass's peak.

@anth-volk
anth-volk merged commit 096dfd2 into main Nov 26, 2026
12 checks passed
@anth-volk
anth-volk deleted the claude/post-export-merged-baseline-sweep-3b4e0c branch November 26, 2026 18:19
juaristi22 added a commit that referenced this pull request Nov 26, 2026
…nd, the table_copies hash binding, and US and NZ changes (#931)

Main took five pull requests since e29843d: #1734 (New Zealand's receipt
target cap), #1749 (staging hands a run's files over at its start and its
results at its end, with no upload interval), #1761 (the UK stage,
population and calibration hashes bind microcosm.frame.table_copies), #1725
(the US post-export merged baseline sweep) and #1750 (the US base engine
lock checked once). No UK feed or engine pin moves.

Eight files conflicted.
- uk_runtime/graph_calibration.py, graph_kernels.py and graph_population.py:
  #1761 binds table_copies into the stage, population and calibration
  hashes; this branch already binds it, as frame_table_copies, in every UK
  kernel that computes through it (bbe3633), so the merge keeps this
  branch's side. The population kernels #1761 binds are gone on the
  clone-first spine, so its new test in test_uk_kernel_frame_copies holds
  the national problem kernel, which copies through context_frame, in their
  place, with the pool checkpoint kernel as the control.
- test_uk_rowwise_candidate: #1749's dense role without an upload interval;
  this branch's removal of the constituency vintage stays.
- The US seed map and seed protocol, the loader's golden spec vector and
  the US pool test's spec pin, computed on the merged tree, and the US F0
  coverage report, regenerated (--check passes, and so does the US
  re-pinner's --check).

The UK gate contract pins, the stage table and the coverage manifest are
current on the merged tree.

Checks: with policyengine-uk hidden, as in CI's engine-free job, the
tests main's five pull requests change, the UK graph's binding rules,
the kernel frame copies (main's new test among them), the clone-first
nesting, the transport binding rule and identity, the graph parity pins,
the spec-engine loader and the Child Benefit stage and gate tests
(2,729 pass); the US coverage report and pins (--check); and the UK gate
pins, the stage table and the coverage manifest (--check).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants