From e061a2c1868da849394cf654b1cdb2be2727c83e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Nov 2026 16:22:45 +0000 Subject: [PATCH 1/6] chore(deps): update policyengine to 6.20.0 --- .../update-policyengine-6.20.0.changed.md | 1 + .../pyproject.toml | 4 ++-- .../policyengine-simulation-executor/uv.lock | 22 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 changelog.d/update-policyengine-6.20.0.changed.md diff --git a/changelog.d/update-policyengine-6.20.0.changed.md b/changelog.d/update-policyengine-6.20.0.changed.md new file mode 100644 index 000000000..04b8fb9b5 --- /dev/null +++ b/changelog.d/update-policyengine-6.20.0.changed.md @@ -0,0 +1 @@ +Updated policyengine.py from 6.17.1 to 6.20.0 in the simulation runtime. diff --git a/projects/policyengine-simulation-executor/pyproject.toml b/projects/policyengine-simulation-executor/pyproject.toml index 2b4f42ac6..0352f41cd 100644 --- a/projects/policyengine-simulation-executor/pyproject.toml +++ b/projects/policyengine-simulation-executor/pyproject.toml @@ -21,7 +21,7 @@ dependencies = [ "policyengine-stage12-persistence", # PolicyEngine.py's models extra is the only selector for core, country # models, and the SPM calculator. Do not duplicate those versions here. - "policyengine[models]==6.17.1", + "policyengine[models]==6.20.0", "tables>=3.10.2", "modal>=0.73.0", "policyengine-observability[fastapi,google,otlp-grpc]>=3.0.7,<4", @@ -49,7 +49,7 @@ packages = ["src/policyengine_simulation_executor"] # certified datasets and writes their receipt. [dependency-groups] modal-simulation-image = [ - "policyengine[models]==6.17.1", + "policyengine[models]==6.20.0", "fastapi>=0.115.0", "tables>=3.10.2", "policyengine-observability[fastapi,google,otlp-grpc]>=3.0.7,<4", diff --git a/projects/policyengine-simulation-executor/uv.lock b/projects/policyengine-simulation-executor/uv.lock index b46aa9520..66aff8e33 100644 --- a/projects/policyengine-simulation-executor/uv.lock +++ b/projects/policyengine-simulation-executor/uv.lock @@ -1747,7 +1747,7 @@ wheels = [ [[package]] name = "policyengine" -version = "6.17.1" +version = "6.20.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "h5py" }, @@ -1759,9 +1759,9 @@ dependencies = [ { name = "pydantic" }, { name = "requests" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/da/45/483142f35ce0dfa02db01e541f730843b9108ae4b60a8bdae92ac223f3b2/policyengine-6.17.1.tar.gz", hash = "sha256:07a2617c738a77d2f1fd8ff2c5f4d89b040a54f44e9f931331a7ae34fdbbfc9f", size = 1629731, upload-time = "2026-11-10T16:26:24.672Z" } +sdist = { url = "https://files.pythonhosted.org/packages/14/e8/4373c716f428ed885392ff1776dc1be1f9e9a3a6f7608afcc1f39d683546/policyengine-6.20.0.tar.gz", hash = "sha256:65dad563d92c17485c5943b2bb8114d8f16cd49c977acbce6412cd8b8bcfadfd", size = 1863269, upload-time = "2026-11-16T16:21:45.756Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/1f/d5/e8b6181f512e5c3b14bbd0638a4c179515a9f479a68a6eaba640005b0fad/policyengine-6.17.1-py3-none-any.whl", hash = "sha256:7fa63f9f6524d911ff7a490448a2b202341487dc09d5c945fc0e0c816893df1e", size = 562776, upload-time = "2026-11-10T16:26:22.717Z" }, + { url = "https://files.pythonhosted.org/packages/64/b6/9ebed9a78c755c25893a20c924bc6952100bc3376608511fbcdb065145c3/policyengine-6.20.0-py3-none-any.whl", hash = "sha256:cc2da1b7448ae229294090318140bfe39440e8899415b8e465459c7e89bb7135", size = 774390, upload-time = "2026-11-16T16:21:43.414Z" }, ] [package.optional-dependencies] @@ -1953,7 +1953,7 @@ requires-dist = [ { name = "openapi-python-client", marker = "extra == 'build'", specifier = ">=0.21.6" }, { name = "opentelemetry-instrumentation-fastapi", specifier = ">=0.65b0,<0.66" }, { name = "opentelemetry-instrumentation-sqlalchemy", specifier = ">=0.65b0,<0.66" }, - { name = "policyengine", extras = ["models"], specifier = "==6.17.1" }, + { name = "policyengine", extras = ["models"], specifier = "==6.20.0" }, { name = "policyengine-fastapi", editable = "../../libs/policyengine-fastapi" }, { name = "policyengine-observability", extras = ["fastapi", "google", "otlp-grpc"], specifier = ">=3.0.7,<4" }, { name = "policyengine-simulation-contract", extras = ["modal"], editable = "../../libs/policyengine-simulation-contract" }, @@ -1976,7 +1976,7 @@ modal-simulation-image = [ { name = "fastapi", specifier = ">=0.115.0" }, { name = "google-cloud-storage", specifier = ">=2" }, { name = "huggingface-hub", specifier = ">=1,<2" }, - { name = "policyengine", extras = ["models"], specifier = "==6.17.1" }, + { name = "policyengine", extras = ["models"], specifier = "==6.20.0" }, { name = "policyengine-observability", extras = ["fastapi", "google", "otlp-grpc"], specifier = ">=3.0.7,<4" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.2,<4" }, { name = "pyarrow", specifier = ">=20,<24" }, @@ -2088,7 +2088,7 @@ wheels = [ [[package]] name = "policyengine-us" -version = "2.2.1" +version = "2.2.2" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "microdf-python" }, @@ -2098,9 +2098,9 @@ dependencies = [ { name = "tables" }, { name = "tqdm" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/2c/09/763b21371a62635e15e62b53fb696e299f01460907c27313d40f63031eb2/policyengine_us-2.2.1.tar.gz", hash = "sha256:d5300c91f3eae2e47a61f485fdfde91a892b80e95db3e46ff2c4bbd417d76501", size = 11946510, upload-time = "2026-09-15T04:45:50.33Z" } +sdist = { url = "https://files.pythonhosted.org/packages/72/86/1bbc7ab8d689987b364e624ef550a7a43ec49343b863be39b267a7c3477b/policyengine_us-2.2.2.tar.gz", hash = "sha256:a7cd4383d82e2453a3433e49d5501fd21b01b43b3910a66954d0a3cfe65f422b", size = 11947023, upload-time = "2026-11-09T20:52:43.712Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/5e/09/86ac3968d2a18e28fce3ba1186fc21728e9f299b96a806d6f204f1e0aaed/policyengine_us-2.2.1-py3-none-any.whl", hash = "sha256:0993a6c73fcdfbe171a796aca9d302741bd8e00ab83388ad81c15a08740318c6", size = 14885537, upload-time = "2026-09-15T04:45:46.649Z" }, + { url = "https://files.pythonhosted.org/packages/84/89/12a44d68e4131cc6ad92cfa22959254c69306d1f25fa6760ea1aab851bcb/policyengine_us-2.2.2-py3-none-any.whl", hash = "sha256:82ac620444dc0f246559fcbf7b34daee5a921a57684b63121f319365820811ce", size = 14885748, upload-time = "2026-11-09T20:52:38.979Z" }, ] [[package]] @@ -2719,7 +2719,7 @@ wheels = [ [[package]] name = "spm-calculator" -version = "1.0.0" +version = "1.1.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "census" }, @@ -2729,9 +2729,9 @@ dependencies = [ { name = "requests" }, { name = "us" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/c2/5e/3f28b212c401795990250bb3daec741f699a8c7dc2a23a3db7005df6feb6/spm_calculator-1.0.0.tar.gz", hash = "sha256:a99aac8c2c0bf81a9455105bbf872366f1ea9066a99cd793714881cd3db846dc", size = 7150825, upload-time = "2026-09-11T15:45:12.732Z" } +sdist = { url = "https://files.pythonhosted.org/packages/33/84/19057fa04e6c8cce85494458b2164d473ce82cbf54608a3b2951af2c36b1/spm_calculator-1.1.0.tar.gz", hash = "sha256:1be418c6a1baaba86f63c3287b38efecf7f94af563b864a73934ecbf60a01f38", size = 9625137, upload-time = "2026-11-02T18:48:45.002Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/19/a0/c484f69a0ebf88a9b9fd0ac28176f8df66550f46714f1b0c5ec0b360824e/spm_calculator-1.0.0-py3-none-any.whl", hash = "sha256:e354937a5e1a4045d4966ed594a528d8b02866fabaac9bb5672017004b627305", size = 7395384, upload-time = "2026-09-11T15:45:10.492Z" }, + { url = "https://files.pythonhosted.org/packages/35/91/12a744eb7f3445db8899dc187bbd193c884f9fe4c373851c0ddb24cc0f5e/spm_calculator-1.1.0-py3-none-any.whl", hash = "sha256:c528ec0f06eeb1188b7d6cf456ff3a9b73a0fd8856b3938358251cc5f9be83e8", size = 9881340, upload-time = "2026-11-02T18:48:42.665Z" }, ] [[package]] From 324a8e6226fd141c10459cbdb7563c00ec0ca0fe Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:53:11 +0400 Subject: [PATCH 2/6] =?UTF-8?q?Expect=20the=202022=E2=80=932036=20SPM=20fo?= =?UTF-8?q?recast=20in=20the=20worker=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The forecast in spm-calculator 1.1.0 runs to 2036 and has content digest 335e6755…, so 2037 becomes the first year the worker refuses (#805). The native year-boundary tests also pass the observability runtime the worker entrypoints now require; without it every case failed with a TypeError before checking any year. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_household_spm.py | 2 +- .../tests/test_spm_runtime_native.py | 48 ++++++++++++------- .../tests/test_stage12_report_run_reuse.py | 2 +- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/projects/policyengine-simulation-executor/tests/test_household_spm.py b/projects/policyengine-simulation-executor/tests/test_household_spm.py index d1053aa52..6b03d9e6d 100644 --- a/projects/policyengine-simulation-executor/tests/test_household_spm.py +++ b/projects/policyengine-simulation-executor/tests/test_household_spm.py @@ -6,7 +6,7 @@ from policyengine_simulation_contract.spm import SPMInputError from policyengine_simulation_executor import household_spm -FORECAST_SHA = "3d86d5c4c0423480e6b69b75d222ffa4a7a2639e4094df5ba2504af01be17173" +FORECAST_SHA = "335e6755dc8e0bd883e09b76c2bd53a5315683773e44d50085c7d6b8832b6291" DEFAULTS = { "as_of": None, "county_vintage": "2020", diff --git a/projects/policyengine-simulation-executor/tests/test_spm_runtime_native.py b/projects/policyengine-simulation-executor/tests/test_spm_runtime_native.py index a32807f2f..3d19ef310 100644 --- a/projects/policyengine-simulation-executor/tests/test_spm_runtime_native.py +++ b/projects/policyengine-simulation-executor/tests/test_spm_runtime_native.py @@ -6,6 +6,7 @@ import os import re +from functools import partial from unittest.mock import Mock import pytest @@ -23,7 +24,12 @@ def forecast(): return _forecast(runtime_spm_capability().defaults.forecast_content_sha256) -def _worker_entrypoint(params, monkeypatch): +def _worker_entrypoint(params, monkeypatch, observability_runtime): + """Return the worker entrypoint for ``params`` and a mock of its next step. + + The entrypoint runs under ``observability_runtime``. The mock replaces the + first step after SPM prevalidation, so a rejected request never reaches it. + """ from policyengine_simulation_executor import region_resolution, simulation_runtime from src.modal import budget_window_batch @@ -35,22 +41,22 @@ def _worker_entrypoint(params, monkeypatch): entrypoint = simulation_runtime._run_simulation_impl_core boundary = Mock(side_effect=AssertionError("Must reject before dataset lookup")) monkeypatch.setattr(region_resolution, "resolve_dataset_reference", boundary) - return entrypoint, boundary + return partial(entrypoint, runtime=observability_runtime), boundary @pytest.mark.parametrize( ("period", "unavailable_year"), [ ({"time_period": "2021"}, 2021), - ({"time_period": "2036"}, 2036), + ({"time_period": "2037"}, 2037), ({"year": "2040"}, 2040), ({"start_year": "2021", "window_size": 1}, 2021), - ({"start_year": "2036", "window_size": 1}, 2036), - ({"start_year": "2035", "window_size": 2}, 2036), + ({"start_year": "2037", "window_size": 1}, 2037), + ({"start_year": "2036", "window_size": 2}, 2037), ], ) def test_worker_year_boundary_matches_real_provider( - forecast, period, unavailable_year, monkeypatch + forecast, period, unavailable_year, monkeypatch, observability_runtime ): from policyengine_simulation_contract.spm import SPMInputError, spm_error_detail from spm_calculator.policyengine_adapter import PolicyEngineSPMProvider @@ -65,7 +71,9 @@ def test_worker_year_boundary_matches_real_provider( assert expected.code == "SPM_YEAR_UNAVAILABLE" assert provider.provenance()["years"] == {} params = {"country": "us", "spm": {"geography_kind": "national"}, **period} - entrypoint, boundary = _worker_entrypoint(params, monkeypatch) + entrypoint, boundary = _worker_entrypoint( + params, monkeypatch, observability_runtime + ) with pytest.raises(SPMInputError) as error: entrypoint(params) assert error.value.to_dict() == expected.model_dump() @@ -80,7 +88,7 @@ def test_worker_year_boundary_matches_real_provider( ], ) def test_worker_scenario_boundary_matches_real_calculator_contract( - forecast, period, monkeypatch + forecast, period, monkeypatch, observability_runtime ): from policyengine_simulation_contract.spm import SPMInputError, spm_error_detail from spm_calculator.axiom_adapter import export_build_spec @@ -98,26 +106,34 @@ def test_worker_scenario_boundary_matches_real_calculator_contract( "spm": {"geography_kind": "national", "scenario": scenario}, **period, } - entrypoint, boundary = _worker_entrypoint(params, monkeypatch) + entrypoint, boundary = _worker_entrypoint( + params, monkeypatch, observability_runtime + ) with pytest.raises(SPMInputError) as error: entrypoint(params) assert error.value.to_dict() == expected.model_dump() boundary.assert_not_called() -def test_valid_worker_prevalidation_does_not_evaluate_amounts(forecast, monkeypatch): +@pytest.mark.parametrize( + "period", + [ + {"start_year": "2034", "window_size": 2}, + # The forecast's last year, alone and as the last year of a window. + {"time_period": "2036"}, + {"start_year": "2027", "window_size": 10}, + ], +) +def test_valid_worker_prevalidation_does_not_evaluate_amounts( + forecast, period, monkeypatch +): from policyengine_simulation_executor.spm import normalize_runtime_spm from spm_calculator.policyengine_adapter import PolicyEngineSPMProvider calculate = Mock(side_effect=AssertionError("Prevalidation is not measurement")) monkeypatch.setattr(PolicyEngineSPMProvider, "calculate_unit", calculate) resolved = normalize_runtime_spm( - { - "country": "us", - "start_year": "2034", - "window_size": 2, - "spm": {"geography_kind": "national"}, - } + {"country": "us", "spm": {"geography_kind": "national"}, **period} ) assert resolved["geography_kind"] == "national" provider = PolicyEngineSPMProvider( diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py b/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py index 50d678948..51f14ee54 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py @@ -66,7 +66,7 @@ "as_of": None, "county_vintage": "2020", "forecast_content_sha256": ( - "3d86d5c4c0423480e6b69b75d222ffa4a7a2639e4094df5ba2504af01be17173" + "335e6755dc8e0bd883e09b76c2bd53a5315683773e44d50085c7d6b8832b6291" ), "geography_id": None, "geography_kind": "county", From c6005f0ada9101289c0f25d437bf86b6254d02bb Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:30:54 +0400 Subject: [PATCH 3/6] Name 6.20.0 as the bundle the SPM stand-in copies, and add the changelog fragment Co-Authored-By: Claude Opus 5.5 --- changelog.d/805-spm-forecast-2036.changed.md | 1 + .../tests/test_stage12_report_run_reuse.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog.d/805-spm-forecast-2036.changed.md diff --git a/changelog.d/805-spm-forecast-2036.changed.md b/changelog.d/805-spm-forecast-2036.changed.md new file mode 100644 index 000000000..b8195f478 --- /dev/null +++ b/changelog.d/805-spm-forecast-2036.changed.md @@ -0,0 +1 @@ +US simulations for 2036 now run: the worker uses policyengine.py 6.20.0, with policyengine-us 2.2.2 and spm-calculator 1.1.0, whose SPM forecast covers 2022–2036. 2037 is now the first year the worker refuses with `SPM_YEAR_UNAVAILABLE`. diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py b/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py index 51f14ee54..1a5f60e13 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_report_run_reuse.py @@ -60,7 +60,7 @@ OUTPUT_BUCKET = "detailed-save-outputs" # A catalog row the report's simulations don't use. OTHER_CATALOG_ID = UUID("00000000-0000-0000-0000-0000000000f1") -# The certified SPM defaults of the installed .py bundle (6.17.1), which a US +# The certified SPM defaults of the installed .py bundle (6.20.0), which a US # request takes for each SPM option it leaves out. CERTIFIED_SPM_DEFAULTS = { "as_of": None, From 14c716e5c924be117725cb32f18c6e0c771c2892 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:56:14 +0400 Subject: [PATCH 4/6] Report the release's data version from Stage 12 for default-dataset runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit policyengine.py 6.20.0 addresses the US national dataset by a Hugging Face commit (0ff35303…) while the release keeps its version name (populace-us-2024-spm-20260915). The main path reports the release's data version for a run on the default dataset; Stage 12 reported the dataset's revision. Until 6.20.0 the two were the same string, so every US national Stage 12 comparison would now record a data_version difference, and parity qualification would refuse every US national input with dataset_provenance_mismatch. Stage 12 output and the parity check now take the value the main path reports: the release's data version for the default dataset, and the dataset's revision for any other, as before. Co-Authored-By: Claude Opus 5.5 --- changelog.d/805-spm-forecast-2036.changed.md | 2 +- .../stage12_qualification.py | 21 ++++++-- .../stage12_runtime/aggregation.py | 26 +++++++++- .../tests/test_stage12_aggregate_reports.py | 51 +++++++++++++++++-- .../tests/test_stage12_qualification.py | 38 +++++++++++--- 5 files changed, 122 insertions(+), 16 deletions(-) diff --git a/changelog.d/805-spm-forecast-2036.changed.md b/changelog.d/805-spm-forecast-2036.changed.md index b8195f478..7daed8b42 100644 --- a/changelog.d/805-spm-forecast-2036.changed.md +++ b/changelog.d/805-spm-forecast-2036.changed.md @@ -1 +1 @@ -US simulations for 2036 now run: the worker uses policyengine.py 6.20.0, with policyengine-us 2.2.2 and spm-calculator 1.1.0, whose SPM forecast covers 2022–2036. 2037 is now the first year the worker refuses with `SPM_YEAR_UNAVAILABLE`. +US simulations for 2036 now run: the worker uses policyengine.py 6.20.0, with policyengine-us 2.2.2 and spm-calculator 1.1.0, whose SPM forecast covers 2022–2036. 2037 is now the first year the worker refuses with `SPM_YEAR_UNAVAILABLE`. Stage 12 results for US national runs keep reporting the release's data version, as the main path does, now that the bundle addresses the national dataset by a Hugging Face commit. diff --git a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py index c3046fc9e..18725a7cd 100644 --- a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py +++ b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py @@ -6,7 +6,7 @@ from concurrent.futures import ThreadPoolExecutor from dataclasses import dataclass from hashlib import sha256 -from typing import Any, Literal +from typing import TYPE_CHECKING, Any, Literal import pandas as pd from policyengine_observability import ( @@ -55,6 +55,7 @@ stage12_region_groups_for_model, ) from policyengine_simulation_executor.stage12_runtime.aggregation import ( + reported_data_version, validate_uk_local_authority_metadata, ) from policyengine_simulation_executor.stage12_runtime.output_planning import ( @@ -62,6 +63,9 @@ resolve_report_output_plan, ) +if TYPE_CHECKING: + from policyengine_simulation_contract.stage12_bundle import CountryId + class Stage12ParityReceipt(BaseModel): """Value-free evidence for one completed parity qualification.""" @@ -335,15 +339,22 @@ def run_existing(request: dict[str, Any]) -> Mapping[str, Any]: def _validate_existing_provenance( existing_result: Mapping[str, Any], bundle: BundleProvenance, + country: CountryId, ) -> None: - """Require the existing result's model and data versions to be the bundle's.""" + """Require the existing result's model and data versions to be the bundle's. + + The data version is the one the existing path reports for the bundle's + dataset (see ``reported_data_version``). + """ if existing_result.get("model_version") != bundle.country_package_version: error_code = "country_package_provenance_mismatch" raise ParityMismatchError( error_code, "report.model_version", ) - if existing_result.get("data_version") != bundle.dataset.artifact_revision: + if existing_result.get("data_version") != reported_data_version( + country, bundle.dataset + ): error_code = "dataset_provenance_mismatch" raise ParityMismatchError( error_code, @@ -430,7 +441,9 @@ def qualify_report_parity( existing_baseline = _existing_frames(microdata, side="baseline") existing_reform = _existing_frames(microdata, side="reform") bundle = report.baseline.bundle - _validate_existing_provenance(existing_result, bundle) + _validate_existing_provenance( + existing_result, bundle, report.baseline.geography.country + ) baseline_calculation, reform_calculation = _run_v2_simulations( runners.single_simulation, diff --git a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py index 4b732f85a..d0914e0ad 100644 --- a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py +++ b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py @@ -24,10 +24,32 @@ from policyengine.tax_benefit_models.uk.datasets import PolicyEngineUKDataset from policyengine.tax_benefit_models.us.datasets import PolicyEngineUSDataset from policyengine_simulation_contract.stage12_bundle import CountryId + from policyengine_simulation_contract.stage12_execution import DatasetProvenance from policyengine_simulation_contract.uk_geography import UKLocalAuthorityMetadata from pydantic import JsonValue +def reported_data_version(country: CountryId, dataset: DatasetProvenance) -> str: + """Return the ``data_version`` the main path reports for a run on ``dataset``. + + For a run on the country's default dataset the main path reports the + installed release's data version. For a run on another dataset, such as a + US state or district run on the regional dataset or a UK local-area + breakdown, it reports that dataset's revision. Until policyengine.py + 6.20.0 the default dataset's revision was the release's data version; + since then the US one is a Hugging Face commit, while the release keeps + its version name. + """ + from policyengine_simulation_executor.release_bundle import ( # noqa: PLC0415 # resolved per call so tests can patch release_bundle.get_country_release_bundle + get_country_release_bundle, + ) + + release = get_country_release_bundle(country) + if dataset.identity == release.default_dataset: + return release.data_version + return dataset.artifact_revision + + def validate_uk_local_authority_metadata( country: CountryId, baseline: UKLocalAuthorityMetadata | None, @@ -242,7 +264,9 @@ def stand_in( dataset=datasets["baseline"], baseline=stand_in(datasets["baseline"], report.baseline.policy), reform=stand_in(datasets["reform"], report.reform.policy), - resolved_data_version=report.baseline.bundle.dataset.artifact_revision, + resolved_data_version=reported_data_version( + country, report.baseline.bundle.dataset + ), resolved_region_code=report.baseline.geography.region, uk_local_authority_metadata=uk_local_authority_metadata, omit_uk_area_breakdowns=not local_area_report diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py b/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py index 3304280cf..1ec8b30c4 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py @@ -4,6 +4,7 @@ import json from hashlib import sha256 +from types import SimpleNamespace from uuid import uuid4 import pandas as pd @@ -33,6 +34,24 @@ spm_calculation_provenance, ) +# The installed release's data version, which differs from the default +# dataset's revision: since policyengine.py 6.20.0 the US revision is a Hugging +# Face commit, while the release keeps its version name. +RELEASE_DATA_VERSION = "populace-us-2024-release" + + +def _install_release_bundle(monkeypatch) -> None: + """Stand in for the installed US release, whose default is the fixture's dataset.""" + from policyengine_simulation_executor import release_bundle + + installed = SimpleNamespace( + default_dataset=bundle_provenance().dataset.identity, + data_version=RELEASE_DATA_VERSION, + ) + monkeypatch.setattr( + release_bundle, "get_country_release_bundle", lambda _country: installed + ) + def test_aggregate_combines_detached_spm_receipts() -> None: provenance = spm_calculation_provenance() @@ -342,6 +361,7 @@ def test_aggregate_report_wraps_builder_output_with_report_provenance( ) -> None: from policyengine_simulation_executor import simulation_output_builder + _install_release_bundle(monkeypatch) report = report_execution_input() report = report.model_copy( update={"reform": report.reform.model_copy(update={"policy": {}})} @@ -414,14 +434,39 @@ def serialize(self): for role, income in (("baseline", 100.0), ("reform", 120.0)): household = observed[role].output_dataset.data.household assert household["household_net_income"].tolist() == [income] - assert observed["resolved_data_version"] == ( - report.baseline.bundle.dataset.artifact_revision - ) + # The output reports what the main path reports for the default dataset: + # the release's data version, not the dataset's revision. + assert observed["resolved_data_version"] == RELEASE_DATA_VERSION assert observed["resolved_region_code"] == report.baseline.geography.region assert observed["uk_local_authority_metadata"] is None assert observed["omit_uk_area_breakdowns"] is False +@pytest.mark.parametrize( + ("identity", "artifact_revision", "expected"), + [ + ("populace_us_2024", "0ff35303", RELEASE_DATA_VERSION), + ("populace_us_2024_acs_local", "28f355b8", "28f355b8"), + ], + ids=["default-dataset", "regional-dataset"], +) +def test_the_reported_data_version_is_the_one_the_main_path_reports( + identity, artifact_revision, expected, monkeypatch +) -> None: + # The main path reports the release's data version for a run on the + # default dataset and the dataset's own revision for any other dataset. + from policyengine_simulation_executor.stage12_runtime.aggregation import ( + reported_data_version, + ) + + _install_release_bundle(monkeypatch) + dataset = bundle_provenance().dataset.model_copy( + update={"identity": identity, "artifact_revision": artifact_revision} + ) + + assert reported_data_version("us", dataset) == expected + + def test_single_worker_rejects_combined_baseline_and_reform_input() -> None: payload = planned_simulation(SimulationRole.BASELINE).model_dump(mode="json") payload["baseline"] = {} diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_qualification.py b/projects/policyengine-simulation-executor/tests/test_stage12_qualification.py index 5b67d0e5f..53f3ba885 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_qualification.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_qualification.py @@ -2,6 +2,7 @@ from __future__ import annotations +from types import SimpleNamespace from typing import Any import numpy as np @@ -25,7 +26,30 @@ from policyengine_simulation_executor.stage12_runtime.partition import ( US_REGION_GROUPS, ) -from stage12_runtime_support import planned_simulation, report_execution_input +from stage12_runtime_support import ( + bundle_provenance, + planned_simulation, + report_execution_input, +) + +# The data version the existing path reports for a run on the default dataset: +# the installed release's, which since policyengine.py 6.20.0 differs from the +# US default dataset's revision (a Hugging Face commit). +RELEASE_DATA_VERSION = "populace-us-2024-release" + + +@pytest.fixture(autouse=True) +def installed_release(monkeypatch) -> None: + """Stand in for the installed US release, whose default is the fixture's dataset.""" + from policyengine_simulation_executor import release_bundle + + installed = SimpleNamespace( + default_dataset=bundle_provenance().dataset.identity, + data_version=RELEASE_DATA_VERSION, + ) + monkeypatch.setattr( + release_bundle, "get_country_release_bundle", lambda _country: installed + ) def _frames(value: float) -> dict[str, pd.DataFrame]: @@ -117,7 +141,7 @@ def existing_runner(request): assert request == {**_existing_request(), "_emit_microdata": True} return { "model_version": report.baseline.bundle.country_package_version, - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "budget": {"budgetary_impact": 20.0}, "poverty": {"all": {"baseline": 0.1, "reform": 0.09}}, "_microdata": extract_output_microdata( @@ -140,7 +164,7 @@ def aggregate_builder(**arguments): return { "result": { "model_version": report.baseline.bundle.country_package_version, - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "budget": {"budgetary_impact": 20.0}, "poverty": {"all": {"baseline": 0.1, "reform": 0.09}}, } @@ -180,7 +204,7 @@ def test_qualification_fails_with_bounded_diagnostic_without_output_values() -> def existing_runner(_request): return { "model_version": report.baseline.bundle.country_package_version, - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "budget": {"budgetary_impact": 20.0}, "_microdata": extract_output_microdata( _Simulation(baseline), @@ -235,7 +259,7 @@ def test_qualification_rejects_existing_executor_provenance_mismatch() -> None: def existing_runner(_request): return { "model_version": "different", - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "_microdata": extract_output_microdata( _Simulation(baseline), _Simulation(reform), @@ -257,7 +281,7 @@ def _matching_existing_runner(report, baseline, reform, **overrides): def existing_runner(_request): return { "model_version": report.baseline.bundle.country_package_version, - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "budget": {"budgetary_impact": 20.0}, "_microdata": extract_output_microdata( _Simulation(baseline), @@ -295,7 +319,7 @@ def test_qualification_receipt_records_every_digest_and_tolerance_field() -> Non aggregate=lambda **_: { "result": { "model_version": report.baseline.bundle.country_package_version, - "data_version": report.baseline.bundle.dataset.artifact_revision, + "data_version": RELEASE_DATA_VERSION, "budget": {"budgetary_impact": 20.0}, } }, From 628eeeb865c3e8a95a8d68710a21f5d274ee3399 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:10:27 +0400 Subject: [PATCH 5/6] Compare Stage 12's US data version with the main path's on the installed bundle The new test reads the installed bundle with nothing stubbed and checks that Stage 12 reports the data version the main path reports for US national and state runs; with the earlier rule it fails for the national run. The docstring now names the one kind of run where the two still differ, a UK constituency or local-authority report, which predates policyengine.py 6.20.0. Co-Authored-By: Claude Opus 5.5 --- .../stage12_qualification.py | 4 +- .../stage12_runtime/aggregation.py | 14 ++--- .../tests/test_stage12_aggregate_reports.py | 53 +++++++++++++++++-- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py index 18725a7cd..ef9ff14f9 100644 --- a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py +++ b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_qualification.py @@ -343,8 +343,8 @@ def _validate_existing_provenance( ) -> None: """Require the existing result's model and data versions to be the bundle's. - The data version is the one the existing path reports for the bundle's - dataset (see ``reported_data_version``). + The data version must be ``reported_data_version`` of the bundle's + dataset. """ if existing_result.get("model_version") != bundle.country_package_version: error_code = "country_package_provenance_mismatch" diff --git a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py index d0914e0ad..7c13f9336 100644 --- a/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py +++ b/projects/policyengine-simulation-executor/src/policyengine_simulation_executor/stage12_runtime/aggregation.py @@ -33,12 +33,14 @@ def reported_data_version(country: CountryId, dataset: DatasetProvenance) -> str """Return the ``data_version`` the main path reports for a run on ``dataset``. For a run on the country's default dataset the main path reports the - installed release's data version. For a run on another dataset, such as a - US state or district run on the regional dataset or a UK local-area - breakdown, it reports that dataset's revision. Until policyengine.py - 6.20.0 the default dataset's revision was the release's data version; - since then the US one is a Hugging Face commit, while the release keeps - its version name. + installed release's data version, and so does this. For any other dataset + this returns the dataset's revision, which is what the main path reports + for a US state or district run on the regional dataset and for a UK + local-area breakdown. A UK constituency or local-authority report on the + local-area dataset is the exception: the main path reports the release's + data version for it. Until policyengine.py 6.20.0 the default dataset's + revision was the release's data version; since then the US one is a + Hugging Face commit, while the release keeps its version name. """ from policyengine_simulation_executor.release_bundle import ( # noqa: PLC0415 # resolved per call so tests can patch release_bundle.get_country_release_bundle get_country_release_bundle, diff --git a/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py b/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py index 1ec8b30c4..ad21e5377 100644 --- a/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py +++ b/projects/policyengine-simulation-executor/tests/test_stage12_aggregate_reports.py @@ -450,11 +450,9 @@ def serialize(self): ], ids=["default-dataset", "regional-dataset"], ) -def test_the_reported_data_version_is_the_one_the_main_path_reports( +def test_the_reported_data_version_is_the_release_version_only_for_the_default_dataset( identity, artifact_revision, expected, monkeypatch ) -> None: - # The main path reports the release's data version for a run on the - # default dataset and the dataset's own revision for any other dataset. from policyengine_simulation_executor.stage12_runtime.aggregation import ( reported_data_version, ) @@ -467,6 +465,55 @@ def test_the_reported_data_version_is_the_one_the_main_path_reports( assert reported_data_version("us", dataset) == expected +@pytest.mark.parametrize("region_type", ["national", "state"]) +def test_stage12_reports_the_us_data_version_the_main_path_reports( + region_type, +) -> None: + # Both paths read the installed bundle, with nothing stubbed. Since + # policyengine.py 6.20.0 the US default dataset's revision is a Hugging + # Face commit, no longer the release's data version. + from policyengine_simulation_contract.stage12_execution import DatasetProvenance + from policyengine_simulation_executor.simulation_output_provenance import ( + output_data_version, + ) + from policyengine_simulation_executor.simulation_runtime import ( + DatasetSelection, + _selected_dataset_revision, + ) + from policyengine_simulation_executor.stage12_bundle import load_stage12_bundle + from policyengine_simulation_executor.stage12_runtime.aggregation import ( + reported_data_version, + ) + + us = next( + country + for country in load_stage12_bundle().bundle.countries + if country.country == "us" + ) + identity = us.dataset_for_region_type(region_type) + dataset = next(item for item in us.datasets if item.identity == identity) + selection = DatasetSelection( + identity, dataset.uri, is_default=identity == us.default_dataset + ) + main_path = output_data_version( + "us", runtime=None, resolved=_selected_dataset_revision("us", selection) + ) + + assert ( + reported_data_version( + "us", + DatasetProvenance( + identity=identity, + uri=dataset.uri, + artifact_revision=dataset.artifact_revision, + data_package_name=us.data_package_name, + data_package_version=us.data_package_version, + ), + ) + == main_path + ) + + def test_single_worker_rejects_combined_baseline_and_reform_input() -> None: payload = planned_simulation(SimulationRole.BASELINE).model_dump(mode="json") payload["baseline"] = {} From a0902df116b8659708592fc4a33063a025367c69 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:12:46 +0400 Subject: [PATCH 6/6] Take the expected dataset address from the bundle in the logical-revision test policyengine.py 6.20.0 moved the US national dataset into a build folder (releases/microcosm-us-2024-national/populace-us-2024-spm-20260915/), so the root-level path this test expected no longer matches the address the resolver builds. The test now derives the repository and path from the installed bundle and checks only that the requested revision replaces the bundle's. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_release_bundle.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/policyengine-simulation-executor/tests/test_release_bundle.py b/projects/policyengine-simulation-executor/tests/test_release_bundle.py index 430bea485..5c6c28664 100644 --- a/projects/policyengine-simulation-executor/tests/test_release_bundle.py +++ b/projects/policyengine-simulation-executor/tests/test_release_bundle.py @@ -188,14 +188,14 @@ def test_resolve_bundle_dataset_uri_preserves_explicit_dataset_uri_and_revision( def test_resolve_bundle_dataset_uri_maps_explicit_logical_revision_to_hf_uri(): - dataset = "populace_us_2024@custom-v1" + # The repository and the path in it come from the bundle (a build folder + # since policyengine.py 6.20.0); only the revision is the requested one. + bundle = get_country_release_bundle("us") + dataset = f"{bundle.default_dataset}@custom-v1" + expected = f"{bundle.default_dataset_uri.rsplit('@', maxsplit=1)[0]}@custom-v1" - assert resolve_bundle_dataset_name("us", dataset).startswith( - "hf://policyengine/populace-us/populace_us_2024.h5@custom-v1" - ) - assert resolve_bundle_dataset_uri("us", dataset).startswith( - "hf://policyengine/populace-us/populace_us_2024.h5@custom-v1" - ) + assert resolve_bundle_dataset_name("us", dataset).startswith(expected) + assert resolve_bundle_dataset_uri("us", dataset).startswith(expected) def test_resolve_bundle_dataset_uri_preserves_explicit_gcs_uri():