Skip to content

Store the UK State Pension split inputs on the spine - #1808

Draft
MaxGhenis wants to merge 5 commits into
mainfrom
uk-state-pension-split-stage1
Draft

MaxGhenis wants to merge 5 commits into
mainfrom
uk-state-pension-split-stage1

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This branch adds stage 1 of the UK State Pension legal split. The UK spine stores two person inputs that policyengine-uk reads at the data year:

  • state_pension_flat_share (E1) holds a share of the full weekly rate.
  • state_pension_addon_weekly_base (E2) holds weekly pounds of CPI-linked pieces.

At this stage every person's share s equals 1, so the stored pair matches the engine's own cap split and moves no figure. A later method commit fits s < 1 per cell; from then on the inputs change results.

The branch holds three parts:

  1. The engine-free core, uk_runtime/state_pension_split.py: split_state_pension(...) turns aligned arrays into E1, E2 and a receipt per cell (see the core, further down).
  2. Stage 18, state_pension_split, right after hmrc_spi_income_spine. It reads each person's type, the report net of the age addition and both default inputs from policyengine-uk at the survey year. It checks the cap against the parameter leaf and writes both columns under float32 asserts. Its receipt counts support through receipt_counts.
  3. A release-blocking terminal gate, uk_state_pension_copy_lineage. Within each SPI lineage key, it checks that the split, the report, age, gender and months since last birthday agree, on the dense graph's geographic copies too.

The stage and uk.full.export.prepare both refuse a person table that stores basic_state_pension, new_state_pension or additional_state_pension. In a period where any of the three carries an input, policyengine-uk drops a stored split for every person and falls back to its cap split without an error. Export preparation also asserts that the export period equals the data year in the stage's evidence.

Landing constraint

