Repository navigation
Fix structural reforms for their requested periods - #2670
juaristi22 wants to merge 9 commits into
Conversation
Aggregate impact on certified data: passBase Checks: 0 broken by this change, 1 failing on both sides, 0 fixed. Moves flagged for review: 0 (thresholds in Notes
Moves flagged for reviewNone. Spending by benefit and service
Caseloads
Household net income by decileNo household's net income changes in any year. No change in any year: receipts by tax head; government balance, each component counted once; model totals; household income totals; population; poverty rates; people in poverty; inequality; mean household net income in each side's own deciles; standard reform costings (change in gov_balance); standard reforms: change in each reform's target. Checks failing on both base and head (1)
Counted-once checkThe check raised each of 92 components by £1 per unit in 2026-27 and read every head of its totals household by household: its own head must rise by exactly £1, no other tax head may move, no other benefit may rise, and the model's own total must move by what its heads moved. A response that is not finite breaks every rule. The check measures a head that breaks a rule twice more: once holding every other head at its baseline value, and once holding every other head at its value after the first £1 while the component rises again. The head fails where either measurement still shows the response. The check cannot hold a head at a value that is not finite. In each unit where another head is not finite after the first £1, it holds that head at its baseline value, and the second measurement judges no household the unit belongs to. There a head fails wherever it first broke a rule, or wherever the check could not confirm whether its response contains the component. 0 failed and the check skipped 0.
Provenance
Dataset: Receipts by tax head: head levels
Spending by benefit and service: head levels
Caseloads: head levels
Government balance, each component counted once: head levels
Model totals: head levels
Household income totals: head levels
Population: head levels
Poverty rates: head levels
People in poverty: head levels
Inequality: head levels
Mean household net income in each side's own deciles: head levels
Standard reform costings (change in gov_balance): head levels
Standard reforms: change in each reform's target: head levels
|
|
Review of #2670 at The fix works: the four structural switches now follow the year being calculated, and a time-limited switch stops at its end date. One existing test on main has to change with it, which is why CI is red. I'd also like the Core floor raised and the aggregate impact job re-run before this leaves draft. What I checked Household probe, couple with one child in England (HITC: £50,000 + £30,000; Marriage Allowance: £80,000 + £0),
So base samples the switch once at 2025 and applies the result to every year, as #1800 says. Head reads it per year, and the The new test file fails on base (46 of 53 fail, with head's test file copied onto Findings
Question (for Max, not a finding): about 520 of the 598 lines added to Verdict: not ready to leave draft yet. 1 must change; 2 and a green 3 should come with it. Comment only, since this is a draft. What I ran: in a fresh venv (Python 3.13, Core 3.33.2 from the lock), one process, no 🤖 Generated with Claude Code |
f5deeeb to
a63f18e
Compare
|
Pushed commit
The rebase onto Scoped Ruff formatting and lint passed. Local model tests, including the 12 new cases, have not run locally. Matching-head GitHub CI is underway, and the Aggregate impact result remains required. I am keeping this PR in draft until the Aggregate impact check and all applicable checks succeed. I have not opened a separate US issue. |
|
Round 2 at Every round 1 finding is resolved, CI is green and Aggregate impact passes. The one thing still open is the design question from round 1, which needs an answer from @MaxGhenis before I approve. That point has got bigger since round 1. Status of round 1 findings
Still open
New findings: none. Verdict: no open must, but one should (6) is waiting on Max, so I am not approving or adding this to the merge queue at this head. If Max says merge as is, I will check CI again and approve at What I ran: I used a fresh worktree and venv (Python 3.13, Core 3.33.2 from the lock, dev extras) and ran one process with no
I did not run the full suite locally. I read the new tests and the 🤖 Generated with Claude Code |
|
Round 3 at What the merges changed Against merge base
Both cover Earlier items
How the switches choose their years (checked at this head)
So a one-year request stays in its year on each side, the order of queries doesn't matter, two reforms with different years don't interfere, and the baseline is untouched. A fiscal-year key (6 April to 5 April) lands on that fiscal year because Which results move Default-baseline results don't move: every contrib switch defaults to false, and Aggregate impact agrees. Reform runs move in four ways:
I searched the PolicyEngine org for callers. New findings: none. Checked and fine
CI at Verdict: no open must or should of mine. The scope decision in 6 is still with Max. If he says merge as is, I have nothing further at this head. What I ran: a fresh clone and 🤖 Generated with Claude Code |
There was a problem hiding this comment.
One new issue at c658df33c, which arrived with the main merges after round 3. The scope question for Max from round 3 is still open and separate.
Expanded MA still applies in years when its switch is off, through marriage_allowance_reduction_at_stake
Main's 6c91a3c added marriage_allowance_reduction_at_stake, and create_expanded_ma_reform now updates it (policyengine_uk/reforms/cps/marriage_tax_reforms.py:105-123, :129). The period-aware wrapper routes only meets_marriage_allowance_income_conditions and marriage_allowance (marriage_tax_reforms.py:349-356). apply_period_aware_reform applies the whole reform (reforms.py:96) and re-routes only those two. So the reform's where(meets_expanded_ma_conditions, 0, ...) formula runs in every year. With the default max_child_age of 0, meets_expanded_ma_conditions is True for everyone (marriage_tax_reforms.py:43). In inactive years, the least-tax share search (utils/income_tax_allocation.py:248, :462-464) then stops weighing the allowance and can pick a share that fails the s.55B rate test.
Running the head on main's SHARE_COUPLE fixture (test_marriage_allowance_cps_switch.py:467), with situation inputs for 2025 and 2026, gives:
| reform | 2025: at stake / MA / income tax | 2026: at stake / MA / income tax |
|---|---|---|
| none | 252 / 1,260 / 7,248 | 252 / 1,260 / 7,248 |
expanded_ma.remove_income_condition: {"2026": True} |
0 / 0 / 7,354.625 | 0 / 1,260 / 7,124.025 |
same, keyed 2026-01-01.2026-12-31 |
0 / 0 / 7,354.625 | 0 / 1,260 / 7,124.025 |
So in 2025, with the switch off, the couple loses the allowance and pays £106.625 more than with no reform. Adding "marriage_allowance_reduction_at_stake" to the routed tuple gives 252 / 1,260 / 7,248 in 2025 and leaves 2026 unchanged (checked locally).
Suggested changes:
- Route
marriage_allowance_reduction_at_stakewith the other two. - Add an inactive-year case with
SHARE_COUPLEtotest_structural_reform_periods.py. The existing cases usecouple()(test_structural_reform_periods.py:73), which defaults to £80,000 + £0 with no savings or dividends. For that couple the share of reliefs never decides the allowance, so those cases can't catch this. - Consider having
apply_period_aware_reformraise when the trial reform updates an existing variable that isn't innames, so the next variable added on main can't leak the same way.
Review drafted with AI assistance and checked against the code at c658df33c.
|
Addressed the routing and regression points in your latest review in
The four cases first failed on the unchanged production code at the inactive-2025 income-tax assertion, then recorded complete setup/call/teardown PASS after the fix. Validation used Python 3.13.15 and Core 3.34.9. The combined 118-case attempt hit its 2 GiB memory cap after 113 complete PASS observations; it remained incomplete, without JUnit or session-finish evidence. The fresh five-case complement also exceeded the 2 GiB memory cap during its first case. It contributes no normal-run PASS credit. Validation of the complete 118-case manifest remains incomplete. I deferred the optional generic replacement guard because it needs separate compatibility coverage for existing replacements, new helper variables and trial/clone behavior across the structural-reform callers. Max's reported-input-ledger scope decision remains open. Formal approval and fresh hosted checks at the published commit remain pending. |
vahid-ahmadi
left a comment
There was a problem hiding this comment.
Round 5 at 5356a08. Round 4 was at c658df33c. Since then: 70043325b, then a merge of main to resolve the CI shard conflicts.
My round 4 finding is fixed.
marriage_allowance_reduction_at_stakenow sits in the routed tuple (marriage_tax_reforms.py:354).- The four new cases use a
SHARE_COUPLE-style couple across reform dictionary and Scenario, with bare-year and calendar-interval keys. They check MA, the reduction at stake and income tax in the inactive and active years, including repeated and out-of-order calculations. That's the casecouple()couldn't catch. test_structural_reform_periods.pygives 71 passed locally at the head (about 9 minutes).- The merge brings only main's commits. The PR's own files differ from round 4 only by
70043325b. - CI is green: Test / Result and Aggregate impact pass. Of the two Fix evidence runs, the cancelled one was superseded by a pass a few seconds later.
Still open, optional: my third round 4 suggestion. apply_period_aware_reform could raise when the trial reform updates an existing variable that isn't in the routed names. reforms.py raises for changed routing metadata (:95) and for a missing formula route (:112), but not for an unrouted update. That is how marriage_allowance_reduction_at_stake leaked when main added it. Without the guard, the next variable main adds to an expanded reform can leak the same way. Fine as a follow-up if you'd rather not widen this PR.
The design question for @MaxGhenis from rounds 1 to 3 is separate and still unanswered as far as I can see. That's the only thing between this PR and approval from my side.
Review drafted with AI assistance and checked against the code at 5356a0887.
Fixes #1800
Reproducer: policyengine_uk/tests/test_structural_reform_periods.py::test_expanded_ma_share_search_keeps_inactive_year_current_law
Structural reform switches follow the calculation period. Bare-year keys in reform dictionaries and Scenario
parameter_changesactivate only the named year; explicit intervals stop at their end. Finite parameter histories also find future Scottish Child Payment activations beyond the previous five-year scan. Ordinary formulas apply outside each activation interval.Parameter-driven
disable_simulated_benefitsuses reported amounts only in active years and preserves supplied inputs across reform replay, input changes, cache invalidation and cloning. Direct application retains its existing ten-year behavior. #2305 addressed dictionary/Scenario application ordering; this PR addresses activation dates.axiom: n/a: structural activation and input/cache lifecycle engineering; no policy rule or numeric parameter changes.
Commit
70043325b7836ead8a2bbeb3301d7b9cca29839caddresses Vahid's latest review. The expanded Marriage Allowance reform now routesmarriage_allowance_reduction_at_stakealongside its other two replacement variables. This keeps the share search on the unreformed rules outside the activation interval.Four new cases use a self-contained equivalent of
SHARE_COUPLE, whose savings and dividends make the allocation of reliefs affect Marriage Allowance. They cover dictionary and Scenario application with both a bare year and a calendar-year interval. Each checks the amount at stake, Marriage Allowance and income tax against inactive-year and active-reform controls, repeating years out of order.Local validation used Python 3.13.15 and Core 3.34.9 with synthetic fixtures and frozen, offline execution. All four new cases failed on the original production code at the inactive-2025 income-tax assertion, then recorded complete setup/call/teardown PASS after the routing fix. The two affected files collected 118 distinct cases. Their combined run exceeded the 2 GiB memory cap after 113 complete PASS observations; that command remained incomplete, without JUnit or a session-finish result. It was not a successful combined run.
The fresh five-case complement also exceeded the 2 GiB memory cap during its first case. It contributes no normal-run PASS credit. Validation of the complete 118-case manifest remains incomplete.
Hosted checks for
70043325b7836ead8a2bbeb3301d7b9cca29839crequire a fresh read after publication; earlier commits' results do not validate this commit.The optional generic guard against unrouted replacements remains deferred. It needs a separate compatibility contract for existing-variable replacements, newly introduced helper variables and trial/clone behavior across the structural-reform callers.
Max's reported-input-ledger scope decision remains open: retain the ledger, observers and replay here, split reported-only mode into another PR, or keep that switch at build time with its dataset-year requirement documented. This fix leaves that implementation in place. Max's scope decision and formal review approval remain required; the local regression evidence does not clear the whole PR.
Main merge and CI conflict repair
Merge head
5356a0887e5c5754a8e24e874041d0edb28de49dcombines the previous PR head70043325with main00baa92d. It resolves five shard-count differences in the workflow and testing guide using main's ten-shard settings. The nine PR-only implementation, test and changelog files retain their exact previous contents.All 129 focused CI sharding and runner tests passed, with no failures, errors or skips. Formatting, lint, changelog and fix-evidence checks passed. Hosted checks for this merge have not completed at publication.
This validation covers the conflict repair. The reported-input ledger scope decision, earlier incomplete 118-case local model validation and formal approval remain open.