Skip to content

Give comparison-path US baselines their stored plan so they load the precomputed baselines - #1138

Merged
anth-volk merged 6 commits into
mainfrom
v2-cache-comparison-baseline-plan
Nov 27, 2026
Merged

anth-volk merged 6 commits into
mainfrom
v2-cache-comparison-baseline-plan

Conversation

@anth-volk

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

Copy link
Copy Markdown
Contributor

Fixes #1137

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Changelog

  • This PR adds a changelog fragment, changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed.

Summary

Since #1072, the precompute plans the US national baselines with resolve_simulation_output_plan, the plan every run of a simulation stores. The comparison-path coordinator (ReportCoordination) serves shadow comparisons with production jobs and the operator-only POST /internal/stage12/reports. It still gave its baseline the report's own plan, so each baseline region-group segment computed a cache key the precompute never stores, and calculated the baseline (#1137).

  • ReportCoordination.child_output_plan gives the baseline its stored plan whenever that plan holds every column the report reads from the baseline (side_read_plan). Otherwise the baseline keeps the report's plan, as for a report with include_cliffs: true, whose cliff columns the stored plan lacks. The reform always keeps the report's plan.
  • stored_plan_holds (output_planning.py) is the check: every entity the read plan names is in the stored plan, and its materialized columns are a subset of the stored entity's.
  • CoordinationCore.stored_output_plan resolves a simulation's stored plan (the stored_plan_resolver seam, or resolve_simulation_output_plan). Both coordinators now use it; ReportRunCoordination.child_output_plan behaves as before.
  • Results are unchanged. The shared aggregation already reads a side stored under its own plan: it fills the labour-supply responses the side doesn't store with zeros, and validates against the report's plan. The report-run path has relied on this since Let Stage 12 report runs share simulation runs, each storing its own simulation's output #1072. The baseline's file gains the two copied inputs self_employment_income and weekly_hours_worked.
  • Behaviour change. should_segment_simulation reads each child's own plan. A comparison report whose reform turns on a labour-supply response, and whose baseline's own policy turns none on, now splits its US national baseline into 20 region-group segments instead of calculating it in one container. For a current-law baseline in a precomputed year (2025–2027), those segments load the precomputed files.
  • Stored files are reused as they are: the files in the image are already stored under the stored-plan identity, and the deploy check loads one on every deploy. No precompute run is needed.
  • Docs: the migration doc (stage-12-modal-worker-foundation.md) and the observability skill now describe each child's own plan.

Offline, from the installed bundle: a US national 2026 report raising the CTC base amount to $3,000 had a group-0 baseline segment identity of stage12-bl1-6bf58faeedaedc36 before this change. It now has stage12-bl1-928929ee9ffcc2a4, the precomputed one. Measured value of a hit, from production telemetry: about 470 segment-seconds of compute and about 58 s of the baseline's elapsed time per current-law US national report.

Known, not changed here

  • stage12_qualification.qualify_report_parity, the operator parity tool, still plans both sides with the report's plan. Its receipts therefore don't match the comparison path's baseline input digest. They already differed from the report-run path's since Let Stage 12 report runs share simulation runs, each storing its own simulation's output #1072.
  • A comparison report whose coordinator call is restarted after this deploys could fail once. The restarted call would re-plan its baseline under the new plan, and create_or_resolve_simulation would then collide on the child's primary key. This affects only shadow or operator reports in progress during the deploy, as any change to plan selection would.

Testing

