Repository navigation
Serve UK constituency and local-authority results from the routed local-area dataset - #881
Draft
juaristi22 wants to merge 4 commits into
Draft
juaristi22 wants to merge 4 commits into
juaristi22 wants to merge 4 commits into
Conversation
When the policyengine.py bundle routes UK constituency and local-authority
regions to a local-area dataset and the national default carries no area
codes (policyengine.py 6.10.0), a national or nation-level run builds its
two area breakdowns from a second baseline and reform run: the same
policies and nation filter, on the routed dataset. That dataset must carry
constituency_code_oa and la_code_oa, and its authority codes must match one
packaged boundary version. The national figures still come from the run's
own pair, and the builder computes the second pair when the first
breakdown needs it.
Once routed, constituency and local-authority regions resolve by name or by
GSS code in any case to the row-filter regions in policyengine.py's
registry, so policyengine-api's constituency/{name} and
local_authority/{name} requests keep working, and no weight-matrix region is
built for them. The 17 districts replaced in April 2023 are unsupported.
Nothing changes on policyengine.py 6.7.5, which routes no area regions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The executor and Stage 12 image smokes read the installed UK default's local-authority codes. When the default carries none and the bundle routes area regions to another dataset, they now download that dataset next to the default, check it against the bundle digest, and read its codes instead. Both smoke functions mount the Hugging Face credential for that download, and the Stage 12 smoke asks for 2 GiB instead of 512 MiB to read the routed file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Stage 12 UK national or nation-level report whose bundle routes area regions to another dataset plans no constituency_code_oa or la_code_oa columns, since its national dataset may carry none, and its aggregate leaves the constituency and local-authority breakdowns out. Stage 12 has no second run on the routed dataset yet, so its shadow comparison reports the two breakdowns as missing for such reports. The planning tests that describe unrouted reports now pin routing off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #880
Part of #728. This makes the executor ready for policyengine.py 6.10.0 (PolicyEngine/policyengine.py#685), which makes the Microcosm national dataset the UK default and routes constituency and local-authority regions to the Microcosm local-area dataset. Every change below applies only when
uk_area_regions_routed()is true. It is false on the pinned 6.7.5, so this can merge before the bump and changes nothing until then.Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
On 6.10.0 the national file has no area codes. Without this PR, the bump fails every UK national and nation-level comparison, the image smoke and the deploy sentinel.
simulation_runtime.py,simulation_output_builder.py).Noneonly then, and only when routed.constituency_impactandlocal_authority_impactcome from that pair; every other figure still comes from the national pair.constituency_code_oaandla_code_oa, and its authority codes must match one packaged boundary version (detect_uk_area_dataset_metadata). The builder computes the second pair the first time a breakdown needs it.routed_uk_area_dataset_name()finds it the way policyengine.py'sregion_dataset_namedoes, and both area types must route to the same one.smoke_app.py,v2_static_runtime_files_smoke.py).la_code_oaand the bundle routes area regions.materialize_datasetchecks the download against the bundle's SHA-256.hf_secret, the secret the image build already uses for the private UK data. The Stage 12 smoke asks for 2 GiB instead of 512 MiB, because reading the routed file's codes peaked at about 0.5 GB locally.output_planning.py,aggregation.py). A routed national or nation-level report plans no area columns, and its aggregate leaves the two breakdowns out (omit_uk_area_breakdowns). Production is unaffected._registry_uk_area_region_code).constituency/…andlocal_authority/…match the region registry by GSS code in any case, or by name ignoring case.constituencies_2024.csvandlocal_authorities_2023.csv, and each region's label is the name in that list.Unsupported UK region.N09000011.How it combines with the 6.10.0 bump
auto/update-policyengine-6.10.0,pyproject.tomlanduv.lockonly) then needs no edits. If it opens before this merges, rerun its CI afterwards.sentinel_expectedjob runs the sentinel's UK national request in-process, so it computes the second pair too (see Cost).N09000011, Microcosm label) still waits until sim-api serves 6.10.0.Testing
ruff format --check projects/*/src libs/*/srcandruff check .(0.15.22) pass.test_uk_local_authority_metadata,test_simulation_output_builder,test_stage12_output_planning,test_stage12_runtime,test_smoke_app,test_stage12_modal_app,test_region_group_resolution,test_uk_weight_matrix_guard,test_simulation_output_geographic,test_stage12_qualification,test_stage12_worker_validation,test_microdata_weight_boundaries,test_runtime_evaluated_annotations,test_job_progress,test_precompute,test_stage12_cache_precompute,test_stage12_coordination,test_release_sentinel,test_segmented_nationalandtest_segmented_national_reduce.policyengine[models]==6.10.0(policyengine-uk 2.132.6, policyengine-core 3.33.3). 611 passed and 1 failed:test_v2_image_retains_required_runtime_dependenciescompares the pyproject pin with the installed bundle, so it passes once the bump moves the pin. Three existing planning tests describe unrouted reports and now pin routing off, so they pass on either release.run_simulation_implwith the sentinel'suk_basic_rate_21p_2026request:uk: 650 constituency and 361 local-authority records.country/wales: 32 and 22.constituency/Aldershotandlocal_authority/maidstone, addressed by name: resolve and run.local_authority/E07000026:Unsupported UK region.Cost
These are for the sentinel's UK national request on a 10-core Apple laptop with 32 GB. Nothing was measured on Modal.
output_uk_constituencyspan, which now includes computing the second pair, took 72 s.run_simulation's 32 GiB. It also fits the 16 GBubuntu-latestrunner ofsentinel_expected, though without much room.Risks and limits
run_simulationcalls, so each year also runs the second pair, although the window reads only the budget.dataset_resolutionanddataset_loadspans withdataset_role=uk_area, andsimulation_buildspans withsimulation_kindset touk_area_baselineoruk_area_reform. Its calculation counts towardsoutput_uk_constituency.simulation_output_builder.py,UK_GEOGRAPHIC_DATASET_VARIABLESandchangelog_entry.yaml, so whichever PR merges second needs a small rebase:_uk_geography_disclosure_output()should take its baseline and reform from_uk_area_breakdown_inputs().region_code_oaandsource_household_id. The local-area file carries both; the national file carries onlysource_household_id.constituency/{name}andlocal_authority/{name}requests resolve.country/ni, policyengine-api's spelling, stays unsupported, because policyengine.py names that regioncountry/northern_ireland.Follow-ups (under #728)
_build_uk_weight_replacement_region,_require_certified_uk_weight_matrixandtests/test_uk_weight_matrix_guard.py. 6.7.5 needs them until then.country/nitocountry/northern_ireland.🤖 Generated with Claude Code