From b1f1ddb0c5809d0afd01f4023f2e0f4d744ba0cf Mon Sep 17 00:00:00 2001 From: Vahid Ahmadi Date: Wed, 27 May 2026 11:26:42 +0200 Subject: [PATCH 1/6] Add mp-30k-uk switch and rollback planning doc (#1692) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1692 asks for a documented model-side path to switch the default dataset from the enhanced FRS to Microplex UK (mp-30k-uk), with an explicit rollback path. Persist that plan in-repo at docs/book/assumptions/mp30k-uk-switch-plan.md. The page covers: - the current state: the dataset URL is resolved at runtime (constructor arg -> POLICYENGINE_UK_DEFAULT_DATASET env var -> ValueError), so the model is already dataset-agnostic and the switch is a configuration concern rather than a code change, - loader-side assumptions to audit before switching (HDF5 layout matching UKMultiYearDataset, advertised years, enum label parity), - variable-side audit needs (input/* columns present in both datasets; reported-vs-derived benefit columns implying take-up recalibration), - calibration-side implications for policyengine-uk-data targets, - five gating criteria (aggregate parity, cross-section parity, reform parity, full test suite, documentation parity), - a rollback path that requires no code change in this repo — just reverting the env var per deploy environment and keeping eFRS published in parallel during beta. --- changelog.d/1692.md | 1 + docs/book/assumptions/mp30k-uk-switch-plan.md | 130 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 changelog.d/1692.md create mode 100644 docs/book/assumptions/mp30k-uk-switch-plan.md diff --git a/changelog.d/1692.md b/changelog.d/1692.md new file mode 100644 index 0000000000..1ae9e9d64f --- /dev/null +++ b/changelog.d/1692.md @@ -0,0 +1 @@ +- Add a planning docs page at `docs/book/assumptions/mp30k-uk-switch-plan.md` capturing the model-side switch and rollback path for moving from the enhanced FRS to Microplex UK (`mp-30k-uk`), with explicit gating criteria (aggregate, cross-section, reform-parity, tests, docs) and a rollback path that keeps eFRS available as an env-var fallback throughout the beta period. diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md new file mode 100644 index 0000000000..aa39b3b862 --- /dev/null +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -0,0 +1,130 @@ +# Microplex UK (mp-30k-uk) switch and rollback plan + +```{note} +**Planning page.** PolicyEngine UK currently runs on the **enhanced FRS** +(eFRS, published as `policyengine/policyengine-uk-data`). +[Microplex UK](https://github.com/PolicyEngine/microplex-uk) (`mp-30k-uk`) +is the next-generation calibrated microdata. This page captures the +model-side switch and rollback path tracked under +[#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692). +``` + +## Current state + +PolicyEngine UK accepts any HDF5 URL as its dataset. The selected +dataset URL is resolved in this order: + +1. An explicit `dataset=` argument passed to `Simulation()` / + `Microsimulation()` (see + [`policyengine_uk/simulation.py`](../../../policyengine_uk/simulation.py)). +2. The `POLICYENGINE_UK_DEFAULT_DATASET` environment variable. +3. Otherwise the simulation requires either an inline `situation` or a + `ValueError` is raised. + +There is **no compiled-in default** — the model is dataset-agnostic by +design, and the URL is resolved at runtime. Today's typical +configuration uses +`hf://policyengine/policyengine-uk-data/enhanced_frs_2022_23.h5` (public) +or +`hf://policyengine/policyengine-uk-data-private/enhanced_frs_2023_24.h5` +(private, used in CI). + +## What the switch needs + +Identify eFRS-specific assumptions before switching the runtime default +to mp-30k-uk: + +### Loader-side + +- [`UKMultiYearDataset`](https://github.com/PolicyEngine/policyengine-core/blob/main/policyengine_core/data/dataset.py) + is the multi-year data container used by both eFRS and (planned) + mp-30k-uk. Confirm that mp-30k-uk's HDF5 layout matches the + table/column conventions PolicyEngine UK reads (`_pre_encode_enum_columns` + walks `table_names`). +- The `years` set on the dataset object drives uprating; mp-30k-uk + needs to advertise the same year range eFRS does (or a documented + superset). +- Enum-typed columns must use the same possible-values labels as the + variable definitions in this repo — otherwise the `encode()` step + silently drops rows. + +### Variable-side + +- The variables under + [`policyengine_uk/variables/input/`](../../../policyengine_uk/variables/input) + are the data-side contract. mp-30k-uk should populate all of them, or + the variable formulas should provide sensible defaults when a column + is missing. +- Variables that read from the dataset by name (`person("foo", data_year)`) + break if `foo` is renamed; an audit script that reports `input/` + columns present in eFRS but not in mp-30k-uk (and vice versa) should + be part of the gating tests. +- The reported-vs-derived split for benefits (`_reported` inputs feeding + formulas) means take-up will have to be re-calibrated on mp-30k-uk + rather than carried across from eFRS. + +### Calibration-side + +- `policyengine-uk-data`'s reweighting routines and target sets need to + be either pointed at mp-30k-uk inputs or retained as separate eFRS-only + artefacts. The target set itself (HMRC + DWP outturn) doesn't change; + what changes is the population the weights are reconciling. + +## Switch criteria + +A documented gate must pass before flipping the runtime default. Minimum +checklist: + +1. **Aggregate parity** — `Microsimulation` totals for the headline + tax/benefit variables (income tax, NI, UC, child benefit, state + pension) match between eFRS and mp-30k-uk at within ±£1 bn or 2%, + whichever is wider, against the same OBR outturn target year. +2. **Cross-section parity** — household-level decile-by-decile mean net + income and poverty rates (HBAI + AHC) agree within 2 pp. +3. **Reform parity** — at least three canonical reforms (e.g. abolish + council tax, +1 ppt basic rate, +£5 UC standard allowance) produce + the same sign and within-5% magnitude of household impact on both + datasets. +4. **Tests** — the full test suite in `policyengine_uk/tests/` passes + against an mp-30k-uk default. Specifically, `test_no_economic_assumptions.py`, + `test_deterministic_variables.py`, and + `test_latest_data_smoke.py` need updating to dual-run. +5. **Documentation** — the `assumptions/` section calls out the switch + and the residual aggregate gaps (if any) with the same level of + detail the State Pension undershoot doc carries. + +## Rollback path + +Until the criteria above are met (and even after), keep eFRS as an +explicit incumbent comparator: + +1. The runtime resolver in `simulation.py` stays URL-agnostic — no + compile-time switch on the dataset identity. +2. Continuous integration runs the full test suite **on both datasets** + while mp-30k-uk is on beta; gating any merge on parity tests + completing on both. +3. The default URL captured in + `POLICYENGINE_UK_DEFAULT_DATASET` becomes a deploy-time decision + per environment (staging vs production), with eFRS as the fallback + in every environment. +4. If a production-side mp-30k-uk regression is identified, the rollback + is reverting that one env var and re-deploying — no code change in + this repo. The infrastructure assumption is that + `policyengine-uk-data` keeps publishing eFRS artefacts in parallel + throughout the beta period. + +## Acceptance + +> PolicyEngine UK can switch to mp-30k-uk only after the gates above pass, +> with a tested rollback path that requires no code change in this repo. + +Until then both datasets remain first-class — choose either by passing +`dataset=...` or setting the env var. + +## References + +- Umbrella discussion: [`PolicyEngine/microplex-uk` discussion #2](https://github.com/PolicyEngine/microplex-uk/discussions/2). +- Tracking issue: [#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692). +- Related: [#1621](https://github.com/PolicyEngine/policyengine-uk/issues/1621) (UK pipeline alignment audit). +- Dataset loader: [`policyengine_uk/simulation.py`](../../../policyengine_uk/simulation.py). +- Default-dataset env var: `POLICYENGINE_UK_DEFAULT_DATASET` (defined in `tax_benefit_system.py`). From 64a65376972256302d4365b36cc8464b5e542ce3 Mon Sep 17 00:00:00 2001 From: vahid-ahmadi Date: Thu, 8 Oct 2026 15:54:30 +0100 Subject: [PATCH 2/6] Refresh the planning page against the current code and type its changelog fragment Checked every variable, parameter, path and link against main in October 2026, updated the data pipeline references to Microcosm UK, and renamed the changelog fragment to a Towncrier type. Co-Authored-By: Claude Opus 5.5 --- changelog.d/1692.added.md | 1 + changelog.d/1692.md | 1 - docs/book/assumptions/mp30k-uk-switch-plan.md | 181 +++++++----------- 3 files changed, 75 insertions(+), 108 deletions(-) create mode 100644 changelog.d/1692.added.md delete mode 100644 changelog.d/1692.md diff --git a/changelog.d/1692.added.md b/changelog.d/1692.added.md new file mode 100644 index 0000000000..a052c8d27d --- /dev/null +++ b/changelog.d/1692.added.md @@ -0,0 +1 @@ +- Add a planning docs page (`docs/book/assumptions/mp30k-uk-switch-plan.md`) setting out the gates and rollback path for changing the default dataset. It was written for Microplex UK and now applies to its successor, Microcosm UK. diff --git a/changelog.d/1692.md b/changelog.d/1692.md deleted file mode 100644 index 1ae9e9d64f..0000000000 --- a/changelog.d/1692.md +++ /dev/null @@ -1 +0,0 @@ -- Add a planning docs page at `docs/book/assumptions/mp30k-uk-switch-plan.md` capturing the model-side switch and rollback path for moving from the enhanced FRS to Microplex UK (`mp-30k-uk`), with explicit gating criteria (aggregate, cross-section, reform-parity, tests, docs) and a rollback path that keeps eFRS available as an env-var fallback throughout the beta period. diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md index aa39b3b862..610ef32156 100644 --- a/docs/book/assumptions/mp30k-uk-switch-plan.md +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -1,130 +1,97 @@ -# Microplex UK (mp-30k-uk) switch and rollback plan +# Switching the default dataset: gates and rollback ```{note} -**Planning page.** PolicyEngine UK currently runs on the **enhanced FRS** -(eFRS, published as `policyengine/policyengine-uk-data`). -[Microplex UK](https://github.com/PolicyEngine/microplex-uk) (`mp-30k-uk`) -is the next-generation calibrated microdata. This page captures the -model-side switch and rollback path tracked under -[#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692). +**Planning page.** [#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692) +asked for a switch and rollback path from the Enhanced FRS (eFRS) to Microplex UK +(`mp-30k-uk`). Microplex UK has since been archived (May 2026), and its successor +is [Microcosm UK](https://github.com/PolicyEngine/microcosm). Its first +certified national release, `microcosm_uk_2024_25.h5`, is dated 4 October 2026. +This page applies the same switch and rollback path to Microcosm UK. ``` ## Current state -PolicyEngine UK accepts any HDF5 URL as its dataset. The selected -dataset URL is resolved in this order: +PolicyEngine UK has no built-in default dataset. `Simulation()` uses, in order: -1. An explicit `dataset=` argument passed to `Simulation()` / - `Microsimulation()` (see - [`policyengine_uk/simulation.py`](../../../policyengine_uk/simulation.py)). -2. The `POLICYENGINE_UK_DEFAULT_DATASET` environment variable. -3. Otherwise the simulation requires either an inline `situation` or a - `ValueError` is raised. +1. an explicit `dataset=` argument; +2. the `POLICYENGINE_UK_DEFAULT_DATASET` environment variable + (`DEFAULT_DATASET_ENV_VAR` in `tax_benefit_system.py`); +3. otherwise, unless an inline `situation` is passed, it raises a `ValueError` + (`get_default_dataset_url` in `simulation.py`). -There is **no compiled-in default** — the model is dataset-agnostic by -design, and the URL is resolved at runtime. Today's typical -configuration uses -`hf://policyengine/policyengine-uk-data/enhanced_frs_2022_23.h5` (public) -or -`hf://policyengine/policyengine-uk-data-private/enhanced_frs_2023_24.h5` -(private, used in CI). +The test suite sets the variable to the private +`hf://policyengine/policyengine-uk-data-private/enhanced_frs_2023_24.h5@1.40.3` +when a Hugging Face token is available (`policyengine_uk/tests/conftest.py`). +So the eFRS is still the dataset the model is tested against, and the +default in downstream tools such as policyengine.py. ## What the switch needs -Identify eFRS-specific assumptions before switching the runtime default -to mp-30k-uk: - -### Loader-side - -- [`UKMultiYearDataset`](https://github.com/PolicyEngine/policyengine-core/blob/main/policyengine_core/data/dataset.py) - is the multi-year data container used by both eFRS and (planned) - mp-30k-uk. Confirm that mp-30k-uk's HDF5 layout matches the - table/column conventions PolicyEngine UK reads (`_pre_encode_enum_columns` - walks `table_names`). -- The `years` set on the dataset object drives uprating; mp-30k-uk - needs to advertise the same year range eFRS does (or a documented - superset). -- Enum-typed columns must use the same possible-values labels as the - variable definitions in this repo — otherwise the `encode()` step - silently drops rows. - -### Variable-side - -- The variables under - [`policyengine_uk/variables/input/`](../../../policyengine_uk/variables/input) - are the data-side contract. mp-30k-uk should populate all of them, or - the variable formulas should provide sensible defaults when a column - is missing. -- Variables that read from the dataset by name (`person("foo", data_year)`) - break if `foo` is renamed; an audit script that reports `input/` - columns present in eFRS but not in mp-30k-uk (and vice versa) should - be part of the gating tests. -- The reported-vs-derived split for benefits (`_reported` inputs feeding - formulas) means take-up will have to be re-calibrated on mp-30k-uk - rather than carried across from eFRS. - -### Calibration-side - -- `policyengine-uk-data`'s reweighting routines and target sets need to - be either pointed at mp-30k-uk inputs or retained as separate eFRS-only - artefacts. The target set itself (HMRC + DWP outturn) doesn't change; - what changes is the population the weights are reconciling. +### Loader + +- `UKMultiYearDataset` and `UKSingleYearDataset` + (`policyengine_uk/data/dataset_schema.py`) are the containers both datasets + load into. A Microcosm file must use the same table and column conventions, + because `_pre_encode_enum_columns` walks each year's tables. +- The dataset's `years` drive uprating. Microcosm's base year is 2024-25, + one year later than the eFRS file used in tests, so uprating paths from the + earlier base year need checking. +- Enum columns must use the labels in this repo's variable definitions. + Unknown labels do not encode correctly. + +### Variables + +- `policyengine_uk/variables/input/` is the data contract. A switch should + report the input columns present in one dataset but not the other, and + decide for each whether a missing column is acceptable. +- Take-up and other reported-versus-simulated inputs have to come from the + new data, not be carried over from the eFRS. + +### Calibration + +- Microcosm calibrates its own weights against its target register, and + certifies each release through its own checks. The model side should + compare results against those targets, not re-weight. ## Switch criteria -A documented gate must pass before flipping the runtime default. Minimum -checklist: - -1. **Aggregate parity** — `Microsimulation` totals for the headline - tax/benefit variables (income tax, NI, UC, child benefit, state - pension) match between eFRS and mp-30k-uk at within ±£1 bn or 2%, - whichever is wider, against the same OBR outturn target year. -2. **Cross-section parity** — household-level decile-by-decile mean net - income and poverty rates (HBAI + AHC) agree within 2 pp. -3. **Reform parity** — at least three canonical reforms (e.g. abolish - council tax, +1 ppt basic rate, +£5 UC standard allowance) produce - the same sign and within-5% magnitude of household impact on both - datasets. -4. **Tests** — the full test suite in `policyengine_uk/tests/` passes - against an mp-30k-uk default. Specifically, `test_no_economic_assumptions.py`, - `test_deterministic_variables.py`, and - `test_latest_data_smoke.py` need updating to dual-run. -5. **Documentation** — the `assumptions/` section calls out the switch - and the residual aggregate gaps (if any) with the same level of - detail the State Pension undershoot doc carries. +A documented gate must pass before any environment's default changes: + +1. **Aggregates:** headline totals (income tax, NICs, UC, Child Benefit, + State Pension) on both datasets for the same year, each set against OBR + outturn, with any difference of more than £1bn or 2% (whichever is wider) + explained. +2. **Distribution:** decile mean net income and HBAI poverty rates (before + and after housing costs) within 2 percentage points, or explained. +3. **Reforms:** at least three standard reforms (for example +1p on the basic + rate, +£5 a week on the UC standard allowance, abolishing the two-child + limit) give the same sign and are within 5% of each other. +4. **Tests:** the suite passes with the new default, including + `test_latest_data_smoke.py`, `test_deterministic_variables.py` and + `test_no_economic_assumptions.py`. +5. **Documentation:** the `assumptions/` section records the switch and any + remaining aggregate gaps. ## Rollback path -Until the criteria above are met (and even after), keep eFRS as an -explicit incumbent comparator: - -1. The runtime resolver in `simulation.py` stays URL-agnostic — no - compile-time switch on the dataset identity. -2. Continuous integration runs the full test suite **on both datasets** - while mp-30k-uk is on beta; gating any merge on parity tests - completing on both. -3. The default URL captured in - `POLICYENGINE_UK_DEFAULT_DATASET` becomes a deploy-time decision - per environment (staging vs production), with eFRS as the fallback - in every environment. -4. If a production-side mp-30k-uk regression is identified, the rollback - is reverting that one env var and re-deploying — no code change in - this repo. The infrastructure assumption is that - `policyengine-uk-data` keeps publishing eFRS artefacts in parallel - throughout the beta period. +1. Dataset choice stays a runtime setting: no code in this repo depends on + which dataset is loaded. +2. While both are in use, CI runs the dataset-dependent tests on both. +3. The default is set per environment through + `POLICYENGINE_UK_DEFAULT_DATASET`, with the eFRS file kept available. +4. Rolling back is changing that variable and redeploying, with no code + change here. This assumes the eFRS file stays published while the switch + beds in. ## Acceptance -> PolicyEngine UK can switch to mp-30k-uk only after the gates above pass, -> with a tested rollback path that requires no code change in this repo. - -Until then both datasets remain first-class — choose either by passing -`dataset=...` or setting the env var. +PolicyEngine UK switches its default only after the gates above pass, with a +rollback that needs no code change in this repo. Until then either dataset can +be used by passing `dataset=` or setting the environment variable. ## References -- Umbrella discussion: [`PolicyEngine/microplex-uk` discussion #2](https://github.com/PolicyEngine/microplex-uk/discussions/2). -- Tracking issue: [#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692). -- Related: [#1621](https://github.com/PolicyEngine/policyengine-uk/issues/1621) (UK pipeline alignment audit). -- Dataset loader: [`policyengine_uk/simulation.py`](../../../policyengine_uk/simulation.py). -- Default-dataset env var: `POLICYENGINE_UK_DEFAULT_DATASET` (defined in `tax_benefit_system.py`). +- Tracking issue: [#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692) (still open). Its umbrella discussion is in the archived [`microplex-uk`](https://github.com/PolicyEngine/microplex-uk/discussions/2) repository. +- Related: [#1621](https://github.com/PolicyEngine/policyengine-uk/issues/1621) (aligning the UK model and data pipeline). +- Microcosm UK: [repository](https://github.com/PolicyEngine/microcosm). +- Dataset loading: `policyengine_uk/simulation.py`, `policyengine_uk/data/dataset_schema.py`. From 118b1c9b229f06af5285c967dce19b2cb7ca47a9 Mon Sep 17 00:00:00 2001 From: vahid-ahmadi Date: Mon, 12 Oct 2026 11:06:37 +0200 Subject: [PATCH 3/6] Correct the dataset switch plan against main and Microcosm Drop the unverified Microcosm UK release date and the Microplex archive month (the repository is archived; the date is not recorded), keep the national file name, which Microcosm's runbook and registry use. Note that Microsimulation() here is deprecated in favour of policyengine.py's managed bundle (README), so the default switch has to happen there too. Say that _pre_encode_enum_columns lives in simulation.py, not dataset_schema.py. Drop the leading bullet from the changelog fragment so towncrier does not render it twice. Co-Authored-By: Claude Opus 5.5 --- changelog.d/1692.added.md | 2 +- docs/book/assumptions/mp30k-uk-switch-plan.md | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/changelog.d/1692.added.md b/changelog.d/1692.added.md index a052c8d27d..1816c55e99 100644 --- a/changelog.d/1692.added.md +++ b/changelog.d/1692.added.md @@ -1 +1 @@ -- Add a planning docs page (`docs/book/assumptions/mp30k-uk-switch-plan.md`) setting out the gates and rollback path for changing the default dataset. It was written for Microplex UK and now applies to its successor, Microcosm UK. +Add a planning docs page (`docs/book/assumptions/mp30k-uk-switch-plan.md`) setting out the gates and rollback path for changing the default dataset. It was written for Microplex UK and now applies to its successor, Microcosm UK. diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md index 610ef32156..39f9d64841 100644 --- a/docs/book/assumptions/mp30k-uk-switch-plan.md +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -3,10 +3,10 @@ ```{note} **Planning page.** [#1692](https://github.com/PolicyEngine/policyengine-uk/issues/1692) asked for a switch and rollback path from the Enhanced FRS (eFRS) to Microplex UK -(`mp-30k-uk`). Microplex UK has since been archived (May 2026), and its successor -is [Microcosm UK](https://github.com/PolicyEngine/microcosm). Its first -certified national release, `microcosm_uk_2024_25.h5`, is dated 4 October 2026. -This page applies the same switch and rollback path to Microcosm UK. +(`mp-30k-uk`). The `microplex-uk` repository has since been archived, and its +successor is [Microcosm UK](https://github.com/PolicyEngine/microcosm), whose +UK national line publishes `microcosm_uk_2024_25.h5`. This page applies the +same switch and rollback path to Microcosm UK. ``` ## Current state @@ -25,6 +25,12 @@ when a Hugging Face token is available (`policyengine_uk/tests/conftest.py`). So the eFRS is still the dataset the model is tested against, and the default in downstream tools such as policyengine.py. +Direct microsimulation through `Microsimulation()` in this package is +deprecated in favour of [policyengine.py](https://github.com/PolicyEngine/policyengine.py), +whose managed bundle pins certified datasets (see the repository README). The +default most users meet is therefore the one that bundle pins, so a switch has +to be made there as well as in this repository's tests. + ## What the switch needs ### Loader @@ -32,7 +38,8 @@ default in downstream tools such as policyengine.py. - `UKMultiYearDataset` and `UKSingleYearDataset` (`policyengine_uk/data/dataset_schema.py`) are the containers both datasets load into. A Microcosm file must use the same table and column conventions, - because `_pre_encode_enum_columns` walks each year's tables. + because `_pre_encode_enum_columns` (in `simulation.py`) walks each year's + tables. - The dataset's `years` drive uprating. Microcosm's base year is 2024-25, one year later than the eFRS file used in tests, so uprating paths from the earlier base year need checking. From 37eeed18495b2c6bcbfb7e814b645e87e89749ea Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 23 Oct 2026 02:05:32 -0400 Subject: [PATCH 4/6] Correct the default-dataset switch plan against main and policyengine.py - An inline situation is used before dataset= and the environment variable (simulation.py:349-362). - Tests now pin enhanced_frs_2024_25.h5 from policyengine-uk-data 1.58.1 by commit and SHA-256 (tests/certified_dataset.yaml), not the 2023-24 1.40.3 file, so both datasets share the 2024-25 base year. - policyengine.py 6.10.0 (21 October 2026) switched its UK default to Microcosm UK 2024-25; only this repository's tests remain on the eFRS. - Enum columns are matched by member name and an unknown name raises a ValueError (core Enum.encode), rather than encoding incorrectly. - The loader sets any dataset column named after a variable, so variables/input/ is not the whole data contract. - Rollback is not code-free: gov.simulation.vat.survey_consumption_coverage is calibrated to Microcosm UK only and must be re-derived. - Replaced the released .added fragment with a .changed fragment. Co-Authored-By: Claude Opus 5.5 --- ...dataset-switch-page-corrections.changed.md | 1 + changelog.d/1692.added.md | 1 - docs/book/assumptions/mp30k-uk-switch-plan.md | 61 ++++++++++++------- 3 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 changelog.d/1692-dataset-switch-page-corrections.changed.md delete mode 100644 changelog.d/1692.added.md diff --git a/changelog.d/1692-dataset-switch-page-corrections.changed.md b/changelog.d/1692-dataset-switch-page-corrections.changed.md new file mode 100644 index 0000000000..7d15d60bc2 --- /dev/null +++ b/changelog.d/1692-dataset-switch-page-corrections.changed.md @@ -0,0 +1 @@ +Corrected the default-dataset switch plan (`docs/book/assumptions/mp30k-uk-switch-plan.md`): the tests now pin Enhanced FRS 2024-25 from policyengine-uk-data 1.58.1, policyengine.py 6.10.0 already switched its UK default to Microcosm UK, an inline situation takes precedence over any dataset, unknown enum names raise an error, and the VAT survey-coverage parameter is calibrated to Microcosm UK and must be re-derived on a switch or rollback. diff --git a/changelog.d/1692.added.md b/changelog.d/1692.added.md deleted file mode 100644 index 1816c55e99..0000000000 --- a/changelog.d/1692.added.md +++ /dev/null @@ -1 +0,0 @@ -Add a planning docs page (`docs/book/assumptions/mp30k-uk-switch-plan.md`) setting out the gates and rollback path for changing the default dataset. It was written for Microplex UK and now applies to its successor, Microcosm UK. diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md index 39f9d64841..1bae7f50ce 100644 --- a/docs/book/assumptions/mp30k-uk-switch-plan.md +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -11,25 +11,31 @@ same switch and rollback path to Microcosm UK. ## Current state -PolicyEngine UK has no built-in default dataset. `Simulation()` uses, in order: +PolicyEngine UK has no built-in default dataset. An inline `situation`, if +passed, is used on its own. Otherwise `Simulation()` uses, in order: 1. an explicit `dataset=` argument; 2. the `POLICYENGINE_UK_DEFAULT_DATASET` environment variable (`DEFAULT_DATASET_ENV_VAR` in `tax_benefit_system.py`); -3. otherwise, unless an inline `situation` is passed, it raises a `ValueError` - (`get_default_dataset_url` in `simulation.py`). +3. otherwise it raises a `ValueError` (`get_default_dataset_url` in + `simulation.py`). -The test suite sets the variable to the private -`hf://policyengine/policyengine-uk-data-private/enhanced_frs_2023_24.h5@1.40.3` -when a Hugging Face token is available (`policyengine_uk/tests/conftest.py`). -So the eFRS is still the dataset the model is tested against, and the -default in downstream tools such as policyengine.py. +When a Hugging Face token is available, the test suite sets the variable to +the certified dataset pinned by commit and SHA-256 in +`policyengine_uk/tests/certified_dataset.yaml` (read by +`policyengine_uk/tests/conftest.py`): `enhanced_frs_2024_25.h5` from +policyengine-uk-data 1.58.1, in the private +`policyengine/policyengine-uk-data-private` repository. So the eFRS is still +the dataset this repository's tests run on. Direct microsimulation through `Microsimulation()` in this package is deprecated in favour of [policyengine.py](https://github.com/PolicyEngine/policyengine.py), whose managed bundle pins certified datasets (see the repository README). The default most users meet is therefore the one that bundle pins, so a switch has -to be made there as well as in this repository's tests. +to be made there as well as in this repository's tests. policyengine.py made +that switch in release 6.10.0 (21 October 2026): its UK default is now +Microcosm UK 2024-25 (`microcosm_uk_2024_25`), and the Enhanced FRS 2024-25 +stays loadable by name. Only this repository's tests remain on the eFRS. ## What the switch needs @@ -41,14 +47,20 @@ to be made there as well as in this repository's tests. because `_pre_encode_enum_columns` (in `simulation.py`) walks each year's tables. - The dataset's `years` drive uprating. Microcosm's base year is 2024-25, - one year later than the eFRS file used in tests, so uprating paths from the - earlier base year need checking. -- Enum columns must use the labels in this repo's variable definitions. - Unknown labels do not encode correctly. + the same as the eFRS file now used in tests (`enhanced_frs_2024_25`). +- String enum columns must use the member names in this repo's variable + definitions (for example `OWNED_OUTRIGHT`, not "Owned outright"). An + unknown name raises a `ValueError` when the dataset is encoded + (policyengine-core's `Enum.encode`); integer-coded columns are not + checked. ### Variables -- `policyengine_uk/variables/input/` is the data contract. A switch should +- `policyengine_uk/variables/input/` holds most of the inputs, but the + loader (`build_from_multi_year_dataset` in `simulation.py`) sets every + dataset column named after any model variable as an input and skips the + rest, and several dataset inputs are defined elsewhere (for example + `tenure_type`, `household_weight` and `would_claim_uc`). A switch should report the input columns present in one dataset but not the other, and decide for each whether a missing column is acceptable. - Take-up and other reported-versus-simulated inputs have to come from the @@ -81,19 +93,26 @@ A documented gate must pass before any environment's default changes: ## Rollback path -1. Dataset choice stays a runtime setting: no code in this repo depends on - which dataset is loaded. +1. Dataset choice stays a runtime setting: no code in this repo branches on + which dataset is loaded. One parameter is tied to the dataset, though: + `gov.simulation.vat.survey_consumption_coverage` is calibrated to the + Microcosm UK 2024-25 release only, puts VAT 38% to 44% above 2024-25 + receipts on the Enhanced FRS 2024-25, and has to be re-derived when the + default dataset changes (`docs/engineering/vat-coverage.md`). 2. While both are in use, CI runs the dataset-dependent tests on both. 3. The default is set per environment through - `POLICYENGINE_UK_DEFAULT_DATASET`, with the eFRS file kept available. -4. Rolling back is changing that variable and redeploying, with no code - change here. This assumes the eFRS file stays published while the switch - beds in. + `POLICYENGINE_UK_DEFAULT_DATASET` (in policyengine.py, through its bundle + manifest), with the eFRS file kept available. +4. Rolling back is changing that setting and redeploying. The only change + needed here is re-deriving dataset-calibrated parameters such as the VAT + coverage above. This assumes the eFRS file stays published while the + switch beds in. ## Acceptance PolicyEngine UK switches its default only after the gates above pass, with a -rollback that needs no code change in this repo. Until then either dataset can +rollback that needs no code change in this repo beyond dataset-calibrated +parameters. Until then either dataset can be used by passing `dataset=` or setting the environment variable. ## References From 9e5d089bf6c8d73ca1249f49a0bd8e5ccd09cfdb Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 23 Oct 2026 03:11:24 -0400 Subject: [PATCH 5/6] Tighten the dataset switch plan after independent review - The tests set the variable only when it is not already set (conftest.py). - policyengine.py switched under its own certification, with a recorded UC caseload-floor exception; the page no longer implies the gates ran, and no longer claims nothing else downstream uses the eFRS. - test_latest_data_smoke.py still loads enhanced_frs_2023_24.h5, and the three named tests do not exercise a new default; criterion 4 now names the certified pin and the reform regression fixtures. - variables/input/ holds many, not most, of the dataset inputs. - The VAT coverage parameter matches one Microcosm cut (20261002), not the cut policyengine.py now pins; 38% and 44% are two uk-data releases. - Rollback: the tests' default is a committed pin, and policyengine.py's default comes from its manifest, not the environment variable. - An hf:// path cannot load Microcosm UK, which sits in a dataset repo while core requests repo_type="model". Co-Authored-By: Claude Opus 5.5 --- docs/book/assumptions/mp30k-uk-switch-plan.md | 70 ++++++++++++------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md index 1bae7f50ce..98c8a20c13 100644 --- a/docs/book/assumptions/mp30k-uk-switch-plan.md +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -20,8 +20,8 @@ passed, is used on its own. Otherwise `Simulation()` uses, in order: 3. otherwise it raises a `ValueError` (`get_default_dataset_url` in `simulation.py`). -When a Hugging Face token is available, the test suite sets the variable to -the certified dataset pinned by commit and SHA-256 in +When a Hugging Face token is available and the variable is not already set, +the test suite sets it to the certified dataset pinned by commit and SHA-256 in `policyengine_uk/tests/certified_dataset.yaml` (read by `policyengine_uk/tests/conftest.py`): `enhanced_frs_2024_25.h5` from policyengine-uk-data 1.58.1, in the private @@ -35,7 +35,10 @@ default most users meet is therefore the one that bundle pins, so a switch has to be made there as well as in this repository's tests. policyengine.py made that switch in release 6.10.0 (21 October 2026): its UK default is now Microcosm UK 2024-25 (`microcosm_uk_2024_25`), and the Enhanced FRS 2024-25 -stays loadable by name. Only this repository's tests remain on the eFRS. +stays loadable by name. It did so under its own bundle certification (its +6.10.0 changelog records an accepted exception to its Universal Credit +caseload floor); this page does not record whether the gates below were run. +This repository's tests remain on the eFRS. ## What the switch needs @@ -47,7 +50,9 @@ stays loadable by name. Only this repository's tests remain on the eFRS. because `_pre_encode_enum_columns` (in `simulation.py`) walks each year's tables. - The dataset's `years` drive uprating. Microcosm's base year is 2024-25, - the same as the eFRS file now used in tests (`enhanced_frs_2024_25`). + the same as the pinned eFRS file the tests use (`enhanced_frs_2024_25.h5`); + `test_latest_data_smoke.py` still loads the unpinned + `enhanced_frs_2023_24.h5`. - String enum columns must use the member names in this repo's variable definitions (for example `OWNED_OUTRIGHT`, not "Owned outright"). An unknown name raises a `ValueError` when the dataset is encoded @@ -56,11 +61,12 @@ stays loadable by name. Only this repository's tests remain on the eFRS. ### Variables -- `policyengine_uk/variables/input/` holds most of the inputs, but the +- `policyengine_uk/variables/input/` holds many of the inputs, but the loader (`build_from_multi_year_dataset` in `simulation.py`) sets every dataset column named after any model variable as an input and skips the - rest, and several dataset inputs are defined elsewhere (for example - `tenure_type`, `household_weight` and `would_claim_uc`). A switch should + rest, and many dataset inputs are defined elsewhere (for example + `tenure_type`, `household_weight`, `would_claim_uc` and the `*_reported` + benefit amounts). A switch should report the input columns present in one dataset but not the other, and decide for each whether a missing column is acceptable. - Take-up and other reported-versus-simulated inputs have to come from the @@ -85,9 +91,13 @@ A documented gate must pass before any environment's default changes: 3. **Reforms:** at least three standard reforms (for example +1p on the basic rate, +£5 a week on the UC standard allowance, abolishing the two-child limit) give the same sign and are within 5% of each other. -4. **Tests:** the suite passes with the new default, including - `test_latest_data_smoke.py`, `test_deterministic_variables.py` and - `test_no_economic_assumptions.py`. +4. **Tests:** the suite passes with the new dataset pinned in + `policyengine_uk/tests/certified_dataset.yaml`, with the reform + regression fixtures in `policyengine_uk/tests/microsimulation/reforms_config.yaml` + moved to the same dataset. `test_latest_data_smoke.py` loads a fixed + `enhanced_frs_2023_24.h5`, and `test_deterministic_variables.py` and + `test_no_economic_assumptions.py` use built-in situations, so none of + those three tests the new default as written. 5. **Documentation:** the `assumptions/` section records the switch and any remaining aggregate gaps. @@ -95,25 +105,37 @@ A documented gate must pass before any environment's default changes: 1. Dataset choice stays a runtime setting: no code in this repo branches on which dataset is loaded. One parameter is tied to the dataset, though: - `gov.simulation.vat.survey_consumption_coverage` is calibrated to the - Microcosm UK 2024-25 release only, puts VAT 38% to 44% above 2024-25 - receipts on the Enhanced FRS 2024-25, and has to be re-derived when the - default dataset changes (`docs/engineering/vat-coverage.md`). + `gov.simulation.vat.survey_consumption_coverage` is calibrated to one + Microcosm UK 2024-25 national cut only + (`microcosm-uk-2024-25-national-20261002T230158Z-5c6b3f68`; policyengine.py + 6.10.0 pins the later cut + `microcosm-uk-2024-25-national-20261019T083323Z-6cba5d71`), puts 2024-25 + VAT 38% (policyengine-uk-data 1.56.16) or 44% (1.58.0) above receipts on + the Enhanced FRS 2024-25, and has to be re-derived when the dataset it + should match changes (`docs/engineering/vat-coverage.md`). 2. While both are in use, CI runs the dataset-dependent tests on both. -3. The default is set per environment through - `POLICYENGINE_UK_DEFAULT_DATASET` (in policyengine.py, through its bundle - manifest), with the eFRS file kept available. -4. Rolling back is changing that setting and redeploying. The only change - needed here is re-deriving dataset-calibrated parameters such as the VAT - coverage above. This assumes the eFRS file stays published while the - switch beds in. +3. The default is set per environment: for direct use of this package + through `POLICYENGINE_UK_DEFAULT_DATASET`; for this repository's tests + through the pin in `policyengine_uk/tests/certified_dataset.yaml` (with + the reform regression fixtures recording the same dataset); and in + policyengine.py through its bundle manifest's `default_dataset`, which + changes with a policyengine.py release. The eFRS file is kept available. +4. Rolling back is changing that setting and redeploying (in policyengine.py, + a new bundle release). In this repository it also means re-pinning the + test dataset and regression fixtures if the tests have switched, and + re-deriving dataset-calibrated parameters such as the VAT coverage above. + This assumes the eFRS file stays published while the switch beds in. ## Acceptance PolicyEngine UK switches its default only after the gates above pass, with a -rollback that needs no code change in this repo beyond dataset-calibrated -parameters. Until then either dataset can -be used by passing `dataset=` or setting the environment variable. +rollback that needs no change in this repo beyond re-pinning the test +dataset and re-deriving dataset-calibrated parameters. Until then either +dataset can be used by passing `dataset=` or setting the environment +variable. Microcosm UK files sit in a Hugging Face dataset repository, and +this package's `hf://` loader requests model repositories (policyengine-core's +`download_huggingface_dataset` passes `repo_type="model"`), so download a +Microcosm file and pass its local path. ## References From 20cad2fc6d34b1b82c7b352b7294bc0414886a46 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 23 Oct 2026 03:47:55 -0400 Subject: [PATCH 6/6] Note that the test pin's downloader also needs dataset-repo support Second-round review: materialise() in utils/aggregate_impact/dataset.py downloads the pinned file with repo_type="model" and load_pin() accepts no repository-type key, so criterion 4 cannot pin a Microcosm file without a loader change. Also corrected the description of the three named tests. Co-Authored-By: Claude Opus 5.5 --- docs/book/assumptions/mp30k-uk-switch-plan.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/book/assumptions/mp30k-uk-switch-plan.md b/docs/book/assumptions/mp30k-uk-switch-plan.md index 98c8a20c13..374e9209f3 100644 --- a/docs/book/assumptions/mp30k-uk-switch-plan.md +++ b/docs/book/assumptions/mp30k-uk-switch-plan.md @@ -58,6 +58,14 @@ This repository's tests remain on the eFRS. unknown name raises a `ValueError` when the dataset is encoded (policyengine-core's `Enum.encode`); integer-coded columns are not checked. +- This package's `hf://` loader (policyengine-core's + `download_huggingface_dataset`) and the test pin's downloader (`materialise` + in `policyengine_uk/utils/aggregate_impact/dataset.py`) both request Hugging + Face model repositories (`repo_type="model"`), and the pin file has no + repository-type field. Microcosm UK files sit in a dataset repository + (`policyengine/populace-uk-private`), so pinning one for the tests + (criterion 4) needs both to accept dataset repositories first, and loading + one by `hf://` needs the loader to. ### Variables @@ -94,10 +102,12 @@ A documented gate must pass before any environment's default changes: 4. **Tests:** the suite passes with the new dataset pinned in `policyengine_uk/tests/certified_dataset.yaml`, with the reform regression fixtures in `policyengine_uk/tests/microsimulation/reforms_config.yaml` - moved to the same dataset. `test_latest_data_smoke.py` loads a fixed - `enhanced_frs_2023_24.h5`, and `test_deterministic_variables.py` and - `test_no_economic_assumptions.py` use built-in situations, so none of - those three tests the new default as written. + moved to the same dataset. `test_latest_data_smoke.py` loads a + hard-coded, unpinned `enhanced_frs_2023_24.h5`; + `test_deterministic_variables.py` uses inline situations and + `test_no_economic_assumptions.py` an inline situation and a hand-built + one-person dataset, so none of those three tests the new default as + written. 5. **Documentation:** the `assumptions/` section records the switch and any remaining aggregate gaps.