Tests were run one at a time by node ID, not as a suite.

  • New file tests/test_stage12_comparison_baseline_cache.py, committed failing before the change:
    • test_comparison_report_baseline_segment_uses_the_precomputed_identity: failed with …6bf58faeedaedc36 against …928929ee9ffcc2a4; passes now.
    • test_a_labour_supply_reform_splits_its_baseline_into_precomputed_segments: failed (should_segment_simulation false); passes now.
    • test_a_baseline_stored_under_its_own_plan_gives_the_same_report_columns[reform_turns_responses_on]: failed (the baseline was given the report's plan); passes now. [no_responses] was added with the review fixes.
    • test_a_cliff_report_keeps_the_report_plan_for_its_baseline and test_the_reform_keeps_the_report_plan[…] pass both before and after the change; they check the cases that keep the report's plan.
    • The first four plan with the installed bundle and US model and load no dataset.
  • Changed: test_stage12_coordinator.py::test_coordinator_starts_both_children_before_waiting_and_aggregates and test_stage12_coordination.py::test_default_output_plan_resolver_measures_its_own_stages now pass a stored plan resolver, so planning a baseline loads no country model. Both pass.
  • Ruff format and check (0.15.22) on the changed files; Pyright 1.1.414 on the changed modules (0 errors); scripts/run_quality_guards.py; check-changelog-fragment.sh.
  • Two rounds of adversarial review found no bug in the new behaviour. Their documentation and test findings are fixed in 32bf311b and d8b2e999.
  • After Move the v2 report app's cache onto the prebuilt-file level handlers #1136 and Restore the v2 simulation workers from Modal memory snapshots with their country's models loaded #1142 merged, main was merged into this branch (no text conflicts). The identity tests now build the segment's RunScope, which qualifying_cache_identity takes since Move the v2 report app's cache onto the prebuilt-file level handlers #1136, as the segment worker does. On the merged tree all 9 test cases above pass. With main's report_coordination.py swapped back in, the identity test still fails with …6bf58faeedaedc36 against …928929ee9ffcc2a4.

🤖 Generated with Claude Code

anth-volk and others added 6 commits November 27, 2026 21:02
The comparison-path coordinator (ReportCoordination), which serves shadow
comparisons and the operator route, gives its baseline the report's plan,
so a current-law US national baseline segment computes a cache identity
the precompute never stores. These tests expect the stored plan instead
whenever it holds every column the report reads from the baseline: the
CTC report's group-0 segment gets the precomputed identity (it gets
stage12-bl1-6bf58faeedaedc36, not stage12-bl1-928929ee9ffcc2a4), a
labour-supply reform splits its baseline into segments with that identity,
and a baseline stored under its own plan is aggregated with the same
values as under the report's plan. A cliff report's baseline and every
reform keep the report's plan.

Two tests that build the coordinator's dependencies directly now pass a
stored plan resolver, so planning a baseline loads no country model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…port's reads

Since the precompute plans the US baselines as simulation runs store them
(resolve_simulation_output_plan), only the report-run coordinator's
baselines found them. ReportCoordination, which serves shadow comparisons
and the operator route, gave each child the report's plan, so every US
national baseline segment computed a cache identity the precompute never
stores and calculated its baseline.

ReportCoordination.child_output_plan now gives the baseline its stored
plan whenever that plan holds every column the report reads from the
baseline (side_read_plan, checked by the new stored_plan_holds), and keeps
the report's plan otherwise, as for include_cliffs reports. The reform
always keeps the report's plan. The shared aggregation already reads a
side stored under its own plan, zero-filling the labour-supply responses
it doesn't store. Both coordinators now resolve a stored plan through
CoordinationCore.stored_output_plan.

A US national baseline is split into region groups from its own plan, so
a comparison report whose reform turns a labour-supply response on now
splits its current-law baseline into 20 segments, which find the
precomputed files.

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

Review found passages that still said both children get the same plan,
that segmentation follows a shared plan, and that the precomputed files
serve only report runs; they now describe each child's own plan. The
changelog and the migration doc now say that any US national baseline
whose own policy turns no response on is split when its reform turns one
on, and that only the precomputed years and SPM selection load from the
cache. The observability skill describes the stored-plan resolution inside
stage12_child_input_planning.

The aggregation test now covers a report turning no response on, where
the baseline's file holds columns neither side reads, and its name says
what it checks: the aggregation receives the same values in every column
the report reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The observability skill said the nested planning operations appear where
a child is given its stored plan; the comparison-path coordinator resolves
the baseline's stored plan before checking it, so a baseline that keeps
the report's plan records them too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #1136, qualifying_cache_identity takes the run's RunScope (country,
year, region and dataset selection) in place of the dataset-default flag
and the scoping strategy. The test now builds it as the segment worker
does. Against main's coordinator the identity test still fails with
stage12-bl1-6bf58faeedaedc36 against stage12-bl1-928929ee9ffcc2a4.

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 20:43
@anth-volk
anth-volk merged commit 07a7321 into main Nov 27, 2026
28 of 30 checks passed
@anth-volk
anth-volk deleted the v2-cache-comparison-baseline-plan branch November 27, 2026 20:43
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.

v2 report app: comparison-path US national baselines never load the precomputed baselines

1 participant