Once this branch merges main and CI runs, engine-uk (3.13 and 3.14), integration-uk and the aggregate check will fail. The locked policyengine-uk 2.180.0 has neither input: engine-uk stops at collection on policyengine_uk.utils.state_pension, and the integration smoke run reaches the new stage. Merging waits on three steps:

  1. a policyengine-uk release that carries both inputs (Let a dataset supply the State Pension split in its data year policyengine-uk#2977, still a draft);
  2. the Microcosm floor bump to that release, including hmrc_uprating_engine_pins.json, whose guard refuses any other installed engine version;
  3. a re-pin of uk_spine.json, whose numerical dependencies stay at the locked 2.180.0 until then.

A cloud task built the stage and ran its engine tests against policyengine-uk d93236f5e1893ae4f9e17255138fb5c9afd1a684. All six acceptance cases passed there. Above the cap, additional_state_pension differed from the engine's value only within tolerance.

A 2040 row that types NEW

The after-d reform test prints the BASIC man's row in each projected year, and by 2040 that row types NEW. Static ageing, already on main, moves his implied birth to 1955 by 2040 (birth_instant, policyengine-uk utils/dates.py:136), outside the male rule. Every run then types him NEW, and the split steps aside because his type changed. That's expected.

The core

split_state_pension(...) takes aligned arrays and returns E1, E2 and a receipt per cell:

  • Inputs: person_id, the annual State Pension net of the age addition (R), and cap_weekly, the full weekly rate for the person's type at the data year. It also takes the type (NONE, BASIC or NEW), a cell key the caller builds, the household weight and the source household id. It optionally takes per-cell targets or upper bounds on the weighted CPI-linked total.
  • Bound: U = min(R, 52 × cap). NONE rows get E1 = 0 and E2 = R / 52, with no division by the cap.
  • Draw: SharePrior gives each person's share s of U as a censored exponential, s = lower + (1 − lower) × min(1, scale × −log u). The uniform u comes from stable_identity_uniforms(person_id, seed=0, salt="state_pension_flat_share"), the convention pip_points uses.
  • Fit: per cell, bisection on the scale meets the weighted CPI-linked target. A cell with no target takes s = 1 and carries the flag unidentified. A target outside the reachable range raises.
  • Write: E1 = sU / (52 × cap) and E2 = (R − sU) / 52, so 52 × (E1 × cap + E2) = R.
  • Receipt: each cell's scale, target, achieved total and its CPI-linked totals at s = 1 and at the prior's floor. The count goes through receipt_counts, and a cell under UK_DISCLOSURE_FLOOR has every figure withheld.

The stage passes no targets, so every cell takes s = 1, and it stores the engine's own pair.

Open method choices

The code settles these only as placeholders. The design owner rules on each before any stage passes targets in:

  1. The prior's family and its floor (lower = 0.5), neither calibrated empirically yet.
  2. Upper bounds. As written, a cell with an upper bound takes the largest CPI-linked total the bound allows. A slack bound therefore puts every share in the cell at lower, while a cell with no target takes s = 1.
  3. Cells under the disclosure floor keep their fit in the output arrays and have their receipt withheld. The core pools no cells.
  4. A target one float outside the reachable range raises, even when the gap falls within the solver's tolerance.

Other changes

  • Gates and manifests: one new gate (95 to 96; national scope 21 to 22) moves the full and release-cut gate digests in contract.py and test_contract.py. The stage roster goes from 58 to 59, and every copy of source_manifest_sha256 follows the new source_stages.json.
  • Counting helper: receipt_counts.complementary_suppression moves out of pip_points unchanged. That moves the implementation hash of every counting stage, so their cached nodes rebuild once; outputs stay the same.
  • Export inputs: uk.full.export.prepare takes the stage's evidence (or spine_provenance) as an input for its data-year assert.
  • Parity fixture: the UK spine fixture gains the stage node, and 36 nodes' person inputs gain the two columns. A regeneration had also moved root birthday values, two household weights and synthetic CGT facts. Regenerating the parent commit on a fresh host, with no new stage, reproduces the same moves, so they come from the host; this branch keeps the committed bytes.

Tests

  • New engine-free files: test_state_pension_split.py (Hypothesis properties of the core) and test_uk_state_pension_split_stage.py (writer asserts at the cap edges, survey year, receipt suppression, copy-lineage gate, export data year and component refusals).
  • New engine file tests/engine/uk/test_uk_state_pension_split_stage.py: the stored pair against the engine at d and in projected years, reforms in force at d, a reform starting after d, and positive controls. It needs the policyengine-uk release.
  • Locally, the engine-free stage, terminal-graph and inspection-export tests pass, and ruff format --check and ruff check pass on the touched files.

axiom: n/a: data-build stage that stores engine inputs; the State Pension rules themselves change in PolicyEngine/policyengine-uk#2977

🤖 Generated with Claude Code

MaxGhenis and others added 5 commits November 29, 2026 12:05
Stage 1 of the UK State Pension legal split (d3519) needs two person
inputs: state_pension_flat_share (E1, a share of the full weekly rate)
and state_pension_addon_weekly_base (E2, weekly pounds of CPI-linked
pieces). This adds the pure core that computes them from arrays: a
censored exponential share prior drawn at a person_id-keyed uniform,
one bisected scale per cell to meet a weighted target or upper bound,
and a receipt routed through receipt_counts.

No stage is registered and no build output changes. The prior's family
and floor are placeholders for the design owner's choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stage 18, state_pension_split, stores policyengine-uk's data-year cap
split at s = 1 after the SPI income redraw: it reads the report
excluding the age addition, the type and both default inputs from the
engine, and writes state_pension_flat_share and
state_pension_addon_weekly_base with float32 asserts. A terminal
copy-lineage gate checks the split, report, age, gender and months
since last birthday within each SPI lineage key, including on the dense
graph's geographic copies.

Built in a Codex cloud task from the hub's reviewed brief against
policyengine-uk d93236f5e1893ae4f9e17255138fb5c9afd1a684; applied here
from the harvested patch (sha256 07ec37bb..., tree 9915ceb).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stage commit regenerated the UK spine parity fixture in a container
with policyengine-uk 2.180.2 installed from git. Three of its changes
were not the stage's doing. A regeneration at the parent commit, on a
fresh host with no new stage, reproduces all three byte for byte with
both the locked 2.180.0 and the git engine:

- sources/person.csv: 31 months_since_last_birthday values, from the
  root's floating-point cumulative sums over parsed gross4 weights;
- sources/weights.json: two household weights one ulp apart, from the
  default float parser reading househol.tab;
- sources/cgt_asset_type_facts.json: 24 synthetic CGT fact values
  derived from those root tables.

Restore those three files to their committed bytes. Also pin the 59
graph nodes' policyengine-uk numerical dependency to the locked 2.180.0,
as a regeneration under the lockfile records it; the stage node and the
36 rewired inputs stay. No CI job runs the fixture's --check, and no
test pins these files' bytes; the H2 acceptance test derives the root
from frs_raw in-process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In a period where basic_state_pension, new_state_pension or
additional_state_pension carries an input, policyengine-uk drops the
stored split for every person and falls back to its cap split without
an error. The stage and uk.full.export.prepare now refuse a person
table that stores any of the three. The names live in
state_pension_split.py, which the stage kernel already hashes;
export.prepare's implementation hash now includes that module too.

No source stage or fixture writes these columns, so no build output
moves. Engine-free tests cover each name at both points, and the H5
round trip checks that none comes back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis changed the title Add the engine-free core of the UK State Pension split Store the UK State Pension split inputs on the spine Nov 30, 2026
@juaristi22

Copy link
Copy Markdown
Collaborator

A note on the gate manifest's room, because this PR adds a gate. It comes from the work on #1815.

The room. The UK gate nodes carry the whole gate manifest as one parameter. It has 2,011 characters of room, and the room test fails under 1,024. About 65% of the string is notes. The nodes use the parameter for one thing: they build the manifest again from the package and compare. No reader takes a note from it. The change planned under #1815 carries the manifest without its notes in the parameter, which takes the room to about 86,000 characters. So the room is no reason to shorten a note here.

A suggestion: make note edits free. Today an edit to any gate note re-keys much more than the gates:

  • the gate declarations are in the package fingerprint, so the dense graph re-keys from target compilation on, and a stored solve is not used again;
  • a note on a spine gate also stops a built spine from binding, because the signed spine gate report holds a manifest digest that includes the notes.

Notes are prose. It may be worth taking them out of both places: a file of their own outside the solve's fingerprint, and a manifest digest without notes. The cost: the digest is shared gate code, so every country's gate report digests change once, and the signature then no longer covers the notes' text. Is that acceptable?

This branch has not been deployed

No deployments
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