From 32d62687736c6459a3fbd7f3e87428aa3e826a57 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 3 Dec 2026 23:08:48 +0400 Subject: [PATCH 1/5] Describe build folders and the new certification commands in the docs The certification docs now describe certifying a US or UK Microcosm build from its own folder with `scripts/bundle.py certify-build`, the compatibility check (`check-compatibility`) and the Tuesday and Friday `Check model compatibility` workflow. The US runbook becomes `docs/engineering/runbooks/microcosm-certification.md` for both countries, the UK qualification runbook is removed with its workflow, and tagged addresses and policyengine-uk-data steps remain only in the data certification skill's "Earlier certifications" history section. Co-Authored-By: Claude Opus 5.5 --- docs/bundles.md | 46 +- .../runbooks/acs-local-wic-replacement.md | 2 +- .../build-m-us-populace-certification.md | 132 --- .../runbooks/microcosm-certification.md | 197 +++++ docs/engineering/runbooks/uk-qualification.md | 144 ---- docs/engineering/skills/data-certification.md | 754 ++++++++++-------- docs/release-bundles.md | 287 +++---- 7 files changed, 774 insertions(+), 788 deletions(-) delete mode 100644 docs/engineering/runbooks/build-m-us-populace-certification.md create mode 100644 docs/engineering/runbooks/microcosm-certification.md delete mode 100644 docs/engineering/runbooks/uk-qualification.md diff --git a/docs/bundles.md b/docs/bundles.md index acaf3ab39..0954a4602 100644 --- a/docs/bundles.md +++ b/docs/bundles.md @@ -197,31 +197,31 @@ certificate that binds its core (`certify-data --core-version`, re-certified for the new core. See "The core" in the data certification skill. -To certify a new data release from a data-producer manifest, run: +To certify a US or UK Microcosm build, name it by build (the release defaults +to the one the bundle pins) together with the local-area build its regions +use: ```bash -python scripts/bundle.py certify-data \ +python scripts/bundle.py certify-build \ --country uk \ - --data-producer populace \ - --manifest-uri hf://dataset/policyengine/populace-uk-private@/releases//release_manifest.json + --national-build \ + --local-area-build \ + --model-version ``` -For US Microcosm releases, certify the Microcosm release manifest directly: - -```bash -python scripts/bundle.py certify-data \ - --country us \ - --data-producer populace \ - --manifest-uri hf://dataset/policyengine/populace-us@/releases//release_manifest.json \ - --regional-manifest-uri hf://dataset/policyengine/populace-us@/releases//release_manifest.json \ - --model-version -``` - -US state and congressional-district regions scope one certified ACS-local -Microcosm dataset with row filters. Pass its non-default local-area release -manifest through `--regional-manifest-uri`; certification adds the pinned H5 -artifact to `data_releases.us.datasets` and writes both regional path templates -under `data_releases.us.region_datasets`. If a legacy release publishes derived +It runs the compatibility check on each build, then `certify-data` with each +build's own folder, `releases///release_manifest.json`, at +the commit that published it; tagged addresses are refused. See the +[Microcosm certification runbook](engineering/runbooks/microcosm-certification.md) +for every option, and the data certification skill for what certification +checks. On Tuesdays and Fridays the `Check model compatibility` workflow does +this for each country's newest model release and opens a draft pull request. + +US state and congressional-district regions, and UK constituency and +local-authority regions, scope one certified local-area Microcosm dataset with +row filters. Certification adds its pinned H5 artifact to +`data_releases..datasets` and writes the regional path templates +under `data_releases..region_datasets`. If a legacy release publishes derived `states/*.h5` or `districts/*.h5` slices, certification still omits them. `policyengine bundle install` continues to materialize only each country's @@ -240,6 +240,6 @@ bumps the package and bundle versions together after merge. CI checks derived bundle metadata, installs the package scaffold from the bundle manifest, runs `pip check`, and verifies the packaged bundle metadata with lightweight URI checks. Dataset downloads are handled by -`policyengine bundle install`, so certified UK data can be pinned by manifest -version and downloaded from Hugging Face even when the matching -`policyengine-uk-data` package is not published to PyPI. +`policyengine bundle install`, so certified data is pinned by its build folder +and commit and downloaded from Hugging Face; no data package is installed from +PyPI. diff --git a/docs/engineering/runbooks/acs-local-wic-replacement.md b/docs/engineering/runbooks/acs-local-wic-replacement.md index 72f7b9a08..d88917645 100644 --- a/docs/engineering/runbooks/acs-local-wic-replacement.md +++ b/docs/engineering/runbooks/acs-local-wic-replacement.md @@ -40,7 +40,7 @@ certified. Do not invent its revision or hash or relax its failing check. Once the replacement is available: -1. Follow the [US certification runbook](build-m-us-populace-certification.md) +1. Follow the [Microcosm certification runbook](microcosm-certification.md) with its actual immutable regional manifest. Keep national defaults and model pins unchanged unless separately approved. 2. Verify complete current-name participation on the replacement and record diff --git a/docs/engineering/runbooks/build-m-us-populace-certification.md b/docs/engineering/runbooks/build-m-us-populace-certification.md deleted file mode 100644 index c69f77986..000000000 --- a/docs/engineering/runbooks/build-m-us-populace-certification.md +++ /dev/null @@ -1,132 +0,0 @@ -# US Microcosm certification runbook - -Use this runbook to certify a new national US Microcosm release together with -the shared ACS-local release used for state and congressional-district -simulations. For now, state and district simulations use the national release -instead; see the interim exception in Step 2. Read the -[data certification](../skills/data-certification.md) skill first for -validation semantics. - -This historical filename is retained so existing links remain valid; the -procedure itself is release-independent. - -## When to use - -Both release manifests have been published to `policyengine/populace-us`, and -the model version used by the national release is known. The national release -will remain the default dataset; the local-area release will remain -non-default and be selected only for supported regional runs (none while the -interim exception in Step 2 holds). - -## Prerequisites - -- A clean worktree branched from current `origin/main`. -- Network access: certification fetches the release manifest and PyPI wheel - metadata and runs reachability `HEAD` checks against Hugging Face. -- `HUGGING_FACE_TOKEN` (or `HF_TOKEN`) exported — required to regenerate the - UK TRO in the `--include-tros` step and to run the UK data-release fetch in - the test suite. The US release repo, `policyengine/populace-us`, is public. - -## Step 1 — identify the releases - -Set values from the two published release manifests rather than copying an -older certification: - -``` -NATIONAL_RELEASE_ID = populace-us-2024---Z -LOCAL_AREA_RELEASE_ID = populace-us-2024---Z -MODEL_VERSION = -``` - -The local-area manifest must declare `dataset_role: non_default_local_area`, -`is_default: false`, no default datasets, and exactly one pinned H5 microdata -artifact. - -## Step 2 — certify both releases - -```bash -python scripts/bundle.py certify-data \ - --country us \ - --data-producer populace \ - --model-version "$MODEL_VERSION" \ - --manifest-uri "hf://dataset/policyengine/populace-us@$NATIONAL_RELEASE_ID/releases/$NATIONAL_RELEASE_ID/release_manifest.json" \ - --regional-manifest-uri "hf://dataset/policyengine/populace-us@$LOCAL_AREA_RELEASE_ID/releases/$LOCAL_AREA_RELEASE_ID/release_manifest.json" -``` - -This one command: - -- rewrites `data_releases.us` in `src/policyengine/data/bundle/manifest.json` - from the national release manifest (default dataset, per-artifact - repo/revision/sha256 pins, certified artifact, certification block); -- runs `generate(check=False)`, which re-normalizes `manifest.json` and - updates `pyproject.toml` **only if the model pins moved**; -- writes the changelog fragment - `changelog.d/certify-us-$NATIONAL_RELEASE_ID.changed.md`. - -## Step 3 — regenerate TRACE sidecars - -The certify step does not touch TRACE sidecars. Regenerate them so they record -the new bundle-manifest SHA-256: - -```bash -HUGGING_FACE_TOKEN="$HUGGING_FACE_TOKEN" python scripts/bundle.py generate --include-tros -``` - -Both country sidecars contain the bundle-manifest hash, so both may change when -the bundle changes. If UK cannot be reached, the run writes a *limited* UK -sidecar; do not commit that degraded output. - -## Step 4 — update pinned expectations - -Update tests that intentionally pin the outgoing national release, local-area -release, model version, or artifact hashes. Derive every replacement from the -new manifests; do not copy identifiers from this runbook. - -If the model version changed, refresh the household snapshots with: - -```bash -PE_UPDATE_SNAPSHOTS=1 pytest tests/test_household_calculator_snapshot.py -``` - -## Step 5 — certify and verify the local-area release - -The certification command passes the immutable ACS-local release manifest with -`--regional-manifest-uri`. Confirm all of the following: - -- `default_dataset` remains the national Microcosm dataset; -- the local-area artifact appears in `data_releases.us.datasets` with its - repository type, immutable revision, and SHA-256; -- `region_datasets.national` selects the national artifact; -- `region_datasets.state` and `region_datasets.congressional_district` select - the shared local-area artifact; -- no derived `states/*.h5` or `districts/*.h5` artifacts are runtime inputs. - -```bash -pytest tests/test_certify_data_release.py \ - tests/test_release_manifests.py \ - tests/test_us_regions.py \ - -q -``` - -## Step 6 — check, format, lint, test - -```bash -python scripts/bundle.py check # must exit 0 -make format -make lint -make test # needs HUGGING_FACE_TOKEN for UK -``` - -## Step 7 — inspect and commit the generated changes - -The expected diff normally includes the bundle manifest, TRACE sidecars, one -Towncrier fragment, and pinned test expectations. Include package pins and -snapshots only when the certified model version changed. Investigate any other -generated difference before committing it. - -## Step 8 — open the PR - -Follow [github-prs](../skills/github-prs.md): open/find the issue, put -`Fixes #ISSUE` first, push to the canonical repo, and open a **draft** PR. The -certify step already wrote the changelog fragment, so the changelog check -passes. diff --git a/docs/engineering/runbooks/microcosm-certification.md b/docs/engineering/runbooks/microcosm-certification.md new file mode 100644 index 000000000..cbf64ba48 --- /dev/null +++ b/docs/engineering/runbooks/microcosm-certification.md @@ -0,0 +1,197 @@ +# Microcosm certification runbook + +Use this runbook to certify a US or UK Microcosm build, or to certify the +pinned builds for a new model version. Both countries follow the same steps +with the same command. Read the [data certification](../skills/data-certification.md) +skill first for what certification checks and records. + +## When to use + +- **A new model release.** You usually don't need this runbook: on Tuesdays + and Fridays the `Check model compatibility` workflow checks each country's + newest model release against the builds the bundle pins and opens a draft + pull request when they pass (see [The scheduled workflow](#the-scheduled-workflow)). + Run the steps below by hand only to certify a version the workflow didn't, + or with options it doesn't use. +- **A new Microcosm build.** Microcosm has published a national build, a + local-area build, or both, and the bundle should pin them. + +## Prerequisites + +- A clone of `policyengine.py` at current `origin/main`, with the + environment installed for the country (`uv sync --extra us --extra dev` or + `--extra uk`). The command makes its own worktree and branch beside the + clone unless you pass `--in-place`. +- `uv`, network access to Hugging Face and PyPI, and `gh` signed in (for the + check that no one else is certifying the same build and model, and for the + pull request). +- For the UK, whose builds are private, `HUGGING_FACE_TOKEN` (or `HF_TOKEN`) + exported with read access to `policyengine/populace-uk-private`. The US + repository, `policyengine/populace-us`, is public. +- Free disk for both builds' files. The command checks the space before it + downloads anything, sized from the builds' manifests (about 10 GB for the + US local-area file). + +## Step 1: name the builds + +Microcosm publishes each build in its own folder, +`releases///`, and lists every build in the repository's +`releases.json`. Read `releases.json` at `main` to find the build names: + +| Country | Repository | National release | Local-area release | +|---|---|---|---| +| US | `policyengine/populace-us` | `microcosm-us-2024-national` | `microcosm-us-2024-local` | +| UK | `policyengine/populace-uk-private` | `microcosm-uk-2024-25-national` | `microcosm-uk-2024-25-dense` | + +A build must be listed and must not be withdrawn. Which build is `current` +doesn't matter: a certificate pins one build. Take the model version from the +national build's `release_manifest.json` (`built_with_model_package`) unless +you are certifying it for another version. + +## Step 2: run the certification + +Check the plan first: + +```bash +python scripts/bundle.py certify-build --country us \ + --national-build \ + --local-area-build \ + --dry-run +``` + +Then run it, pushing the branch and opening a draft pull request: + +```bash +python scripts/bundle.py certify-build --country us \ + --national-build \ + --local-area-build \ + --push --open-pr +``` + +For the UK, pass `--country uk` and the UK build names. The release names +default to the releases the bundle pins now; pass `--national-release` or +`--local-area-release` when a build is in another release. + +The one command: + +1. refuses when an open pull request or a branch already certifies this + national build for this model version (`--skip-writer-check ""` + skips that check); +2. reads each build from its own folder at the last commit of its + `release_manifest.json` on `main`, after checking that `releases.json` at + `main` lists it and has not withdrawn it, and checks the free disk; +3. runs `scripts/bundle.py check-compatibility` for each build with the model + version (see [the compatibility check](../skills/data-certification.md#the-compatibility-check)); +4. runs `scripts/bundle.py certify-data` for the national build with the + chosen regional route, using the check's record as the basis whenever the + model is not the one the build was made with; +5. runs `uv lock` and `scripts/release_lock.py`; +6. runs `scripts/bundle.py generate --include-tros`, rewrites the certified + constants that tests pin, regenerates the household snapshots, then runs + `scripts/bundle.py check --published-spm --include-tros --strict-tros`; +7. for the UK, runs the Universal Credit floor check (weighted national + totals only); +8. commits on a new branch in a new worktree and writes a pull request body + that lists every decision left to a reviewer. `--push` pushes the branch + and `--open-pr` opens a draft pull request. It never merges or releases. + +It runs no tests beyond regenerating the snapshots; the pull request's CI runs +them. Never run the full test suite locally for a certification. + +### Options + +| Option | Use | +|---|---| +| `--country us\|uk` | The country (required). | +| `--national-build BUILD` | The national build to certify (required). | +| `--national-release RELEASE` | The national build's release (default: the bundle's). | +| `--national-data-commit COMMIT` | Read the national build at this commit on `main` instead of the last commit of its manifest. | +| `--local-area-build BUILD` | Route state, district, constituency and local-authority regions to this local-area build. | +| `--keep-regional-release` | Keep the local-area build the bundle routes to now. | +| `--drop-regional-release` | Route no regions to a local-area build. | +| `--local-area-release RELEASE` | The local-area build's release (default: the bundle's). | +| `--local-area-data-commit COMMIT` | With `--local-area-build`: read it at this commit on `main`. | +| `--model-version VERSION` | The model version to certify for (default: the national build's own). | +| `--core-version VERSION` | Bind the certificate to this policyengine-core and move the bundle's core pin to it (default: the bundle's pin, unbound). | +| `--in-place` | Change this checkout's files; make no worktree, branch or commit. | +| `--worktree PATH` | The new worktree (default: beside this checkout). | +| `--base-ref REF` | The commit the branch starts from (default: `origin/main`). | +| `--output-dir PATH` | Where the command log and the pull request body go. | +| `--skip-writer-check WHY` | Skip the check for another pull request or branch certifying the same build and model. | +| `--push` / `--open-pr` | Push the branch; open a draft pull request (needs `--push`). | +| `--dry-run` | Print the plan only. | +| `--co-author NAME ` | Add a co-author line to the commit (repeatable). | +| `--pr-body-footer TEXT` | A closing line for the pull request body. | + +Pass exactly one of `--local-area-build`, `--keep-regional-release` and +`--drop-regional-release`. + +## Step 3: review the pull request + +The expected diff is: + +- `src/policyengine/data/bundle/manifest.json` and the country TRACE + sidecars (`{country}.trace.tro.jsonld`; both countries' sidecars record the + bundle manifest's hash, so both may change); +- `src/policyengine/data/compatibility/.json`, when a build was + certified on the compatibility check's record; +- `pyproject.toml` and `uv.lock`, only when the model or core pin moved; +- one Towncrier fragment under `changelog.d/`; +- the certified constants tests pin and the household snapshots. + +Investigate any other change before the pull request is marked ready. Check +the decisions the pull request body lists, and for the UK the Universal Credit +floor result (see [acceptance evidence for a UK default switch](../skills/data-certification.md#acceptance-evidence-for-a-uk-default-switch)). +Confirm that `region_datasets` routes the national region type to the +national build and the local region types to the local-area build, and that +no derived `states/*.h5` or `districts/*.h5` files are runtime inputs. + +Follow [github-prs](../skills/github-prs.md) for the tracking issue and the +`Fixes #ISSUE` first line. + +## The scheduled workflow + +`.github/workflows/check-model-compatibility.yaml` runs at 06:17 UTC on +Tuesdays and Fridays, and by hand (`workflow_dispatch`, with `country` set to +`both`, `us` or `uk`, and an optional `model_version` that needs one +country). + +- A planning job picks, for each country, the newest `policyengine-us` or + `policyengine-uk` release on PyPI (or the version given by hand). It leaves + a country out when the bundle already pins that version or a pull request + for it already exists. +- For each remaining country, a job runs `scripts/bundle.py certify-build` + on the national and local-area builds the bundle pins, with that model + version. A pass pushes branch `certify//-` + and opens a draft pull request with the GitHub App's token, so the pull + request's own workflows run. A person reviews and merges it as in Step 3. + Earlier certification pull requests stay open, so any version that passed + can still be chosen. +- Every run uploads a `compatibility-` result file: the model + version, the builds, whether the check passed, and the pull request. +- A failure opens or comments on the issue "Model compatibility check + failed: US" (or UK); the next pass closes it. + +## Running the steps by hand + +`certify-build` runs these commands; run them yourself only to investigate. +Every manifest address names a build's own folder at a commit: + +```bash +python scripts/bundle.py check-compatibility --country us \ + --manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-national//release_manifest.json" \ + --model-version "" \ + --work-dir \ + --output national-record.json + +python scripts/bundle.py certify-data --country us --data-producer populace \ + --manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-national//release_manifest.json" \ + --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-local//release_manifest.json" \ + --model-version "" \ + --compatibility-record national-record.json \ + --regional-compatibility-record local-area-record.json +``` + +Leave out `--compatibility-record` when the model is the national build's +own, and `--regional-compatibility-record` when it is the local-area build's +own. diff --git a/docs/engineering/runbooks/uk-qualification.md b/docs/engineering/runbooks/uk-qualification.md deleted file mode 100644 index a1cad6e2e..000000000 --- a/docs/engineering/runbooks/uk-qualification.md +++ /dev/null @@ -1,144 +0,0 @@ -# UK candidate qualification: what the ledger shows, and reproducing a gate - -UK candidate qualification starts via `workflow_dispatch` and resolves legacy -uk-data pairs. Scheduled recovery and requalification are disabled. - -The workflow qualifies candidate policyengine-uk and uk-data pairs before -promotion (`scripts/check_uk_candidate.py`, `policyengine.provenance.uk_candidate`). -It writes each attempt's gate results and evidence to the public -`uk-qualification-ledger` branch and withholds any survey data that could -identify a record. - -## What the ledger withholds - -- **Reform contract, population checks.** These run on the survey data. Each - row's check, route, status and the runner's fixed fields - (`POPULATION_ROW_FIELDS`) are published; from its `detail`, only top-level - `True`/`False`/`None` findings are kept, and every count, total, amount, - text, list or nested mapping reads `"withheld"`. The digest the gate - records is of that published copy, never of the full report. -- **Metrics review and responsiveness.** The aggregate-impact tool publishes - a figure from fewer than 10 records as suppressed, and the gate records no - value from a report that breaks that format; such a report is published - only as its digest and problems. - -## Reproducing a failed population check - -The withheld figures exist only in the runner's report, which is not saved. -To see them, rerun the contract on a machine with access to the private UK -dataset, and keep the output local: it holds figures from the survey data, -some from fewer than 10 records, so never commit, paste or publish it. - -1. Check out the candidate commit the attempt ran on (`git_commit` in the - attempt's `harness.json` in the ledger): its bundle manifest names the - dataset `materialize_dataset` fetches, so an older checkout would fetch - older data even with the candidate's wheels installed. -2. Install the candidate pair (the attempt's `candidate.json` names the - wheels) and export `HUGGING_FACE_TOKEN` for the private dataset. -3. Materialize the certified dataset, check its SHA-256 against - `data.dataset_sha256` in the pair's `pair.json`, and run the contract - with the seed and sample size in - `src/policyengine/data/qualification/uk.json`: - - ```python - import hashlib - import json - from pathlib import Path - - from policyengine.provenance.dataset_materialization import materialize_dataset - from policyengine.tax_benefit_models.uk.budget_reform_contract import ( - run_budget_reform_contract, - ) - - dataset = materialize_dataset("uk", data_dir=Path("data")).path - pair = json.loads(Path("path/to/ledger/uk//pair.json").read_text()) - digest = hashlib.sha256(Path(dataset).read_bytes()).hexdigest() - assert digest == pair["data"]["dataset_sha256"], "not the certified dataset" - report = run_budget_reform_contract( - routes=None, dataset_path=str(dataset), seed=0, max_examples=20 - ) - failing = [row for row in report["population"] if row["status"] != "pass"] - ``` - -4. Read `failing[...]["detail"]` locally. Report only the finding (which - condition failed, on which route), never the figures. - -## A candidate stranded before automatic promotion - -Automatic promotion moves main to a qualified candidate only once the newest -run of each workflow and event on the candidate branch, from this repository, -has passed, including a `pr_code_changes.yaml` run dispatched on the branch -itself. The candidate-tree code-check dispatch remains reachable. Replay and -acceptance still refresh candidate PR checks. The schedule-only recovery job -and its two self-dispatches are unreachable. Runs of pull requests from other -branches or forks at the same commit do not count. The `refresh-pr-checks` -step re-runs a failed, timed-out or cancelled run until it has had four -attempts, within GitHub's 30 days of its first attempt. - -When the candidate waits on a run that refresh will not re-run, the promote -job fails with `::error:: waits on runs refresh will not re-run`, -naming each run, its result and its attempts. That covers a run at four -attempts, one older than 30 days, and one whose result refresh never re-runs -(`action_required`, `skipped`, `stale`, `startup_failure` and the like). The -job fails on each run until one of these clears it: - -- Fix the cause, then re-run the named run by hand - (`gh run rerun --repo PolicyEngine/policyengine.py`); a passing - newest attempt clears it. GitHub refuses this for a run whose first - attempt is more than 30 days old. -- For the run on the candidate's own tree, dispatch a new one: - `gh workflow run pr_code_changes.yaml --repo PolicyEngine/policyengine.py --ref `. -- Requalify the pair: run `certify-uk-release` with its versions, `pair_id` - and `force` set. - -### Another pull request from the candidate branch - -Any other pull request from a candidate branch runs the same workflows with -the same commit and branch as the candidate's own pull request, and -GitHub's run records say neither which pull request a run is for nor which -base it tested; a pull request's current base does not settle it, since a -base renamed into main records no event. So while another pull request from -the branch is open, or after one was closed or merged at the candidate's -commit (whatever its base), or when the candidate's own pull request's base -was ever changed, the promote job fails with -`::error:: is not promoted: runs at its commit may have tested another base`, -naming the pull requests, and refresh re-runs none of the candidate's runs. -Close those pull requests, then requalify the pair as above: the new -candidate commit leaves their runs behind, and prepare opens a new pull -request to main if none is open. - -### What promotion trusts - -Promotion guards against mistakes by people who can write to this -repository and against anything people who cannot can do (forks' pull -requests, whatever their branch names, and other pull requests opened from -a candidate branch, which make promotion refuse; one to main that prepare's -lookup adopts is the candidate's own, and promotion refuses it if its base -was ever changed). Whatever else happens, main only -ever becomes the exact qualified commit, built on main as it is at the push, -after the dispatched `pr_code_changes.yaml` run on that commit's own tree -passed. It does not try to resist deliberate disguise by people who can -write here, such as renaming another branch into main to make a run against -another base look like the candidate's: main is not protected, so they -could push it directly. Treat any such change as an incident, not as -something the gate will catch. - -## A pair from another data line - -Promotion compares only pairs on main's data line (its UK certificate's data -package and repository). While Microcosm UK is the default, the -policyengine-uk-data candidates the workflow resolves are `other_line`. An -unforced run of one stops there and writes nothing to the ledger. Recovery and -check refreshes skip such pairs, and promotion closes their open pull requests; -the ledger keeps their evidence. - -`force` still qualifies such a pair, for evidence only. Its candidate commit -drops main's area routing (`--drop-regional-release`), because the routing -belongs to the line the pair would replace, and leaves the test constants that -pin main's certificate as they are, so the candidate's own tests fail. Its pull -request says it is never promoted, and promotion closes it once its receipt is -published, at the commit that receipt qualified. Re-run the workflow by hand -with `force` to recover an attempt. If an attempt dies before publishing a -receipt, close its open pull request by hand. Changing the data line -is a reviewed certification pull request (see -`docs/engineering/skills/data-certification.md`), not a promotion. diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index 545b1aad4..ebbdb866a 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -9,47 +9,57 @@ A data release is published on Hugging Face with a release manifest: per- artifact repo/revision/sha256 pins, build provenance, compatibility claims, and region dataset templates. Certification asserts that *this* `policyengine.py` release, with the model package pinned in -`pyproject.toml`, serves that data release — and the assertion is only made -good by the test suite passing on the exact pinned pair. +`pyproject.toml`, serves that data release. The assertion rests on one of the +[compatibility bases](#compatibility-bases) and is made good by the test +suite passing on the exact pinned pair in the certification pull request's CI. There is no intermediate bundle repo. The `data_releases.{country}` entry in `src/policyengine/data/bundle/manifest.json` is derived directly from the data release manifest. -## Certifying a release +## Certifying a build -Open the work on a fresh branch from current `main` (use a clean worktree if -the checkout is dirty). +US and UK Microcosm builds are certified the same way, with one command: ```bash -python scripts/bundle.py certify-data --country uk --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases//release_manifest.json" +python scripts/bundle.py certify-build --country \ + --national-build \ + --local-area-build \ + --push --open-pr ``` -Pin the cut tag (`@`), never `main`: each cut of a Microcosm release -line rewrites that line's `releases//` directory, for example -`releases/microcosm-uk-2024-25-national/`. Microcosm records the line name as -`build.build_id` on every cut and the cut in `build.cut_tag`; certification -uses the cut tag as the build id (`data_releases..version`, the -certification's `data_build_id` and the changelog fragment name), so two cuts -of one line never look identical. +It checks each build against the model version, certifies the national build +with its regional route, regenerates everything derived from the bundle, and +opens a draft pull request. The model version defaults to the national +build's own; `--model-version` certifies the builds for another. The +[Microcosm certification runbook](../runbooks/microcosm-certification.md) +gives the steps, every option and what the pull request should change. + +For a new model release you usually run nothing: the +[scheduled workflow](#the-scheduled-workflow) checks each country's newest +model release twice a week and opens the pull request itself. ### Builds in their own release folders -Once Microcosm publishes each build in its own folder, -`releases///`, a build is never changed after publishing and -gets no Hugging Face tag. The repository's root `releases.json` records which -build of each release is current. That build's `release_manifest.json` names -its `release` and `build` as strings, for example +Microcosm publishes each build in its own folder, +`releases///`, in `policyengine/populace-us` and +`policyengine/populace-uk-private`. A build is never changed after publishing +and gets no Hugging Face tag. The repository's root `releases.json` records +which build of each release is current. That build's `release_manifest.json` +names its `release` and `build` as strings, for example `microcosm-uk-2024-25-national` and -`uk-frs-calibration-attempt-20261019T083323Z-6cba5d71`. Certify the build from -its own folder, at the commit that published it: +`uk-frs-calibration-attempt-20261019T083323Z-6cba5d71`. A build is certified +from its own folder, at a commit that holds it: ```bash python scripts/bundle.py certify-data --country uk --data-producer populace \ --manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases///release_manifest.json" ``` +`certify-build` finds that commit itself (the last commit of the build's +`release_manifest.json` on `main`) and runs `certify-data` for you. The rules +`certify-data` applies: + - The URI must be the build's own folder: a manifest that names another release or build than the folder it was read from is refused. - The repository's `releases.json` at `main` must list the build and must not @@ -82,255 +92,123 @@ python scripts/bundle.py certify-data --country uk --data-producer populace \ was certified keeps loading in every installed .py release whose bundle pins it. Certifying again changes only the .py releases published afterwards. -Manifests published before this layout, whose `build` is an object, are -certified as described above, but only from a repository that has no -`releases.json` at `main`. A repository is read in one layout: once it has -`releases.json`, a tagged manifest (primary or `--regional-manifest-uri`) is -refused, and the build is certified from its own folder instead. Only Hugging -Face's 404 for `releases.json` means the repository has none; a 404 whose -error code is `RepoNotFound` or `RevisionNotFound`, or any other failure, -refuses certification rather than being taken for a tagged repository. - -### UK constituency and local-authority regions - -UK constituency and local-authority regions row-filter the dataset a regional -release routes them to (`region_datasets.constituency` and -`region_datasets.local_authority`), and the national dataset when nothing is -routed. policyengine-sim-api accepts a UK default without area codes -(`constituency_code_oa`, `la_code_oa`) only when both are routed. Certify a -Microcosm national release with one of: - -- **A Microcosm local-area release (ship together).** The release declares - `dataset_role: non_default_local_area`, as for the US below. - - ```bash - python scripts/bundle.py certify-data --country uk --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases/microcosm-uk-2024-25-national/release_manifest.json" \ - --regional-manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases//release_manifest.json" \ - --model-version "" - ``` - - This records `regional_release_kind: local_area`, and the default UK region - registry then includes all 650 constituencies and 361 local authorities. - -- **The enhanced FRS (national first).** When the national release is ready - before a local one, route the area regions to a certified policyengine-uk-data - release whose households carry area codes: - - ```bash - python scripts/bundle.py certify-data --country uk --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases/microcosm-uk-2024-25-national/release_manifest.json" \ - --regional-manifest-uri "hf://model/policyengine/policyengine-uk-data-private@/releases//release_manifest.json" \ - --regional-release-kind area_coded_national \ - --model-version "" - ``` - - Certification carries that release's national dataset - (`enhanced_frs_2024_25`) and its `weights` artifacts (the constituency and - local-authority matrices and `local_geography_weights`) at their own repo - and revision, records `regional_release_kind: area_coded_national`, and - leaves area regions out of the default registry: the API keeps serving them - from the matrices. The enhanced FRS release must itself claim the pinned - policyengine-uk version (built with it or listed in - `compatible_model_packages`); otherwise policyengine-uk-data must publish a - claim first. Its `frs_2024_25` is not carried, so keep it loadable with a - `dataset_overlays.uk` entry. - -- **An older local-area release, on an accepted mismatch.** When the national - cut moves to a new policyengine-uk before a local-area cut on that version - exists, a reviewer can accept retaining the older regional route. A reason - and a byte-bound input-surface audit are both required. First audit the - actual local H5 with the exact target model installed. The audit also needs - `uv` and access to PyPI (see below): - - ```bash - .venv/bin/python scripts/audit_regional_input_surface.py \ - --regional-manifest-uri "" \ - --artifact "microcosm_uk_2024_25_dense=/local/dense.h5" \ - --model-version 2.147.2 \ - --audited-by "" \ - --limitation "the dense cut's VAT predates the policyengine-uk VAT factor fix (#2187, 2.135.7); the dashboard holds a VAT limit" \ - --output regional-input-surface.json - - .venv/bin/python scripts/bundle.py certify-data --country uk --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-uk-private@/releases/microcosm-uk-2024-25-national/release_manifest.json" \ - --regional-manifest-uri "" \ - --accept-regional-model-mismatch "" \ - --regional-input-surface-evidence regional-input-surface.json \ - --model-version 2.147.2 - ``` - - The audit compares the entity-table columns the H5 actually stores, in each - period, with two models: the build model and core the regional manifest - records (`build.built_with_model_package` and - `build.built_with_core_package`), and the target. As in Microcosm #1348's - `tools/certify_uk_cut_in_policyengine_py.py`, the build model is the - baseline: - - - **Dropped columns** are stored columns the build model defines and the - target does not. The target's loaders skip them. Certification refuses - **any dropped column**; there is no override. - - **Never-modelled columns** are stored columns neither model defines: - Microcosm's own area codes (among them `constituency_code_oa` and - `la_code_oa`), build and source ids, clone indices and SPI donor fields. - No model ever loaded them, so they are recorded, not refused. - - **Defaulted inputs** are target inputs the file does not store, after the - target's input aliases, that were not inputs of the build model. Area runs - default them where the build model did not. Inputs absent under both - models are not changes. - - The audit reads the build model's variables and inputs in a throwaway - `uv run --isolated --no-project --no-config --default-index - https://pypi.org/simple --exclude-newer --with - policyengine-uk== --with policyengine-core==` environment, so - it needs `uv` and access to PyPI. `--isolated` makes the environment fresh: - without it, uv reuses an environment that already meets both pins, such as - a `.venv` in the working directory, and neither the index nor the cutoff - applies. `--exclude-newer` is the manifest's build time, so the build - model's other dependencies resolve as they did then, and every `UV_*` - setting except the cache, Python-install and connection ones is removed. A - regional manifest that does not record both build versions has no - baseline, and one without `build.built_at` cannot be read as of its build; - the audit refuses both. The evidence binds the regional release identity, - original manifest bytes, actual H5 bytes, both build versions and the exact - target model version, and keeps both models' full variable and input lists. - - Certification does not trust those lists. It reads the target model in - process, so the environment that runs `certify-data` must have the target - policyengine-uk installed, as the audit's does, and reads the build model - again with `uv`; any list or input alias that differs refuses. Only the - stored columns rest on the auditor's word: they cannot be re-read without - the H5, and the evidence binds them to its SHA-256. The record says so, - with `stored_columns: auditor_attested`. Certification then - recomputes all three lists and refuses missing or mismatched evidence, - including evidence without `schema_version: 2`, from before the comparison - was relative to the build model. It records the never-modelled columns, - every defaulted input and the free-text limitations in the validated - `regional_certification`, and adds one limitation naming the defaulted - inputs; the bundle hash binds that record. - - The policyengine-uk 2.147.2 dataset loaders silently skip columns absent - from the model's variables: both the - [generic dataset loader](https://github.com/PolicyEngine/policyengine-uk/blob/fe0b99a36bd309a722b19937345e34290cb6dd73/policyengine_uk/simulation.py#L1113-L1127) - and the - [UK multi-year loader](https://github.com/PolicyEngine/policyengine-uk/blob/fe0b99a36bd309a722b19937345e34290cb6dd73/policyengine_uk/simulation.py#L1186-L1196) - use `continue` without warning. A removed or renamed input can therefore - disappear silently at runtime; the audit must catch that column loss before - certification. - - The national certificate never widens. Area status remains `uncertified`: - the certificate still covers the national dataset only (#685). TRACE - carries the whole regional record, evidence included, separately from the - national certification. An area run's execution receipt carries a summary - of it (both model versions, the reason, the three lists and the - limitations) and `record_sha256`, the digest of the whole record; check it - with `verify_regional_certification`. A national receipt carries none: its - `certificate_sha256` already digests the record. The flag applies to UK and - US local-area releases (see [US](#us) for the US audit); an empty or - invisible reason, a release that already covers the target model, or a - missing regional release refuses. - The regional core checks still apply. Re-certifying with - `--drop-regional-release` removes the regional record, routes and artifact. - - For the Budget route, the audit of dense cut - `microcosm-uk-2024-25-dense-20261019T000432Z-ee5c2dbe`, built with - policyengine-uk 2.132.6 and policyengine-core 3.33.3, measured in #699: - - - **83 never-modelled columns**, and **no dropped column** under either - 2.147.2 or 2.151.0. The first version of this audit counted those 83 as - dropped and refused the cut, even against its own build model. - - **16 new defaults under 2.147.2:** - `additional_residential_property_purchased`, - `defined_benefit_pension_share`, `directly_held_shares`, - `early_years_school_start_deferred`, `is_full_year_category_a_director`, - `local_bus_uncapped_single_fare`, `non_residential_property_purchased`, - `non_residential_property_secured_debt`, - `other_residential_property_secured_debt`, - `pension_annual_allowance_taxable_lump_sum_death_benefits`, - `pension_contributions_via_salary_sacrifice_pre_2015`, `pip_dl_points`, - `pip_m_points`, `salary_sacrifice_returned_to_income`, - `unit_and_investment_trusts`, and `war_widows_pension_reported`. - - **37 new defaults under 2.151.0:** those 16 and 21 more. The 21 include - the gambling duty inputs, liquid and solid fuel consumption, and bonus - sacrifice (`pension_contributions_via_bonus_sacrifice`), so area - breakdowns of those measures use defaults on 2.151.0. Certification - names every defaulted input in the limitations. - - Another **123 inputs already defaulted under 2.132.6**. They are absent - under both models, so they are not changes; the first version listed - them too, giving 139 defaults under 2.147.2 and 160 under 2.151.0. - - Record the pre-fix VAT limitation shown above for this dense cut. - - After the receipt schema changes, refresh the Budget dashboard's vendored - `tests/fixtures/w4/execution_receipt.v1.schema.json` from - `src/policyengine/data/schemas/execution_receipt.v1.schema.json`. - -Either way, certification checks that the regional release serves the pinned -model by its own build or compatibility claims (a `--qualified-pair-id` names -the primary release only), checks its core claims as for the primary release -(below), and HEAD-checks every artifact it carries. - -### The core - -The bundle has one core pin, `packages.policyengine-core`, shared by every -country. A certificate says how it covers it: - -- **`core_binding: bundle_pin` (the default, no `--core-version`).** The - certificate names no core and certifies whatever core the bundle pins, so - the pin can move with another country without re-certifying this one. - Certification checks the pin against each release's build-time core and - core claims, and warns, without refusing, when the pin is outside them. - `bundle.py check --include-tros --strict-tros` warns the same way when the - pin later moves outside the claims. Receipts then certify the pin without - the release's claim; the warning, the certificate and its TRO say so. -- **`core_binding: certified` (`--core-version`).** The certificate names the - core (`certified_for_core_version`). Certification refuses a core that a - release neither was built with nor claims, and the strict check refuses a - pin that differs from the named core, so moving the core needs a - re-certification first. A qualified exact pair always binds its core. - -Use the default unless a release must not run on any other core. - -### Re-certifying a routed bundle - -Certification rewrites `data_releases.` from the manifests it is -given. While the bundle routes regions (`regional_source_manifest_uri` is set), -a run without `--regional-manifest-uri` is refused; pass the current regional -release again (or its replacement), or `--drop-regional-release` to remove the -routing on purpose. The two flags cannot be combined. - -An overlay may never shadow a certified dataset name, so certification removes -any `dataset_overlays.` entry whose name the new release certifies. A -rollback to policyengine-uk-data with `--drop-regional-release`, for example, -removes the enhanced FRS overlays. `bundle.py check` refuses a bundle with an -overlay that shadows a certified name. - -Removed overlays do not come back by themselves. Certification warns about -every dataset name that stops resolving. After a certification that stops -certifying a name that must stay loadable (rolling forward after a rollback, -or a ship-together run after a national-first one), re-add its overlay from -the previous bundle, as #685 did for `enhanced_frs_2024_25`, `frs_2024_25` and -their `_tiny` files. - -### US - -For US Microcosm certification, certify the Microcosm release manifests -directly. `policyengine/populace-us` publishes each build in its own release -folder (it has `releases.json`), so give each manifest's folder at the commit -that published it: +A repository is read in one layout. Once it has `releases.json` (both +Microcosm repositories do), a manifest address with a tag instead of a build +folder, primary or `--regional-manifest-uri`, is refused. Only Hugging Face's +404 for `releases.json` means a repository has none; a 404 whose error code +is `RepoNotFound` or `RevisionNotFound`, or any other failure, refuses +certification. [Earlier certifications](#earlier-certifications) records how +builds were certified before the build folders. + +### Compatibility bases + +The certificate's `compatibility_basis` says why the build may run with the +pinned model version. Certification refuses a build that has none of them: + +- **`built_with_model_package`.** The model version is the one the build was + made with (`built_with_model_package` in its manifest). +- **`compatibility_checked_exact_pair`.** `check-compatibility` passed for + exactly this build, model wheel and core (see + [the compatibility check](#the-compatibility-check)). + `certify-data --compatibility-record ` certifies on that record, and + `--regional-compatibility-record ` routes regions to the local-area + build on its own record. The record is stored in + `src/policyengine/data/compatibility/.json`, and a model accepts + the certificate at load time only for that build, wheel and core. A record + never applies to the build's own model or together with a qualified pair. + `certify-build` uses this basis whenever the model is not the build's own. +- **`legacy_compatible_model_package`.** The publisher's + `compatible_model_packages` claim covers the model version. It is recorded + with a warning; the claim is made good only by this repository's test suite + passing on the pinned pair. A compatibility record replaces it when both + apply. +- **`qualified_exact_pair`.** A receipt of the retired UK qualification + workflow (`--qualified-pair-id`). No .py release has pinned a certificate + on it, and no new certification uses it. + +### The compatibility check ```bash -python scripts/bundle.py certify-data --country us --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-national//release_manifest.json" \ - --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-local//release_manifest.json" \ - --model-version "" +python scripts/bundle.py check-compatibility --country \ + --manifest-uri "hf://dataset/@/releases///release_manifest.json" \ + --model-version "" \ + [--core-version ""] \ + --work-dir \ + --output record.json ``` -US state and congressional-district regions are row filters over one shared, -certified ACS-local Microcosm dataset. Its release manifest must declare -`dataset_role: non_default_local_area`, `is_default: false`, no default -datasets, and exactly one pinned H5 microdata artifact. Certification writes -each dataset's path in its build folder: +It checks one build against one model version and runs from a checkout of +.py. It passes only when all of these hold: + +1. The build's manifest passes the checks `certify-data` makes before it + downloads anything: a listed build in its own release folder, a recorded + build model and core, and a SHA-256 for every microdata H5 file. +2. Each H5 file, downloaded and verified against the manifest's SHA-256, + stores no column that the build's model defines and the new model does + not. The build's model is read in a throwaway `uv run --isolated` with the + build's model and core versions; the new model in the sample run's + environment. +3. A 2,000-household sample of each file loads and runs through .py under + exactly the new model's PyPI wheel (checked against PyPI's SHA-256) and + the core, and every headline variable has a finite, positive weighted + total: `household_net_income` and `income_tax`, plus `universal_credit`, + `child_benefit`, `state_pension`, `pension_credit` and `housing_benefit` + for the UK, and `snap`, `ssi` and `social_security` for the US. + +The sample is fixed by the household IDs: each ID, written as its decimal +integer, is ranked by the SHA-256 of +`policyengine-compatibility-sample-v1:`, and the 2,000 lowest-ranked are +kept (every household when a file has 2,000 or fewer). The core defaults to +the bundle's pin. The `--work-dir` folder holds the downloaded wheel and H5 +files; files already there with the expected SHA-256 are reused. + +A pass writes the record to `--output`: the build, named by the SHA-256 of +its `release_manifest.json`; the model, named by its wheel's SHA-256; the +core version; the sample's method and the SHA-256 of its IDs; and each file's +result. A failure exits 1 and says why. + +### The scheduled workflow + +`.github/workflows/check-model-compatibility.yaml` runs at 06:17 UTC on +Tuesdays and Fridays, and by hand for one country and a named version. For +each country whose newest `policyengine-us` or `policyengine-uk` release the +bundle doesn't pin yet, and which has no certification pull request for it, +it runs `certify-build` on the builds the bundle pins with that version. A +pass opens a draft pull request from branch +`certify//-`; a failure opens or comments on +the country's "Model compatibility check failed" issue. Every run uploads a +`compatibility-` result file. A person reviews and merges the pull +request; earlier ones stay open. The +[runbook](../runbooks/microcosm-certification.md#the-scheduled-workflow) has +the details. + +### Regional routes + +US state and congressional-district regions, and UK constituency and +local-authority regions, are row filters over one shared, certified +local-area dataset. Certify a national build with one of these routes +(`certify-build` options; `certify-data` takes the matching manifest flags): + +- **A local-area build** (`--local-area-build`, or `certify-data + --regional-manifest-uri`). Its release manifest must declare + `dataset_role: non_default_local_area`, `is_default: false`, no default + datasets, and exactly one pinned H5 microdata artifact. Certification + records `regional_release_kind: local_area`. For the UK, the default region + registry then includes all 650 constituencies and 361 local authorities; + policyengine-sim-api accepts a UK default without area codes + (`constituency_code_oa`, `la_code_oa`) only when both are routed. +- **The local-area build the bundle routes to now** + (`--keep-regional-release`). +- **No local-area build** (`--drop-regional-release`). Area regions then + filter the national dataset. + +Certification checks that the local-area build serves the pinned model, by +its own build model, a compatibility record or its compatibility claims; +checks its core claims as for the national build (below); and HEAD-checks +every artifact it carries. + +Certification writes each dataset's path in its build folder, for example +for the US: ```json "region_datasets": { @@ -340,39 +218,110 @@ each dataset's path in its build folder: } ``` -The ACS-local artifact is a second entry in `data_releases.us.datasets`; it is -not a dataset overlay and it never replaces the national `default_dataset`. +The local-area artifact is a second entry in `data_releases..datasets`; +it is not a dataset overlay and it never replaces the national +`default_dataset`. If a Microcosm release publishes derived `states/*.h5` or +`districts/*.h5` files for compatibility checks, certification omits them +from the runtime bundle. -If the Microcosm release publishes derived `states/*.h5` or `districts/*.h5` -files for compatibility checks, certification omits them from the runtime -bundle. The country-wide default and ACS-local dataset are each single shared -files; region registries select one and then filter its rows. +#### An older local-area build, on an accepted mismatch -**An older ACS-local release, on an accepted mismatch.** When the bundle -moves to a policyengine-us the ACS-local release was neither built with nor -claims, route it on an accepted mismatch as for the UK: audit the H5 with the -exact target installed, then certify with the reason and the evidence. +`certify-build` checks the local-area build against the model version with +the compatibility check, so an accepted mismatch is needed only when that +check can't be run and a reviewer accepts routing regions to a local-area +build that neither was built with nor claims the target model. Run +`certify-data` by hand with a reason and a byte-bound audit of the build's +input columns. First audit the actual local H5 with the exact target model +installed; the audit also needs `uv` and access to PyPI: ```bash .venv/bin/python scripts/audit_regional_input_surface.py \ - --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-local//release_manifest.json" \ - --artifact "populace_us_2024_acs_local=/local/populace_us_2024_acs_local.h5" \ - --model-version "" \ + --regional-manifest-uri "hf://dataset/@/releases///release_manifest.json" \ + --artifact "=/local/.h5" \ + --model-version "" \ --audited-by "" \ --limitation "" \ --output regional-input-surface.json -.venv/bin/python scripts/bundle.py certify-data --country us --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-national//release_manifest.json" \ - --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-local//release_manifest.json" \ +.venv/bin/python scripts/bundle.py certify-data --country --data-producer populace \ + --manifest-uri "hf://dataset/@/releases///release_manifest.json" \ + --regional-manifest-uri "hf://dataset/@/releases///release_manifest.json" \ --accept-regional-model-mismatch "" \ --regional-input-surface-evidence regional-input-surface.json \ - --model-version "" + --model-version "" ``` -The audit, the comparison and the record are the UK's (see the accepted -mismatch under [UK constituency and local-authority regions](#uk-constituency-and-local-authority-regions)), -with three US differences: +The audit compares the entity-table columns the H5 actually stores, in each +period, with two models: the build model and core the regional manifest +records (`built_with_model_package` and `built_with_core_package`), and the +target. The build model is the baseline: + +- **Dropped columns** are stored columns the build model defines and the + target does not. The target's loaders skip them. Certification refuses + **any dropped column**; there is no override. +- **Never-modelled columns** are stored columns neither model defines: + Microcosm's own area codes (among them `constituency_code_oa` and + `la_code_oa`), build and source ids, clone indices and SPI donor fields. + No model ever loaded them, so they are recorded, not refused. +- **Defaulted inputs** are target inputs the file does not store, after the + target's input aliases, that were not inputs of the build model. Area runs + default them where the build model did not. Inputs absent under both + models are not changes. + +The audit reads the build model's variables and inputs in a throwaway +`uv run --isolated --no-project --no-config --default-index +https://pypi.org/simple --exclude-newer --with +== --with policyengine-core==` environment, so +it needs `uv` and access to PyPI. `--isolated` makes the environment fresh: +without it, uv reuses an environment that already meets both pins, such as +a `.venv` in the working directory, and neither the index nor the cutoff +applies. `--exclude-newer` is the manifest's build time, so the build +model's other dependencies resolve as they did then, and every `UV_*` +setting except the cache, Python-install and connection ones is removed. A +regional manifest that does not record both build versions has no +baseline, and one without `built_at` cannot be read as of its build; the +audit refuses both. The evidence binds the regional release identity, +original manifest bytes, actual H5 bytes, both build versions and the exact +target model version, and keeps both models' full variable and input lists. + +Certification does not trust those lists. It reads the target model in +process, so the environment that runs `certify-data` must have the target +model installed, as the audit's does, and reads the build model again with +`uv`; any list or input alias that differs refuses. Only the stored columns +rest on the auditor's word: they cannot be re-read without the H5, and the +evidence binds them to its SHA-256. The record says so, with +`stored_columns: auditor_attested`. Certification then recomputes all three +lists and refuses missing or mismatched evidence, including evidence without +`schema_version: 2`. It records the never-modelled columns, every defaulted +input and the free-text limitations in the validated +`regional_certification`, and adds one limitation naming the defaulted +inputs; the bundle hash binds that record. + +Model dataset loaders silently skip columns absent from the model's +variables (policyengine-uk 2.147.2's +[generic dataset loader](https://github.com/PolicyEngine/policyengine-uk/blob/fe0b99a36bd309a722b19937345e34290cb6dd73/policyengine_uk/simulation.py#L1113-L1127) +and +[UK multi-year loader](https://github.com/PolicyEngine/policyengine-uk/blob/fe0b99a36bd309a722b19937345e34290cb6dd73/policyengine_uk/simulation.py#L1186-L1196) +both use `continue` without warning). A removed or renamed input can +therefore disappear silently at runtime; the audit, like the compatibility +check, must catch that column loss before certification. + +The national certificate never widens. Area status remains `uncertified`: +the certificate still covers the national dataset only (#685). TRACE +carries the whole regional record, evidence included, separately from the +national certification. A UK area run's execution receipt carries a summary +of it (both model versions, the reason, the three lists and the +limitations) and `record_sha256`, the digest of the whole record; check it +with `verify_regional_certification`. A national receipt carries none: its +`certificate_sha256` already digests the record. .py writes execution +receipts for UK results only, so a US run carries no per-run record; the US +record is `data_releases.us.regional_certification` in the bundle manifest +and the US TRO. An empty or invisible reason, a release that already covers +the target model, or a missing regional release refuses. The regional core +checks still apply. Re-certifying with `--drop-regional-release` removes the +regional record, routes and artifact. + +The US audit differs from the UK's in three ways: - **The file layout.** The audit reads either layout .py's US loader reads, and only names, never values. The Microcosm ACS-local release stores entity @@ -400,31 +349,73 @@ with three US differences: - **The models.** The build model is read with `--with policyengine-us==`, and certification runs with the target policyengine-us installed. -.py writes execution receipts for UK results only, so a US run carries no -per-run record of the exception. The record is `data_releases.us.regional_certification` -in the bundle manifest, its evidence included, and the US TRO, which carries -it separately from the national certification. The national certificate -itself does not change. +After the receipt schema changes, refresh the Budget dashboard's vendored +`tests/fixtures/w4/execution_receipt.v1.schema.json` from +`src/policyengine/data/schemas/execution_receipt.v1.schema.json`. -The script fetches and validates the manifest (every artifact must carry a -revision pin; the certified dataset must be reachable), writes the canonical -bundle manifest, exact-pins the country model package in that same manifest, -regenerates derived bundle metadata, and writes a Towncrier changelog fragment. +### The core -Private data (UK) requires `HUGGING_FACE_TOKEN` or `HF_TOKEN`. +The bundle has one core pin, `packages.policyengine-core`, shared by every +country. A certificate says how it covers it: -After running: +- **`core_binding: bundle_pin` (the default, no `--core-version`).** The + certificate names no core and certifies whatever core the bundle pins, so + the pin can move with another country without re-certifying this one. + Certification checks the pin against each release's build-time core and + core claims, and warns, without refusing, when the pin is outside them. + `bundle.py check --include-tros --strict-tros` warns the same way when the + pin later moves outside the claims. Receipts then certify the pin without + the release's claim; the warning, the certificate and its TRO say so. +- **`core_binding: certified` (`--core-version`).** The certificate names the + core (`certified_for_core_version`). Certification refuses a core that a + release neither was built with nor claims, and the strict check refuses a + pin that differs from the named core, so moving the core needs a + re-certification first. `certify-build --core-version` also moves the + bundle's core pin to it. + +A compatibility record names the core it ran with, and a model accepts a +certificate on that record only with that core. Use the default unless a +release must not run on any other core. + +### Re-certifying a routed bundle -- run `python scripts/bundle.py check`, -- run the full test suite — snapshot drift from a model bump is refreshed - with `PE_UPDATE_SNAPSHOTS=1 pytest tests/test_household_calculator_snapshot.py`, -- commit `src/policyengine/data/bundle/manifest.json`, `pyproject.toml`, the - Towncrier fragment, and any regenerated TRO sidecars together. +Certification rewrites `data_releases.` from the manifests it is +given. While the bundle routes regions (`regional_source_manifest_uri` is set), +a `certify-data` run without `--regional-manifest-uri` is refused; pass the +current regional release again (or its replacement), or +`--drop-regional-release` to remove the routing on purpose. The two flags +cannot be combined. `certify-build` always asks for one route. + +An overlay may never shadow a certified dataset name, so certification removes +any `dataset_overlays.` entry whose name the new release certifies. +`bundle.py check` refuses a bundle with an overlay that shadows a certified +name. + +Removed overlays do not come back by themselves. Certification warns about +every dataset name that stops resolving. After a certification that stops +certifying a name that must stay loadable, re-add its overlay from the +previous bundle, as #685 did for `enhanced_frs_2024_25`, `frs_2024_25` and +their `_tiny` files. + +### What a certification changes + +`certify-data` fetches and validates the manifest (every artifact must carry +a revision pin; the certified dataset must be reachable), writes the +canonical bundle manifest, exact-pins the country model package in that same +manifest, regenerates derived bundle metadata, and writes a Towncrier +changelog fragment. `certify-build` then regenerates the lock, the TRACE +sidecars, the certified constants tests pin and the household snapshots, and +runs `bundle.py check --published-spm --include-tros --strict-tros`. The +pull request's CI runs the test suite; don't run the full suite locally. + +Private data (UK) requires `HUGGING_FACE_TOKEN` or `HF_TOKEN`. A certification PR should normally change only: - `src/policyengine/data/bundle/manifest.json` (+ `{country}.trace.tro.jsonld`) -- `pyproject.toml` +- `src/policyengine/data/compatibility/.json`, on a compatibility + record +- `pyproject.toml` and `uv.lock`, when a pin moved - one Towncrier fragment under `changelog.d/` - test constants/snapshots that pin certified versions @@ -433,29 +424,30 @@ A certification PR should normally change only: Hard failures (certification refuses): missing national default dataset, default dataset absent from artifacts, any artifact without a revision pin, unreachable certified dataset, missing required supplemental release files -(for example Microcosm-US `us_source_coverage.json`), a malformed shared -local-area release, area-coded national release or legacy per-state artifacts -when `--regional-manifest-uri` is used, a regional release that does not serve -the pinned model version, an unreachable regional artifact, a re-certification -that would silently drop regional routing, unknown country. - -Certification gate: the model version must either exactly match the -build-time model (`compatibility_basis: built_with_model_package`) or be -covered by the publisher's `compatible_model_packages` claim -(`compatibility_basis: legacy_compatible_model_package`, recorded with a -warning — the publisher's claim is made good only by this repo's test -suite passing on the pinned pair). Neither basis means certification is -refused: a new data build or a published compatibility claim is required. - -Warnings (recorded, not blocking): artifacts without sha256, and the -publisher-claim basis above. +(for example Microcosm-US `us_source_coverage.json`), a build outside its own +release folder or not listed in `releases.json`, a withdrawn build, a tagged +manifest address in a repository with `releases.json`, a malformed shared +local-area release or legacy per-state artifacts when +`--regional-manifest-uri` is used, a regional release that does not serve the +pinned model version, an unreachable regional artifact, a re-certification +that would silently drop regional routing, a compatibility record that names +another build, wheel or core, unknown country. + +Certification refuses a model version that none of the +[compatibility bases](#compatibility-bases) covers: a new data build, a +passed compatibility check or a published compatibility claim is required. + +Warnings (recorded, not blocking): artifacts without sha256, the +publisher-claim basis, and a core pin outside a release's core claims under +`core_binding: bundle_pin`. ## Acceptance evidence for a UK default switch -A PR that changes the UK default dataset carries, besides the UK candidate -qualification gates, the Universal Credit coverage floor from #491: benefit -units with Universal Credit and Universal Credit spend in Great Britain within -10% of DWP's and the OBR's figures. +A PR that changes the UK default dataset carries the Universal Credit +coverage floor from #491: benefit units with Universal Credit and Universal +Credit spend in Great Britain within 10% of DWP's and the OBR's figures. +`certify-build` runs it for every UK certification and reports a failure in +the pull request body. To run it alone: ```bash python scripts/check_uk_uc_floor.py --dataset \ @@ -470,43 +462,107 @@ Before quoting any other figure from UK data in a PR, apply the UKDS output rules: no unit-record values, no cells under 10 unweighted cases, no differencing. -**Recorded exceptions (policyengine.py#685, October 2026).** +## Release runbooks + +Concrete, fill-in-the-id runbooks live under `docs/engineering/runbooks/`. +[`runbooks/microcosm-certification.md`](../runbooks/microcosm-certification.md) +is the US and UK certification procedure. + +## Earlier certifications -- **UC floor.** The Microcosm UK national cut +This section is history. Current .py refuses the tagged addresses below for +`policyengine/populace-us` and `policyengine/populace-uk-private`, which now +have `releases.json`; certify every build from its own folder. + +**Tagged release folders.** Before the build folders, each build of a +Microcosm release rewrote that release's `releases//` folder, and +each build was pinned by a Hugging Face tag. Certification read: + +```text +hf://dataset/policyengine/populace-uk-private@/releases//release_manifest.json +hf://dataset/policyengine/populace-us@/releases//release_manifest.json +``` + +Microcosm recorded the release name as `build.build_id` and the tag in +`build.cut_tag`, and certification used the tag as the build id. The US +runbook of that time passed `@$NATIONAL_RELEASE_ID/releases/$NATIONAL_RELEASE_ID/` +and `@$LOCAL_AREA_RELEASE_ID/releases/$LOCAL_AREA_RELEASE_ID/` for the +national and local-area releases. + +**The enhanced FRS as the UK area route.** Before a UK local-area build +existed, UK area regions were routed to a certified policyengine-uk-data +release whose households carried area codes +(`--regional-release-kind area_coded_national`, with +`--regional-manifest-uri "hf://model/policyengine/policyengine-uk-data-private@/releases//release_manifest.json"`). +Certification carried its `enhanced_frs_2024_25` and its area weight +matrices, recorded `regional_release_kind: area_coded_national`, and left +area regions out of the default registry. A rollback to policyengine-uk-data +with `--drop-regional-release` removed the enhanced FRS overlays. No current +certification uses this route. + +**The UK qualification workflow.** `certify-uk-release.yaml` qualified each +new policyengine-uk wheel or uk-data release before promotion and recorded a +receipt in the `uk-qualification-ledger` branch, the basis +`qualified_exact_pair`. The compatibility check and the scheduled workflow +replace it. + +**The UK default switch (policyengine.py#685, October 2026).** + +- **UC floor.** The Microcosm UK national build `microcosm-uk-2024-25-national-20261019T083323Z-6cba5d71` became the default with benefit units at 0.897 of the floor's 6.7m benchmark; spend passed at 0.959. The floor's benchmarks are not the figures Microcosm calibrates to (DWP Stat-Xplore's 6.2m households on Universal Credit in payment, and its own - OBR spend line). Their definitions are to be settled when the UK data checks - move to the data pipelines. Until then, a later Microcosm cut with the same + OBR spend figure). Their definitions are to be settled when the UK data checks + move to the data pipelines. Until then, a later Microcosm build with the same gap needs the same explicit acceptance in its pull request, recorded here. -- **Comparison gates.** The metrics review and the scorecard replay measure a - candidate against the previous certified pair, and a change of data line +- **Comparison checks.** The metrics review and the scorecard replay measure a + candidate against the previous certified pair, and a change of data source moves the totals by design, so they were not run for that switch; its pull - request compares the two lines' weighted totals instead. The other gates, - reform responsiveness included, were run on the national cut. + request compares the two sources' weighted totals instead. The other + qualification checks, reform responsiveness included, were run on the + national build. - **Budget-critical inputs: needs review.** `incapacity_benefit_reported` is missing from the Microcosm file but was a column of the enhanced FRS. The enhanced FRS column carries no values (Incapacity Benefit is closed), so both datasets give zero. Accepted by María Juaristi in #685. - **Reform responsiveness: needs review.** The metrics tool's small-cell rule - withholds a standard reform's figures, so the gate cannot recompute that + withholds a standard reform's figures, so the check cannot recompute that reform's verdict. Accepted by María Juaristi in #685. -## Release runbooks - -Concrete, fill-in-the-id runbooks that replay a specific certification live -under `docs/engineering/runbooks/`. See -`runbooks/build-m-us-populace-certification.md` for the reusable US national -and local-area certification procedure. The historical filename is retained -so existing links remain valid. - -## Legacy paths - -Do not hand-edit bundle data releases for normal updates. Countries whose -current data release predates release manifests need a data-producer strategy -before they can be updated through this path. - -The retired `policyengine-bundles` flow (candidates → generated bundle → -archive import) is preserved read-only in that repo's history; bundles -4.15.x–4.16.x remain the historical record of earlier certifications. +**The dense build's input audit (#699).** For the Budget route, the audit of +dense build `microcosm-uk-2024-25-dense-20261019T000432Z-ee5c2dbe`, built +with policyengine-uk 2.132.6 and policyengine-core 3.33.3, measured: + +- **83 never-modelled columns**, and **no dropped column** under either + 2.147.2 or 2.151.0. The first version of the audit counted those 83 as + dropped and refused the build, even against its own build model. +- **16 new defaults under 2.147.2:** + `additional_residential_property_purchased`, + `defined_benefit_pension_share`, `directly_held_shares`, + `early_years_school_start_deferred`, `is_full_year_category_a_director`, + `local_bus_uncapped_single_fare`, `non_residential_property_purchased`, + `non_residential_property_secured_debt`, + `other_residential_property_secured_debt`, + `pension_annual_allowance_taxable_lump_sum_death_benefits`, + `pension_contributions_via_salary_sacrifice_pre_2015`, `pip_dl_points`, + `pip_m_points`, `salary_sacrifice_returned_to_income`, + `unit_and_investment_trusts`, and `war_widows_pension_reported`. +- **37 new defaults under 2.151.0:** those 16 and 21 more. The 21 include + the gambling duty inputs, liquid and solid fuel consumption, and bonus + sacrifice (`pension_contributions_via_bonus_sacrifice`), so area + breakdowns of those measures use defaults on 2.151.0. +- Another **123 inputs already defaulted under 2.132.6**. They are absent + under both models, so they are not changes; the first version listed + them too, giving 139 defaults under 2.147.2 and 160 under 2.151.0. + +That build's accepted mismatch recorded a limitation: its VAT predates the +policyengine-uk VAT factor fix (#2187, 2.135.7), and the dashboard holds a +VAT limit. + +**Before release manifests.** Countries whose current data release predates +release manifests need a data-producer strategy before they can be updated +through this path; do not hand-edit bundle data releases. The retired +`policyengine-bundles` flow (candidates → generated bundle → archive import) +is preserved read-only in that repo's history; bundles 4.15.x–4.16.x remain +the historical record of earlier certifications. diff --git a/docs/release-bundles.md b/docs/release-bundles.md index b4f8199ec..501ce1bf5 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -1,14 +1,16 @@ # Release Bundles -> **Current process.** Certification now runs inside this repository: -> `scripts/bundle.py certify-data` derives the vendored country manifest -> directly from a country's data release manifest (see the +> **Current process.** Certification runs inside this repository: +> `scripts/bundle.py certify-build` checks a US or UK Microcosm build against +> a model version and certifies it, deriving the vendored country manifest +> directly from the build's release manifest (see the > [data certification](engineering/skills/data-certification.md) -> engineering skill). The intermediate `policyengine-bundles` repository -> flow is retired; its published bundles remain the historical record of -> earlier certifications. The architecture below — country `*-data` -> repos publish immutable manifests, `policyengine.py` certifies — is -> unchanged. +> engineering skill and the +> [Microcosm certification runbook](engineering/runbooks/microcosm-certification.md)). +> The intermediate `policyengine-bundles` repository flow is retired; its +> published bundles remain the historical record of earlier certifications. +> The architecture below — the data producer publishes immutable build +> manifests, `policyengine.py` certifies — is unchanged. This document defines the intended reproducibility boundary for `policyengine.py`. @@ -69,11 +71,11 @@ before merge, and compare the eventual published wheel against that receipt. The key design decision is: -- country `*-data` repos build and stage immutable data artifacts +- the data producer (Microcosm) builds and publishes immutable data artifacts - `policyengine.py` is the only component that certifies supported runtime bundles - `policyengine.py` does not rebuild country data itself -This keeps country-specific data construction in the country data repos while still giving users a single top-level version to cite and pin. +This keeps country-specific data construction in the data producer while still giving users a single top-level version to cite and pin. ## Installing a certified bundle @@ -164,7 +166,9 @@ It does not own final runtime bundle certification. ### Country data package -Examples: `microcosm-data`, `policyengine-uk-data` +Example: `microcosm-data`, Microcosm's data package, which publishes US +builds to `policyengine/populace-us` and UK builds to +`policyengine/populace-uk-private`. The country data package owns: @@ -172,7 +176,8 @@ The country data package owns: - raw input acquisition - calibration target snapshots - expensive dataset construction -- staging immutable build artifacts with provenance +- publishing each build, with its provenance, in its own immutable folder, + `releases///`, listed in the repository's `releases.json` It does not define the final supported runtime bundle exposed to users. @@ -189,19 +194,23 @@ It does not rebuild microdata artifacts. Certification runs in this repository: `src/policyengine/data/bundle/manifest.json` carries the certified `data_releases.{country}` entry derived directly from the country's published -data release manifest. The entrypoint is: +build manifest. The same command certifies a Microcosm build of either +country, named by release and build: ```bash -python scripts/bundle.py certify-data --country us \ - --manifest-uri "hf://dataset/policyengine/populace-us@/releases//release_manifest.json" +python scripts/bundle.py certify-build --country us \ + --national-build \ + --local-area-build \ + --model-version "" ``` -US Microcosm certification uses the Microcosm release manifest directly: +It runs the [compatibility check](#compatibility-rule) on each build, then +`certify-data` with each build's own folder at the commit that published it: ```bash python scripts/bundle.py certify-data --country us --data-producer populace \ - --manifest-uri "hf://dataset/policyengine/populace-us@/releases//release_manifest.json" \ - --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases//release_manifest.json" \ + --manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-national//release_manifest.json" \ + --regional-manifest-uri "hf://dataset/policyengine/populace-us@/releases/microcosm-us-2024-local//release_manifest.json" \ --model-version "" ``` @@ -209,7 +218,9 @@ That produces one US bundle manifest entry containing the Microcosm national default dataset and the certified ACS-local regional dataset. State and congressional-district simulations use the latter with runtime row filters, so derived `states/*.h5` or `districts/*.h5` files are not vendored into -`data_releases.us.datasets`. +`data_releases.us.datasets`. The UK is certified the same way, from +`policyengine/populace-uk-private`, with its local-area build routing +constituency and local-authority regions. ### Non-default dataset overlays @@ -273,61 +284,42 @@ The architecture has two manifest layers with different responsibilities. ### 1. Data build manifest -Published by the country `*-data` repo. +Published by the data producer, as each build's `release_manifest.json` in +its own folder, `releases///`. This answers: - what bytes were produced - how they were produced -- which exact model and targets produced them +- which exact model and core produced them -Suggested schema: +Abridged example (a Microcosm US national build): ```json { "schema_version": 1, - "country_id": "uk", - "data_package": { - "name": "policyengine-uk-data", - "version": "1.41.0" - }, - "build": { - "build_id": "uk-data-2026-04-12T12-30-00Z", - "git_sha": "abc123", - "built_at": "2026-04-12T12:30:00Z", - "built_with_model_package": { - "name": "policyengine-uk", - "version": "2.81.0", - "git_sha": "def456", - "data_build_fingerprint": "sha256:..." - }, - "calibration_targets": { - "snapshot_id": "2026-04-10", - "sha256": "sha256:..." - }, - "raw_inputs": [ - { - "name": "frs_2023_24", - "sha256": "sha256:..." - } - ], - "build_environment": { - "python_version": "3.13.3", - "lockfile_sha256": "sha256:..." - } - }, - "default_datasets": { - "national": "enhanced_frs_2023_24", - "baseline": "frs_2023_24" - }, + "release": "microcosm-us-2024-national", + "build": "", + "built_at": "", + "built_with_model_package": {"name": "policyengine-us", "version": ""}, + "built_with_core_package": {"name": "policyengine-core", "version": ""}, + "compatible_model_packages": [], + "compatible_core_packages": [], + "data_package": {"name": "microcosm-data", "version": ""}, + "default_datasets": {"national": "populace_us_2024"}, "artifacts": { - "enhanced_frs_2023_24": { + "populace_us_2024": { "kind": "microdata", - "repo_id": "policyengine/policyengine-uk-data-private", - "path": "builds/uk-data-2026-04-12T12-30-00Z/enhanced_frs_2023_24.h5", - "revision": "uk-data-2026-04-12T12-30-00Z", - "sha256": "sha256:...", - "size_bytes": 123456789 + "role": "dataset", + "repo_id": "policyengine/populace-us", + "path": "populace_us_2024.h5", + "sha256": "" + }, + "build_manifest": { + "kind": "evidence", + "repo_id": "policyengine/populace-us", + "path": "build_manifest.json", + "sha256": "" } } } @@ -335,8 +327,11 @@ Suggested schema: Notes: -- `build_id` must be immutable. -- build artifacts should be staged under a build-specific path or revision, not a floating release tag. +- a build folder is never changed after it is published, and has no Hugging + Face tag; certification pins the commit that holds it. +- each artifact's `path` is a bare file name inside the build's folder. +- `releases.json` at the repository root lists every build of each release, + which one is current, and which are withdrawn. - the build manifest is the authoritative provenance record for the artifact bytes. ### 2. Certified runtime bundle manifest @@ -349,40 +344,40 @@ This answers: - which exact dataset should be used by default - which artifact checksum and provenance should be surfaced to users -Suggested schema: +Abridged example (`data_releases.uk` in `src/policyengine/data/bundle/manifest.json`): ```json { "schema_version": 1, - "policyengine_version": "3.5.0", - "bundle_id": "uk-3.5.0", - "published_at": "2026-04-12T13:00:00Z", + "policyengine_version": "", + "bundle_id": "uk-", "country_id": "uk", "model_package": { "name": "policyengine-uk", - "version": "2.81.1" + "version": "" }, "certified_data_artifact": { "data_package": { - "name": "policyengine-uk-data", - "version": "1.41.0" + "name": "microcosm-data", + "version": "" }, - "build_id": "uk-data-2026-04-12T12-30-00Z", - "dataset": "enhanced_frs_2023_24", - "uri": "hf://policyengine/policyengine-uk-data-private/builds/uk-data-2026-04-12T12-30-00Z/enhanced_frs_2023_24.h5@uk-data-2026-04-12T12-30-00Z", - "sha256": "sha256:..." + "build_id": "", + "dataset": "microcosm_uk_2024_25", + "uri": "hf://policyengine/populace-uk-private/releases/microcosm-uk-2024-25-national//microcosm_uk_2024_25.h5@", + "sha256": "" }, "certification": { - "compatibility_basis": "matching_data_build_fingerprint", - "built_with_model_version": "2.81.0", - "certified_for_model_version": "2.81.1", - "data_build_fingerprint": "sha256:...", - "certified_by": "policyengine.py release workflow" + "compatibility_basis": "compatibility_checked_exact_pair", + "built_with_model_version": "", + "certified_for_model_version": "", + "core_binding": "bundle_pin", + "data_build_id": "", + "certified_by": "policyengine.py bundle certification" }, - "default_dataset": "enhanced_frs_2023_24", - "region_artifacts": { + "default_dataset": "microcosm_uk_2024_25", + "region_datasets": { "national": { - "dataset": "enhanced_frs_2023_24" + "path_template": "releases/microcosm-uk-2024-25-national//microcosm_uk_2024_25.h5" } } } @@ -423,9 +418,9 @@ without parsing prose. Every TRO also carries `pe:emittedIn` set to `"github-actions"` or `"local"`; CI-emitted TROs additionally carry `pe:ciRunUrl` and `pe:ciGitSha`. -Country `*-data` repos should also emit a matching `trace.tro.jsonld` per +The data producer should also emit a matching `trace.tro.jsonld` per data release covering the release manifest and every staged artifact hash. -That is a country-data concern and lives in those repos. +That is a data-producer concern and lives in its repositories. #### Emitting a bundle TRO @@ -609,84 +604,98 @@ That is why the recommended design is: ## Compatibility rule -The architecture should avoid forcing a new data build for every harmless country model release. +The architecture avoids forcing a new data build for every harmless country +model release. A build made with one model version may be certified for +another only when compatibility is shown explicitly, and the same rules apply +to US and UK builds. -To do that safely, compatibility must be explicit. +### The compatibility check -### Data build fingerprint +`python scripts/bundle.py check-compatibility` checks one Microcosm build +against one model version, from a checkout of .py: -Each country model package should expose a `data_build_fingerprint` that covers the subset of logic that affects dataset construction or calibration. +- the build's manifest passes `certify-data`'s metadata checks; +- every microdata H5 file, verified against its SHA-256, stores no column + that the build's model defines and the new model does not; +- a fixed 2,000-household sample of each file runs through .py under exactly + the new model's PyPI wheel and the core, with finite, positive weighted + totals for net income, income tax and the main benefits. -Examples of inputs to the fingerprint: - -- variables used in imputations -- variables used in calibration loss matrices -- parameters referenced during data construction -- uprating or target-computation logic used during the build - -Things that should usually not affect the fingerprint: - -- runtime-only outputs that are not used in data construction -- UI-oriented metadata -- code paths unrelated to data construction +A pass writes a record naming the build by the SHA-256 of its +`release_manifest.json`, the model by its wheel's SHA-256, and the core. The +[data certification](engineering/skills/data-certification.md#the-compatibility-check) +skill describes the check in full. ### Certification rules -`policyengine.py` may certify a staged data artifact for a model version only if one of the following is true: +`policyengine.py` may certify a build for a model version only if one of the +following is true: -1. the model version exactly matches the `built_with_model_package.version` +1. the model version exactly matches the build's `built_with_model_package` (`compatibility_basis: built_with_model_package`) -2. the data publisher's `compatible_model_packages` covers the model version - (`compatibility_basis: legacy_compatible_model_package` — the publisher's claim, - recorded with a warning and made good by the test suite passing on the - pinned pair) - -If neither is true, certification fails hard and a new data build or a -published compatibility claim is required. A `data_build_fingerprint` -basis (same fingerprint as the build-time model) is a planned third -basis; it requires fingerprint metadata from the installed model package. +2. the compatibility check passed for exactly this build, model wheel and core + (`compatibility_basis: compatibility_checked_exact_pair`). `certify-data + --compatibility-record` (or `--regional-compatibility-record` for the + local-area build) certifies on the record and stores it in + `src/policyengine/data/compatibility/.json`; a model loads the + certificate only for that build, wheel and core +3. the data publisher's `compatible_model_packages` covers the model version + (`compatibility_basis: legacy_compatible_model_package` — the publisher's + claim, recorded with a warning and made good by the test suite passing on + the pinned pair) + +If none is true, certification fails hard and a new data build, a passed +compatibility check or a published compatibility claim is required. ## Artifact states Artifacts should move through explicit states: -- `staged`: built by the country data repo and available for inspection or later certification +- `staged`: built and published by the data producer and available for inspection or later certification - `certified`: referenced by a released `policyengine.py` runtime bundle - `deprecated`: no longer recommended for new use, but still reproducible The key point is that `staged` and `certified` are different states. A staged artifact is not automatically part of a supported runtime release. -## UK release workflow - -### Case 1: model-only release - -1. Cut UK model release candidate `M`. -2. Compute `data_build_fingerprint(M)`. -3. Compare it to the fingerprint recorded in the previously certified data build manifest. -4. If the fingerprint matches, skip the expensive UK data rebuild. -5. Release `policyengine.py` with a new certified runtime bundle that points to the existing staged UK artifact. - -### Case 2: data-affecting release - -1. Cut UK model release candidate `M`. -2. Compute `data_build_fingerprint(M)`. -3. If the fingerprint changed, build a new UK data artifact in `policyengine-uk-data` against: - - exact `policyengine-uk==M` - - exact target snapshot - - exact raw input hashes -4. Stage the new artifact under a build-specific immutable path or revision. -5. Publish the UK data build manifest. -6. Release `policyengine.py` with a certified runtime bundle that points to the new staged artifact. +## Release workflow + +The same for the US and the UK: + +### A new model release + +1. The country model package publishes version `M` to PyPI. +2. At 06:17 UTC on the next Tuesday or Friday, + `.github/workflows/check-model-compatibility.yaml` runs `certify-build` for + `M` on the national and local-area builds the bundle pins: the + compatibility check on each build, then certification on its record. +3. A pass opens a draft pull request from branch + `certify//-M`; a failure opens or comments on the + country's "Model compatibility check failed" issue, and no data rebuild + starts. +4. A person reviews and merges the pull request, and the next + `policyengine.py` release ships a runtime bundle certifying the existing + builds for `M`. Pull requests for earlier versions stay open, so any + version that passed can be chosen. + +### A new data build + +1. Microcosm publishes a build in its own folder and lists it in + `releases.json`. +2. A person runs `certify-build` with the new national build, the local-area + build and the model version (the build's own by default), following the + [Microcosm certification runbook](engineering/runbooks/microcosm-certification.md). +3. Its draft pull request is reviewed and merged, and the next + `policyengine.py` release ships a runtime bundle that points to the new + build. ## Implementation guidance -The current `release_manifest.json` mechanism in country data repos is a good starting point, but it is not yet enough on its own. The target implementation should add: +Microcosm's build manifests record the build's model and core +(`built_with_model_package`, `built_with_core_package`) and publish each build +in an immutable folder. They could still add: -- `built_with_model_package.version` -- `built_with_model_package.git_sha` -- `built_with_model_package.data_build_fingerprint` +- the model package's git SHA - calibration target snapshot metadata -- immutable staged artifact paths or revisions The target implementation in `policyengine.py` should add: From 4dc42323666efaafe153a86a5ccb39d635cec32a Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:08:23 +0400 Subject: [PATCH 2/5] Follow the earlier tasks' latest changes in the certification docs The compatibility workflow's branches now name the national build, it runs certify-build in place and records cancelled runs; check-compatibility refuses a build's own model and binds the core. Add the changelog fragment for #790. Co-Authored-By: Claude Opus 5.5 --- changelog.d/790.changed.md | 1 + .../runbooks/microcosm-certification.md | 34 +++++++++++-------- docs/engineering/skills/data-certification.md | 27 +++++++++------ docs/release-bundles.md | 2 +- 4 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 changelog.d/790.changed.md diff --git a/changelog.d/790.changed.md b/changelog.d/790.changed.md new file mode 100644 index 000000000..7634d2e7b --- /dev/null +++ b/changelog.d/790.changed.md @@ -0,0 +1 @@ +The certification docs describe certifying a US or UK Microcosm build from its own folder with `scripts/bundle.py certify-build`, the compatibility check and the Tuesday and Friday compatibility workflow. The US certification runbook becomes `docs/engineering/runbooks/microcosm-certification.md` for both countries, and tagged addresses and policyengine-uk-data steps remain only as history. diff --git a/docs/engineering/runbooks/microcosm-certification.md b/docs/engineering/runbooks/microcosm-certification.md index cbf64ba48..f8b3ec3d9 100644 --- a/docs/engineering/runbooks/microcosm-certification.md +++ b/docs/engineering/runbooks/microcosm-certification.md @@ -80,8 +80,8 @@ The one command: 2. reads each build from its own folder at the last commit of its `release_manifest.json` on `main`, after checking that `releases.json` at `main` lists it and has not withdrawn it, and checks the free disk; -3. runs `scripts/bundle.py check-compatibility` for each build with the model - version (see [the compatibility check](../skills/data-certification.md#the-compatibility-check)); +3. runs `scripts/bundle.py check-compatibility` for each build whose own + model is not the version given (see [the compatibility check](../skills/data-certification.md#the-compatibility-check)); 4. runs `scripts/bundle.py certify-data` for the national build with the chosen regional route, using the check's record as the basis whenever the model is not the one the build was made with; @@ -158,19 +158,25 @@ country). - A planning job picks, for each country, the newest `policyengine-us` or `policyengine-uk` release on PyPI (or the version given by hand). It leaves - a country out when the bundle already pins that version or a pull request - for it already exists. -- For each remaining country, a job runs `scripts/bundle.py certify-build` - on the national and local-area builds the bundle pins, with that model - version. A pass pushes branch `certify//-` - and opens a draft pull request with the GitHub App's token, so the pull - request's own workflows run. A person reviews and merges it as in Step 3. - Earlier certification pull requests stay open, so any version that passed - can still be chosen. -- Every run uploads a `compatibility-` result file: the model - version, the builds, whether the check passed, and the pull request. + a country out when the bundle already pins that version, or when the + version's branch already exists, with or without a pull request (open or + closed). A branch pushed without a pull request holds that version back + until someone opens the pull request or deletes the branch. +- For each remaining country, a job runs `scripts/bundle.py certify-build + --in-place` on the national and local-area builds the bundle pins, with + that model version. The checkout holds no GitHub token while the check + runs. A pass then commits the files `certify-build` lists to branch + `certify///-` and opens a + draft pull request with the body `certify-build` wrote, using the GitHub + App's token so the pull request's own workflows run. A person reviews and + merges it as in Step 3. Earlier certification pull requests stay open, so + any version that passed can still be chosen. +- For each country it checks, a run uploads a `compatibility-` + result file: the model version, the builds, whether the run passed, + failed or was cancelled, and the pull request. - A failure opens or comments on the issue "Model compatibility check - failed: US" (or UK); the next pass closes it. + failed: US" (or UK); the next pass closes it, and a cancelled run leaves + it as it is. ## Running the steps by hand diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index ebbdb866a..e09a8e2b4 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -114,8 +114,11 @@ pinned model version. Certification refuses a build that has none of them: `--regional-compatibility-record ` routes regions to the local-area build on its own record. The record is stored in `src/policyengine/data/compatibility/.json`, and a model accepts - the certificate at load time only for that build, wheel and core. A record - never applies to the build's own model or together with a qualified pair. + the certificate at load time only when that file holds a matching record + for the running model and core. The certificate names the core it ran + with. Certification refuses a record for other manifest bytes, another + build, model, wheel or core, and a record given with `--qualified-pair-id`. + Commit the records file with the bundle. `certify-build` uses this basis whenever the model is not the build's own. - **`legacy_compatible_model_package`.** The publisher's `compatible_model_packages` claim covers the model version. It is recorded @@ -138,7 +141,10 @@ python scripts/bundle.py check-compatibility --country \ ``` It checks one build against one model version and runs from a checkout of -.py. It passes only when all of these hold: +.py, with a Hugging Face token that can read the build in +`HUGGING_FACE_TOKEN` or `HF_TOKEN`. It refuses a build whose own model is the +version given: certify that on `built_with_model_package`. It passes only +when all of these hold: 1. The build's manifest passes the checks `certify-data` makes before it downloads anything: a listed build in its own release folder, a recorded @@ -172,13 +178,14 @@ result. A failure exits 1 and says why. `.github/workflows/check-model-compatibility.yaml` runs at 06:17 UTC on Tuesdays and Fridays, and by hand for one country and a named version. For each country whose newest `policyengine-us` or `policyengine-uk` release the -bundle doesn't pin yet, and which has no certification pull request for it, -it runs `certify-build` on the builds the bundle pins with that version. A -pass opens a draft pull request from branch -`certify//-`; a failure opens or comments on -the country's "Model compatibility check failed" issue. Every run uploads a -`compatibility-` result file. A person reviews and merges the pull -request; earlier ones stay open. The +bundle doesn't pin yet, and whose certification branch doesn't exist yet, it +runs `certify-build --in-place` on the builds the bundle pins with that +version. A pass opens a draft pull request from branch +`certify///-`; a failure +opens or comments on the country's "Model compatibility check failed" issue. +Each run uploads a `compatibility-` result file per country it +checks. A person reviews and merges the pull request; earlier ones stay open. +The [runbook](../runbooks/microcosm-certification.md#the-scheduled-workflow) has the details. diff --git a/docs/release-bundles.md b/docs/release-bundles.md index 501ce1bf5..4718869a7 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -669,7 +669,7 @@ The same for the US and the UK: `M` on the national and local-area builds the bundle pins: the compatibility check on each build, then certification on its record. 3. A pass opens a draft pull request from branch - `certify//-M`; a failure opens or comments on the + `certify///-M`; a failure opens or comments on the country's "Model compatibility check failed" issue, and no data rebuild starts. 4. A person reviews and merges the pull request, and the next From c8407cb5a6a3ac3d8ac24d72af8a895b65ea86cc Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:15:48 +0400 Subject: [PATCH 3/5] Fix review round 1 findings in the certification docs - certify-build checks only builds not made with the model version. - A certificate on a compatibility record always binds its core, and the record replaces the release's core claims. - The scheduled workflow skips a version once any pull request came from its branch; a manual run may cover both countries. - Leave uk-qualification.md to the workflow change that removes it, so this branch's tests keep passing on their own. - Note certify-build's full-commit and --in-place restrictions, and correct the regional_release_kind paragraph. Co-Authored-By: Claude Opus 5.5 --- docs/bundles.md | 3 +- .../runbooks/microcosm-certification.md | 27 ++-- docs/engineering/runbooks/uk-qualification.md | 144 ++++++++++++++++++ docs/engineering/skills/data-certification.md | 29 ++-- docs/release-bundles.md | 21 +-- 5 files changed, 195 insertions(+), 29 deletions(-) create mode 100644 docs/engineering/runbooks/uk-qualification.md diff --git a/docs/bundles.md b/docs/bundles.md index 0954a4602..8bf99adf9 100644 --- a/docs/bundles.md +++ b/docs/bundles.md @@ -209,7 +209,8 @@ python scripts/bundle.py certify-build \ --model-version ``` -It runs the compatibility check on each build, then `certify-data` with each +It runs the compatibility check on each build not made with that model +version, then `certify-data` with each build's own folder, `releases///release_manifest.json`, at the commit that published it; tagged addresses are refused. See the [Microcosm certification runbook](engineering/runbooks/microcosm-certification.md) diff --git a/docs/engineering/runbooks/microcosm-certification.md b/docs/engineering/runbooks/microcosm-certification.md index f8b3ec3d9..c5d6fa0bf 100644 --- a/docs/engineering/runbooks/microcosm-certification.md +++ b/docs/engineering/runbooks/microcosm-certification.md @@ -105,15 +105,15 @@ them. Never run the full test suite locally for a certification. | `--country us\|uk` | The country (required). | | `--national-build BUILD` | The national build to certify (required). | | `--national-release RELEASE` | The national build's release (default: the bundle's). | -| `--national-data-commit COMMIT` | Read the national build at this commit on `main` instead of the last commit of its manifest. | +| `--national-data-commit COMMIT` | Read the national build at this commit on `main` (a full 40-character commit) instead of the last commit of its manifest. | | `--local-area-build BUILD` | Route state, district, constituency and local-authority regions to this local-area build. | | `--keep-regional-release` | Keep the local-area build the bundle routes to now. | | `--drop-regional-release` | Route no regions to a local-area build. | | `--local-area-release RELEASE` | The local-area build's release (default: the bundle's). | -| `--local-area-data-commit COMMIT` | With `--local-area-build`: read it at this commit on `main`. | +| `--local-area-data-commit COMMIT` | With `--local-area-build`: read it at this commit on `main` (a full 40-character commit). | | `--model-version VERSION` | The model version to certify for (default: the national build's own). | -| `--core-version VERSION` | Bind the certificate to this policyengine-core and move the bundle's core pin to it (default: the bundle's pin, unbound). | -| `--in-place` | Change this checkout's files; make no worktree, branch or commit. | +| `--core-version VERSION` | Run the check with this policyengine-core, bind the certificate to it and move the bundle's core pin to it (default: the bundle's pin; see the note below). | +| `--in-place` | Change this checkout's files, which must have no changes to tracked files; make no worktree, branch or commit, and skip the check for another pull request or branch certifying the same build and model. Not with `--worktree`, `--push`, `--co-author` or a `--base-ref` other than `origin/main`. | | `--worktree PATH` | The new worktree (default: beside this checkout). | | `--base-ref REF` | The commit the branch starts from (default: `origin/main`). | | `--output-dir PATH` | Where the command log and the pull request body go. | @@ -126,6 +126,13 @@ them. Never run the full test suite locally for a certification. Pass exactly one of `--local-area-build`, `--keep-regional-release` and `--drop-regional-release`. +A certificate made on a compatibility record always names the core the check +ran with (`core_binding: certified`), even without `--core-version`. So +after the bundle's core pin moves, `bundle.py check --strict-tros` refuses +that certificate until the build is certified again with the new core. Only a +build certified for its own model, without `--core-version`, follows the pin +(`core_binding: bundle_pin`). + ## Step 3: review the pull request The expected diff is: @@ -153,15 +160,17 @@ Follow [github-prs](../skills/github-prs.md) for the tracking issue and the `.github/workflows/check-model-compatibility.yaml` runs at 06:17 UTC on Tuesdays and Fridays, and by hand (`workflow_dispatch`, with `country` set to -`both`, `us` or `uk`, and an optional `model_version` that needs one +`both`, `us` or `uk`, and an optional `model_version`, which needs a single country). - A planning job picks, for each country, the newest `policyengine-us` or `policyengine-uk` release on PyPI (or the version given by hand). It leaves - a country out when the bundle already pins that version, or when the - version's branch already exists, with or without a pull request (open or - closed). A branch pushed without a pull request holds that version back - until someone opens the pull request or deletes the branch. + a country out when the bundle already pins that version, when any pull + request (open or closed) has come from the version's branch, or when the + branch exists without one. So a version whose pull request was closed is + not checked again, even after its branch is deleted; a branch pushed + without a pull request holds the version back until someone opens the pull + request or deletes the branch. - For each remaining country, a job runs `scripts/bundle.py certify-build --in-place` on the national and local-area builds the bundle pins, with that model version. The checkout holds no GitHub token while the check diff --git a/docs/engineering/runbooks/uk-qualification.md b/docs/engineering/runbooks/uk-qualification.md new file mode 100644 index 000000000..a1cad6e2e --- /dev/null +++ b/docs/engineering/runbooks/uk-qualification.md @@ -0,0 +1,144 @@ +# UK candidate qualification: what the ledger shows, and reproducing a gate + +UK candidate qualification starts via `workflow_dispatch` and resolves legacy +uk-data pairs. Scheduled recovery and requalification are disabled. + +The workflow qualifies candidate policyengine-uk and uk-data pairs before +promotion (`scripts/check_uk_candidate.py`, `policyengine.provenance.uk_candidate`). +It writes each attempt's gate results and evidence to the public +`uk-qualification-ledger` branch and withholds any survey data that could +identify a record. + +## What the ledger withholds + +- **Reform contract, population checks.** These run on the survey data. Each + row's check, route, status and the runner's fixed fields + (`POPULATION_ROW_FIELDS`) are published; from its `detail`, only top-level + `True`/`False`/`None` findings are kept, and every count, total, amount, + text, list or nested mapping reads `"withheld"`. The digest the gate + records is of that published copy, never of the full report. +- **Metrics review and responsiveness.** The aggregate-impact tool publishes + a figure from fewer than 10 records as suppressed, and the gate records no + value from a report that breaks that format; such a report is published + only as its digest and problems. + +## Reproducing a failed population check + +The withheld figures exist only in the runner's report, which is not saved. +To see them, rerun the contract on a machine with access to the private UK +dataset, and keep the output local: it holds figures from the survey data, +some from fewer than 10 records, so never commit, paste or publish it. + +1. Check out the candidate commit the attempt ran on (`git_commit` in the + attempt's `harness.json` in the ledger): its bundle manifest names the + dataset `materialize_dataset` fetches, so an older checkout would fetch + older data even with the candidate's wheels installed. +2. Install the candidate pair (the attempt's `candidate.json` names the + wheels) and export `HUGGING_FACE_TOKEN` for the private dataset. +3. Materialize the certified dataset, check its SHA-256 against + `data.dataset_sha256` in the pair's `pair.json`, and run the contract + with the seed and sample size in + `src/policyengine/data/qualification/uk.json`: + + ```python + import hashlib + import json + from pathlib import Path + + from policyengine.provenance.dataset_materialization import materialize_dataset + from policyengine.tax_benefit_models.uk.budget_reform_contract import ( + run_budget_reform_contract, + ) + + dataset = materialize_dataset("uk", data_dir=Path("data")).path + pair = json.loads(Path("path/to/ledger/uk//pair.json").read_text()) + digest = hashlib.sha256(Path(dataset).read_bytes()).hexdigest() + assert digest == pair["data"]["dataset_sha256"], "not the certified dataset" + report = run_budget_reform_contract( + routes=None, dataset_path=str(dataset), seed=0, max_examples=20 + ) + failing = [row for row in report["population"] if row["status"] != "pass"] + ``` + +4. Read `failing[...]["detail"]` locally. Report only the finding (which + condition failed, on which route), never the figures. + +## A candidate stranded before automatic promotion + +Automatic promotion moves main to a qualified candidate only once the newest +run of each workflow and event on the candidate branch, from this repository, +has passed, including a `pr_code_changes.yaml` run dispatched on the branch +itself. The candidate-tree code-check dispatch remains reachable. Replay and +acceptance still refresh candidate PR checks. The schedule-only recovery job +and its two self-dispatches are unreachable. Runs of pull requests from other +branches or forks at the same commit do not count. The `refresh-pr-checks` +step re-runs a failed, timed-out or cancelled run until it has had four +attempts, within GitHub's 30 days of its first attempt. + +When the candidate waits on a run that refresh will not re-run, the promote +job fails with `::error:: waits on runs refresh will not re-run`, +naming each run, its result and its attempts. That covers a run at four +attempts, one older than 30 days, and one whose result refresh never re-runs +(`action_required`, `skipped`, `stale`, `startup_failure` and the like). The +job fails on each run until one of these clears it: + +- Fix the cause, then re-run the named run by hand + (`gh run rerun --repo PolicyEngine/policyengine.py`); a passing + newest attempt clears it. GitHub refuses this for a run whose first + attempt is more than 30 days old. +- For the run on the candidate's own tree, dispatch a new one: + `gh workflow run pr_code_changes.yaml --repo PolicyEngine/policyengine.py --ref `. +- Requalify the pair: run `certify-uk-release` with its versions, `pair_id` + and `force` set. + +### Another pull request from the candidate branch + +Any other pull request from a candidate branch runs the same workflows with +the same commit and branch as the candidate's own pull request, and +GitHub's run records say neither which pull request a run is for nor which +base it tested; a pull request's current base does not settle it, since a +base renamed into main records no event. So while another pull request from +the branch is open, or after one was closed or merged at the candidate's +commit (whatever its base), or when the candidate's own pull request's base +was ever changed, the promote job fails with +`::error:: is not promoted: runs at its commit may have tested another base`, +naming the pull requests, and refresh re-runs none of the candidate's runs. +Close those pull requests, then requalify the pair as above: the new +candidate commit leaves their runs behind, and prepare opens a new pull +request to main if none is open. + +### What promotion trusts + +Promotion guards against mistakes by people who can write to this +repository and against anything people who cannot can do (forks' pull +requests, whatever their branch names, and other pull requests opened from +a candidate branch, which make promotion refuse; one to main that prepare's +lookup adopts is the candidate's own, and promotion refuses it if its base +was ever changed). Whatever else happens, main only +ever becomes the exact qualified commit, built on main as it is at the push, +after the dispatched `pr_code_changes.yaml` run on that commit's own tree +passed. It does not try to resist deliberate disguise by people who can +write here, such as renaming another branch into main to make a run against +another base look like the candidate's: main is not protected, so they +could push it directly. Treat any such change as an incident, not as +something the gate will catch. + +## A pair from another data line + +Promotion compares only pairs on main's data line (its UK certificate's data +package and repository). While Microcosm UK is the default, the +policyengine-uk-data candidates the workflow resolves are `other_line`. An +unforced run of one stops there and writes nothing to the ledger. Recovery and +check refreshes skip such pairs, and promotion closes their open pull requests; +the ledger keeps their evidence. + +`force` still qualifies such a pair, for evidence only. Its candidate commit +drops main's area routing (`--drop-regional-release`), because the routing +belongs to the line the pair would replace, and leaves the test constants that +pin main's certificate as they are, so the candidate's own tests fail. Its pull +request says it is never promoted, and promotion closes it once its receipt is +published, at the commit that receipt qualified. Re-run the workflow by hand +with `force` to recover an attempt. If an attempt dies before publishing a +receipt, close its open pull request by hand. Changing the data line +is a reviewed certification pull request (see +`docs/engineering/skills/data-certification.md`), not a promotion. diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index e09a8e2b4..ecc34e714 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -28,7 +28,7 @@ python scripts/bundle.py certify-build --country \ --push --open-pr ``` -It checks each build against the model version, certifies the national build +It checks each build not made with the model version against it, certifies the national build with its regional route, regenerates everything derived from the bundle, and opens a draft pull request. The model version defaults to the national build's own; `--model-version` certifies the builds for another. The @@ -120,6 +120,9 @@ pinned model version. Certification refuses a build that has none of them: build, model, wheel or core, and a record given with `--qualified-pair-id`. Commit the records file with the bundle. `certify-build` uses this basis whenever the model is not the build's own. + Such a certificate always binds its core (`core_binding: certified`), and + the record's core takes the place of the release's core claims: the core + claim check below doesn't apply to it. - **`legacy_compatible_model_package`.** The publisher's `compatible_model_packages` claim covers the model version. It is recorded with a warning; the claim is made good only by this repository's test suite @@ -176,10 +179,12 @@ result. A failure exits 1 and says why. ### The scheduled workflow `.github/workflows/check-model-compatibility.yaml` runs at 06:17 UTC on -Tuesdays and Fridays, and by hand for one country and a named version. For +Tuesdays and Fridays, and by hand for one or both countries, with an +optional model version for a single country. For each country whose newest `policyengine-us` or `policyengine-uk` release the -bundle doesn't pin yet, and whose certification branch doesn't exist yet, it -runs `certify-build --in-place` on the builds the bundle pins with that +bundle doesn't pin yet, and whose certification branch has never had a pull +request and doesn't exist, it runs `certify-build --in-place` on the builds +the bundle pins with that version. A pass opens a draft pull request from branch `certify///-`; a failure opens or comments on the country's "Model compatibility check failed" issue. @@ -211,7 +216,8 @@ local-area dataset. Certify a national build with one of these routes Certification checks that the local-area build serves the pinned model, by its own build model, a compatibility record or its compatibility claims; -checks its core claims as for the national build (below); and HEAD-checks +checks its core claims as for the national build (below), unless a +compatibility record names the core it ran with instead; and HEAD-checks every artifact it carries. Certification writes each dataset's path in its build folder, for example @@ -379,10 +385,15 @@ country. A certificate says how it covers it: pin that differs from the named core, so moving the core needs a re-certification first. `certify-build --core-version` also moves the bundle's core pin to it. - -A compatibility record names the core it ran with, and a model accepts a -certificate on that record only with that core. Use the default unless a -release must not run on any other core. +- **A certificate on a compatibility record** always has `core_binding: + certified`, naming the core the check ran with (the bundle's pin, unless + `--core-version` named another), even without `--core-version`. The record + takes the place of the release's core claims, and a model accepts the + certificate only with that core. So every certification the + [scheduled workflow](#the-scheduled-workflow) makes for a model other than + the build's own must be made again before the core pin moves. + +Use the default unless a release must not run on any other core. ### Re-certifying a routed bundle diff --git a/docs/release-bundles.md b/docs/release-bundles.md index 4718869a7..351e57346 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -204,7 +204,8 @@ python scripts/bundle.py certify-build --country us \ --model-version "" ``` -It runs the [compatibility check](#compatibility-rule) on each build, then +It runs the [compatibility check](#compatibility-rule) on each build not made +with that model version, then `certify-data` with each build's own folder at the commit that published it: ```bash @@ -261,13 +262,11 @@ installation downloads only that national default; a regional runtime is responsible for materializing the additional certified dataset. `data_releases.{country}.regional_release_kind` records how certification -routed those region types: `local_area` for a non-default local-area release, -and `area_coded_national` (UK only) for another release's national dataset -whose households carry area codes, certified together with that release's -area weight matrices at their own repo and revision. It is absent when nothing -is routed, for a legacy US per-state release, and in an entry certified before -the field existed (as the US ACS-local routing is until its next -certification). +routed those region types: `local_area` for a Microcosm local-area build, as +both countries' bundle entries record now. It is absent when nothing is +routed, for a legacy US per-state release, and in an entry certified before +the field existed. Earlier UK certifications also used `area_coded_national` +(see the data certification skill's "Earlier certifications"). Cross-package overlays must declare `data_package_name` and `repo_type` explicitly. Ordinary artifacts inherit these values from the country release's @@ -370,7 +369,8 @@ Abridged example (`data_releases.uk` in `src/policyengine/data/bundle/manifest.j "compatibility_basis": "compatibility_checked_exact_pair", "built_with_model_version": "", "certified_for_model_version": "", - "core_binding": "bundle_pin", + "core_binding": "certified", + "certified_for_core_version": "", "data_build_id": "", "certified_by": "policyengine.py bundle certification" }, @@ -667,7 +667,8 @@ The same for the US and the UK: 2. At 06:17 UTC on the next Tuesday or Friday, `.github/workflows/check-model-compatibility.yaml` runs `certify-build` for `M` on the national and local-area builds the bundle pins: the - compatibility check on each build, then certification on its record. + compatibility check on each build not made with `M`, then certification + on its record. 3. A pass opens a draft pull request from branch `certify///-M`; a failure opens or comments on the country's "Model compatibility check failed" issue, and no data rebuild From 2300587104299c745427968c687c936d6e6c049d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:21:48 +0400 Subject: [PATCH 4/5] Fix review round 2 findings in the certification docs - A compatibility record for either build binds the certificate's core, and the other build's core claims then refuse instead of warning. - bundles.md names records as a way a certificate binds its core. - The scheduled workflow checks only the newest version on PyPI. - Remove the last fingerprint-plan passages, and describe the disk check and --output-dir as the code has them. Co-Authored-By: Claude Opus 5.5 --- docs/bundles.md | 7 +++--- .../runbooks/microcosm-certification.md | 23 +++++++++++-------- docs/engineering/skills/data-certification.md | 9 ++++++-- docs/release-bundles.md | 7 +++--- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/docs/bundles.md b/docs/bundles.md index 8bf99adf9..169164cb0 100644 --- a/docs/bundles.md +++ b/docs/bundles.md @@ -192,9 +192,10 @@ python scripts/bundle.py update-packages \ By default a data certificate follows the core pin (`core_binding: bundle_pin`), so `--core` can move it; `bundle.py check --include-tros --strict-tros` then warns when a data release does not claim the new core. A -certificate that binds its core (`certify-data --core-version`, -`core_binding: certified`) instead fails that check until the country is -re-certified for the new core. See "The core" in the data certification +certificate that binds its core (`core_binding: certified`: made with +`--core-version`, or on a compatibility record, as every certification the +scheduled compatibility workflow makes for a newer model is) instead fails +that check until the country is re-certified for the new core. See "The core" in the data certification skill. To certify a US or UK Microcosm build, name it by build (the release defaults diff --git a/docs/engineering/runbooks/microcosm-certification.md b/docs/engineering/runbooks/microcosm-certification.md index c5d6fa0bf..13c3ee514 100644 --- a/docs/engineering/runbooks/microcosm-certification.md +++ b/docs/engineering/runbooks/microcosm-certification.md @@ -28,9 +28,10 @@ skill first for what certification checks and records. - For the UK, whose builds are private, `HUGGING_FACE_TOKEN` (or `HF_TOKEN`) exported with read access to `policyengine/populace-uk-private`. The US repository, `policyengine/populace-us`, is public. -- Free disk for both builds' files. The command checks the space before it - downloads anything, sized from the builds' manifests (about 10 GB for the - US local-area file). +- Free disk for both builds' files. Before it downloads anything, the + command checks for the size of both build folders, as Hugging Face lists + their files, plus a 5 GB margin (the US local-area file alone is about + 10 GB). ## Step 1: name the builds @@ -116,7 +117,7 @@ them. Never run the full test suite locally for a certification. | `--in-place` | Change this checkout's files, which must have no changes to tracked files; make no worktree, branch or commit, and skip the check for another pull request or branch certifying the same build and model. Not with `--worktree`, `--push`, `--co-author` or a `--base-ref` other than `origin/main`. | | `--worktree PATH` | The new worktree (default: beside this checkout). | | `--base-ref REF` | The commit the branch starts from (default: `origin/main`). | -| `--output-dir PATH` | Where the command log and the pull request body go. | +| `--output-dir PATH` | Where the command log, the pull request body and the compatibility check's downloads go (and, with `--in-place`, the list of changed files). | | `--skip-writer-check WHY` | Skip the check for another pull request or branch certifying the same build and model. | | `--push` / `--open-pr` | Push the branch; open a draft pull request (needs `--push`). | | `--dry-run` | Print the plan only. | @@ -126,12 +127,14 @@ them. Never run the full test suite locally for a certification. Pass exactly one of `--local-area-build`, `--keep-regional-release` and `--drop-regional-release`. -A certificate made on a compatibility record always names the core the check -ran with (`core_binding: certified`), even without `--core-version`. So -after the bundle's core pin moves, `bundle.py check --strict-tros` refuses -that certificate until the build is certified again with the new core. Only a -build certified for its own model, without `--core-version`, follows the pin -(`core_binding: bundle_pin`). +When either build is certified on a compatibility record, the certificate +names the core the check ran with (`core_binding: certified`), even without +`--core-version`. The other build's core claims are then checked against +that core, and a core it neither was built with nor claims refuses instead +of warning. After the bundle's core pin moves, `bundle.py check --strict-tros` +refuses such a certificate until the build is certified again with the new +core. Only a certification with no compatibility record for either build and +no `--core-version` follows the pin (`core_binding: bundle_pin`). ## Step 3: review the pull request diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index ecc34e714..8d0f796b9 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -371,7 +371,8 @@ After the receipt schema changes, refresh the Budget dashboard's vendored The bundle has one core pin, `packages.policyengine-core`, shared by every country. A certificate says how it covers it: -- **`core_binding: bundle_pin` (the default, no `--core-version`).** The +- **`core_binding: bundle_pin` (the default: no `--core-version` and no + compatibility record for either build).** The certificate names no core and certifies whatever core the bundle pins, so the pin can move with another country without re-certifying this one. Certification checks the pin against each release's build-time core and @@ -387,7 +388,11 @@ country. A certificate says how it covers it: bundle's core pin to it. - **A certificate on a compatibility record** always has `core_binding: certified`, naming the core the check ran with (the bundle's pin, unless - `--core-version` named another), even without `--core-version`. The record + `--core-version` named another), even without `--core-version`. This holds + when either build has a record: the other build's core claims are then + checked against that core and refuse instead of warning, for example a new + national build certified for its own model with `--keep-regional-release` + while the local-area build is on a record. The record takes the place of the release's core claims, and a model accepts the certificate only with that core. So every certification the [scheduled workflow](#the-scheduled-workflow) makes for a model other than diff --git a/docs/release-bundles.md b/docs/release-bundles.md index 351e57346..911d83902 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -160,7 +160,6 @@ The country model package owns: - policy logic - variables and parameters - reforms -- a `data_build_fingerprint` for the subset of model logic that affects data construction It does not own final runtime bundle certification. @@ -583,7 +582,7 @@ TRACE is not the source of truth for compatibility policy. In particular, TRACE does not decide: - whether a new model version can safely reuse an existing data artifact -- how `data_build_fingerprint` is computed +- how the compatibility check decides that a build serves a model version - which staged artifact becomes a supported runtime default Those decisions still belong to the country data build manifest and the @@ -664,7 +663,9 @@ The same for the US and the UK: ### A new model release 1. The country model package publishes version `M` to PyPI. -2. At 06:17 UTC on the next Tuesday or Friday, +2. At 06:17 UTC on the next Tuesday or Friday, if `M` is still the newest + version on PyPI (a version released and then superseded before the run is + not checked automatically; run the workflow by hand for it), `.github/workflows/check-model-compatibility.yaml` runs `certify-build` for `M` on the national and local-area builds the bundle pins: the compatibility check on each build not made with `M`, then certification From 01d51c9520ae251645ed5db9708551b6acf1c1ca Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:29:07 +0400 Subject: [PATCH 5/5] Fix review round 3 findings in the certification docs Certifying moves the bundle's model pin to the certified version, and certify-build defaults to the national build's own model, so the docs now say to pass the bundle's current pin as --model-version when it is newer. Also describe --local-area-release's dependency on --local-area-build and everything --output-dir holds. Co-Authored-By: Claude Opus 5.5 --- .../runbooks/acs-local-wic-replacement.md | 3 ++- .../runbooks/microcosm-certification.md | 21 +++++++++++++------ docs/engineering/skills/data-certification.md | 4 +++- docs/release-bundles.md | 3 ++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/engineering/runbooks/acs-local-wic-replacement.md b/docs/engineering/runbooks/acs-local-wic-replacement.md index d88917645..35189af92 100644 --- a/docs/engineering/runbooks/acs-local-wic-replacement.md +++ b/docs/engineering/runbooks/acs-local-wic-replacement.md @@ -42,7 +42,8 @@ Once the replacement is available: 1. Follow the [Microcosm certification runbook](microcosm-certification.md) with its actual immutable regional manifest. Keep national defaults and - model pins unchanged unless separately approved. + model pins unchanged unless separately approved: pass the bundle's current + model pin as `--model-version`. 2. Verify complete current-name participation on the replacement and record its revision and hashes. 3. Add the real certification changes to the removal PR and rebase it onto diff --git a/docs/engineering/runbooks/microcosm-certification.md b/docs/engineering/runbooks/microcosm-certification.md index 13c3ee514..3973a0a2d 100644 --- a/docs/engineering/runbooks/microcosm-certification.md +++ b/docs/engineering/runbooks/microcosm-certification.md @@ -45,9 +45,18 @@ Microcosm publishes each build in its own folder, | UK | `policyengine/populace-uk-private` | `microcosm-uk-2024-25-national` | `microcosm-uk-2024-25-dense` | A build must be listed and must not be withdrawn. Which build is `current` -doesn't matter: a certificate pins one build. Take the model version from the -national build's `release_manifest.json` (`built_with_model_package`) unless -you are certifying it for another version. +doesn't matter: a certificate pins one build. + +Then choose the model version. `certify-build` defaults to the version the +national build was made with (`built_with_model_package` in its +`release_manifest.json`), and certification moves the bundle's model pin to +whatever version it certifies. Check the pin first +(`packages.policyengine-us` or `packages.policyengine-uk` in +`src/policyengine/data/bundle/manifest.json`): when the bundle already pins a +newer model, for example after a scheduled certification, pass +`--model-version` with that pin, or the certification moves the pin and the +lock back to the older model. This matters most when you replace only the +local-area build. ## Step 2: run the certification @@ -110,14 +119,14 @@ them. Never run the full test suite locally for a certification. | `--local-area-build BUILD` | Route state, district, constituency and local-authority regions to this local-area build. | | `--keep-regional-release` | Keep the local-area build the bundle routes to now. | | `--drop-regional-release` | Route no regions to a local-area build. | -| `--local-area-release RELEASE` | The local-area build's release (default: the bundle's). | +| `--local-area-release RELEASE` | With `--local-area-build`: the build's release (default: the bundle's). | | `--local-area-data-commit COMMIT` | With `--local-area-build`: read it at this commit on `main` (a full 40-character commit). | -| `--model-version VERSION` | The model version to certify for (default: the national build's own). | +| `--model-version VERSION` | The model version to certify for (default: the national build's own; pass the bundle's pin to keep a newer pin, see Step 1). | | `--core-version VERSION` | Run the check with this policyengine-core, bind the certificate to it and move the bundle's core pin to it (default: the bundle's pin; see the note below). | | `--in-place` | Change this checkout's files, which must have no changes to tracked files; make no worktree, branch or commit, and skip the check for another pull request or branch certifying the same build and model. Not with `--worktree`, `--push`, `--co-author` or a `--base-ref` other than `origin/main`. | | `--worktree PATH` | The new worktree (default: beside this checkout). | | `--base-ref REF` | The commit the branch starts from (default: `origin/main`). | -| `--output-dir PATH` | Where the command log, the pull request body and the compatibility check's downloads go (and, with `--in-place`, the list of changed files). | +| `--output-dir PATH` | Where the command log, the pull request body, the compatibility check's downloads, the UK Universal Credit floor receipt and, with `--in-place`, the list of changed files go (default: the folder that holds the worktree or checkout). | | `--skip-writer-check WHY` | Skip the check for another pull request or branch certifying the same build and model. | | `--push` / `--open-pr` | Push the branch; open a draft pull request (needs `--push`). | | `--dry-run` | Print the plan only. | diff --git a/docs/engineering/skills/data-certification.md b/docs/engineering/skills/data-certification.md index 8d0f796b9..3dee31446 100644 --- a/docs/engineering/skills/data-certification.md +++ b/docs/engineering/skills/data-certification.md @@ -31,7 +31,9 @@ python scripts/bundle.py certify-build --country \ It checks each build not made with the model version against it, certifies the national build with its regional route, regenerates everything derived from the bundle, and opens a draft pull request. The model version defaults to the national -build's own; `--model-version` certifies the builds for another. The +build's own; `--model-version` certifies the builds for another. Certifying +moves the bundle's model pin to that version, so when the bundle already pins +a newer model, pass that pin as `--model-version` to keep it. The [Microcosm certification runbook](../runbooks/microcosm-certification.md) gives the steps, every option and what the pull request should change. diff --git a/docs/release-bundles.md b/docs/release-bundles.md index 911d83902..4cde9fa6b 100644 --- a/docs/release-bundles.md +++ b/docs/release-bundles.md @@ -684,7 +684,8 @@ The same for the US and the UK: 1. Microcosm publishes a build in its own folder and lists it in `releases.json`. 2. A person runs `certify-build` with the new national build, the local-area - build and the model version (the build's own by default), following the + build and the model version (the build's own by default; the bundle's + current pin when that is newer, so the pin doesn't move back), following the [Microcosm certification runbook](engineering/runbooks/microcosm-certification.md). 3. Its draft pull request is reviewed and merged, and the next `policyengine.py` release ships a runtime bundle that points to the new