UK: constituency and local-authority runs use enhanced-FRS weight matrices, and every UK run requires `la_code_oa`; both break on a Microcosm UK default
维护者通常 1 天内回复
评估
调研方向
Start with detect_uk_local_authority_metadata in uk_local_authority_metadata.py:280 and _resolve_region / _build_uk_weight_replacement_region in simulation_runtime.py:317 and :241, plus the same paths in stage12_runtime/simulation.py and stage12_worker_validation.py:80. Done means a UK dataset without la_code_oa loads and passes worker validation, local-authority requests fail only with a clear message, and the weight-matrix fallback validates household count before apply. Note open PR #727 already targets this issue, so confirm scope with maintainers before starting.
由索引模型根据 Issue 内容生成。
描述
Summary
policyengine.py plans to replace the UK default, the enhanced FRS 1.56.16, with a Microcosm national release. Constituency and local-authority runs would move to a separate Microcosm local-area dataset (PolicyEngine/policyengine.py#553, PolicyEngine/microcosm#1114). Two parts of the executor assume the enhanced FRS and would fail on that default. The second blocks every UK run, not only local ones. Line numbers below are at d1d4834.
1. Constituency and local-authority runs use enhanced-FRS weight matrices
- How the fallback is reached: policyengine.py's default UK registry has no constituency or local-authority regions;
build_uk_region_registry()loads them only on request. So_resolve_region(simulation_runtime.py:317) getsNonefromget_regionand falls back to_build_uk_weight_replacement_region(simulation_runtime.py:241). - What the fallback builds: a
WeightReplacementStrategyoverparliamentary_constituency_weights.h5orlocal_authority_weights.h5. These are looked up throughconstituencies_2024.csvorlocal_authorities_2021.csvin thepolicyengine-uk-data-privateGCS bucket. Both runtime paths (simulation_runtime.py:588,stage12_runtime/simulation.py:157) andprecompute.pygo through it. - Why it fails on another dataset: the matrices have one row per area and one column per enhanced-FRS household. The certified 1.56.16 copies on Hugging Face are 650 × 52,846 for constituencies and 360 × 52,846 for local authorities.
WeightReplacementStrategy.applyraisesWeight matrix row length (…) does not match household count (…)on any dataset of a different size. The published Microcosm national file has 63,827 households, so every constituency and local-authority run would fail on it. - Worth checking: the 1.56.16 copies on Hugging Face hold a single
2025key, andapplyreadsf[str(year)]. I could not read the GCS copies the executor downloads, so check that runs for other years find their key.
2. Every UK run requires la_code_oa
- Per-run check:
detect_uk_local_authority_metadata(uk_local_authority_metadata.py:280) runs on every UK dataset right after loading (simulation_runtime.py:608,stage12_runtime/simulation.py:183). It raisesUK dataset household table contains no la_code_oa columnwhen the column is missing. - Start-up check:
validate_country_workerruns the same check on the installed UK default (_check_uk_local_authority_dataset,stage12_worker_validation.py:80). - Effect on a Microcosm default: the Microcosm national file carries
regionand no area codes. With it as the default, every UK run fails at dataset load and UK workers fail validation. - Geographic reports: they also copy
constituency_code_oaandla_code_oainto their outputs (UK_GEOGRAPHIC_DATASET_VARIABLES,stage12_runtime/output_planning.py:26).
What already works for a Microcosm local-area file
- Boundary detection: with the aliases from PolicyEngine/microcosm#1114, the local file carries
la_code_oaon the April 2023 frame.detect_uk_local_authority_boundary_versionidentifies that frame as LAD23. The packagedcoordinates_lad23.csvhas all 361 codes, Ards and North Down included. - Local outputs:
build_uk_constituency_impactandbuild_uk_local_authority_impactalready group byconstituency_code_oaandla_code_oa, so they work on any file that carries those columns. - Dataset pins:
runtime_dataset_urikeeps an explicit revision for repositories outside the GCS-mirroredpolicyengine-*-datarepos. A Microcosm dataset inpopulace-uk-privatetherefore keeps its own pin.
Proposed changes
- Make the local-authority check conditional.
detect_uk_local_authority_metadatareturnsNonewhen the dataset has nola_code_oa.- The worker check accepts a default without area codes.
- Local-authority outputs and scoped runs fail with a clear message only when they are requested on such a dataset.
- This is needed before any policyengine.py release with a Microcosm UK default reaches the executor, so it gates the next
policyengine[models]pin bump (currently==6.2.1inprojects/policyengine-simulation-executor/pyproject.toml).
- Use policyengine.py's constituency and local-authority regions instead of building weight-replacement ones.
- PolicyEngine/policyengine.py#553 ships the area lists in the package and points those regions at the local-area dataset, the way PolicyEngine/policyengine.py#552 does for US states.
get_regionthen returns a row-filter region with its owndataset_path, and the fallback is no longer reached. - Until then, keep the fallback only for the enhanced FRS. Compare the resolved dataset's household count with the matrix before running, and stop with a clear message otherwise.
- PolicyEngine/policyengine.py#553 ships the area lists in the package and points those regions at the local-area dataset, the way PolicyEngine/policyengine.py#552 does for US states.
- Geographic outputs of national reports: run them on the local-area dataset, or skip them, when the national dataset carries no area codes. This follows decision 2 in PolicyEngine/policyengine.py#553.
- Loading cost: the size of the local-area file depends on the Microcosm local release. If it is large, the per-area extracts discussed in #717 for the US local-area file may apply here too.
Related
- PolicyEngine/policyengine.py#553: certifying a Microcosm national dataset, with separate national and local-area datasets.
- PolicyEngine/microcosm#1114:
_oaaliases on Microcosm local-area exports. - PolicyEngine/policyengine.py#552 and #717: the US counterpart (local-area dataset for state and district runs).
- policyengine-api (v1)
uk_constituency_breakdowndownloads the same enhanced-FRS constituency matrix.
🤖 Generated with Claude Code
- 主要语言
- Python
- 星标
- 1
- 派生
- 1
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PolicyEngine/policyengine-sim-api 的其他 Issue
-
Integration tests fail due to missing UV virtual environment setup可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
PolicyEngine/policyengine-sim-api#314 ·
维护者通常 1 天内回复
-
Update policyengine to 6.3.4可能已有人在做 @policyengine 于 1 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 40/100
PolicyEngine/policyengine-sim-api#796 ·
维护者通常 1 天内回复
-
Segmented US national runs wait on stuck regional children until the parent times out可能已有人在做 @anth-volk 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
PolicyEngine/policyengine-sim-api#794 ·
维护者通常 1 天内回复
-
Stage 12 coordinator can outlive its timeout while waiting and leaves workers running可能已有人在做 @anth-volk 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 20/100
PolicyEngine/policyengine-sim-api#792 ·
维护者通常 1 天内回复
-
Stage 12 failure records keep only the exception class name可能已有人在做 @anth-volk 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
PolicyEngine/policyengine-sim-api#790 ·
维护者通常 1 天内回复
查看 PolicyEngine/policyengine-sim-api 的全部 Issue
相似的 Issue
-
documentation pkg: sphinx-needs
难度 1/5 1 小时以内 新手友好度 82/100
useblocks/sphinx-needs#2255 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 60/100
home-assistant/core#186538 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
btclib-org/btclib-secp256k1#1181 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
pyrite-wiki/pyrite#917 ·
维护者通常 1 天内回复