Repository navigation
Conversation
These tests fail on main (8 failed, 80 passed across the four files):
- the ACS local release's population targets label a state with its
postal code ("ME") where the ledger targets use the Census name
("Maine"), and label at-large districts differently from the IRS SOI
district rows for the same id;
- the IRS SOI district rows translated to the 119th Congress plan are
not labelled with the Census Bureau's district names, which
Chronicle's ACS district facts carry for the same ids;
- microcosm.calibrate.geography_constants has no US state FIPS-to-name
table;
- a US target registry accepts a geography id with two labels, and a
registry for another country does not report one;
- the ACS local materialize stage reads the staging frame before it
checks the admin and population target labels together.
Refs #1335
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ACS local release labelled each state's Census population target
with its postal code ("ME") where the ledger targets use the state's
Census name ("Maine"), so its calibration diagnostics file gave all 51
states two labels.
Labels:
- Add US_STATE_FIPS_TO_NAME to microcosm.calibrate.geography_constants:
the 51 names the Chronicle state facts declare and the release's ledger
targets carry. The block ladder's US_STATES table derives its P.L.
94-171 directory names from it (the derived table equals the old
literal).
- population_target_specs labels a state with that name and a district
with congressional_district_label, the Census Bureau's district name
("Congressional District 1 (119th Congress), Alabama"). The IRS SOI
district rows translated to the 119th Congress plan use the same
function, which replaces the postal-code labels that disagreed with the
population targets on at-large districts. Chronicle's ACS district
facts carry these names for the same ids.
Check:
- TargetRegistry refuses a US registry in which one geography id has two
labels (GeographyLabelConflictError names the id, the labels and the
first target carrying each) and reports it for other countries
(GeographyLabelConflictWarning), because UK publishers name some
regions, nations and local authorities differently.
- The ACS local materialize stage assembles its admin targets and the
ladder's population targets into one registry before reading the
staging frame, so a conflict stops the build before the engine pass.
- Two test fixtures gave one id two labels and now name ids the way
production facts do: the US fiscal fixtures ("Test geography 0100000US"
and "United States") and the ACS local loss-weights fixture (ids as
labels).
The tests from the previous commit pass unchanged: 88 passed across the
four files.
Fixes #1335
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lean checkpoint written by the materialize stage before this branch
labels a state's population target with its postal code ("ME") next to
ledger targets labelled "Maine". The registry now refuses that
target_registry.json, but --stage calibrate stops with the registry's
GeographyLabelConflictError, which names the labels and not what the
operator should do, although the pull request says the stage tells the
operator to re-run --stage materialize.
The test writes such a checkpoint and expects load_checkpoint_surface to
exit with that remedy. It fails on this branch (1 failed, 4 passed in the
module): GeographyLabelConflictError is raised instead of SystemExit.
Refs #1335
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_checkpoint_surface (the calibrate stage's checkpoint reader) now turns the registry's GeographyLabelConflictError into the tool's usual SystemExit for an unusable checkpoint: it names the registry file, says that checkpoints written before microcosm#1335 give a geography two labels, tells the operator to re-run --stage materialize with the current tool, and keeps the registry's message with the ids and labels. The changelog fragment says the refusal carries that message. The test from the previous commit passes unchanged: 5 passed in test_us_acs_local_geography_labels.py. Refs #1335 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The note on ACS_LOCAL_PER_DISTRICT_METADATA gave the Census district name as the example for both ledger_fact_label and ledger_layout_groupby_value_label. The vintage translation sets only the group value label (and the geography name) to the current district's Census name; it copies the source-plan fact's label unchanged into the translated fact, so ledger_fact_label keeps it. Comment only. Refs #1335 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 #1335
Cause
The US release
populace-us-2024-buildo-acs-local-766b7c7-20261017T030317Z(publicpolicyengine/populace-us,calibration_diagnostics.json, schema 8) gives each of its 51 state geographies two labels.0400000US23is "Maine" on 84 IRS SOI, SNAP and Medicaid targets and "ME" onpop_state_23@2024.population_target_specsintools/build_us_acs_local_release.pylabelled the Census population targets withUS_STATE_FIPS_TO_POSTAL(postal codes), and districts as "ME congressional district 1".geography_constantshad no FIPS-to-name table, and nothing checked that one geography id has one label in a registry.Change 1: one label per geography id
US_STATE_FIPS_TO_NAMEinmicrocosm.calibrate.geography_constants: the 51 Census names, District of Columbia included. No display-name table existed. The block ladder'sUS_STATESheld the names only as P.L. 94-171 directory names ("District_of_Columbia"); it now derives them from the new table, and the derived tuple equals the old literal. Checked against two sources:51aa40f, 228 package YAMLs): each state and the nation have exactly one declared name, equal to these.State population targets use that name.
Congressional districts. No other source in the 766b7c7 release uses
5001900USids; only the 436 population targets do. Two other producers in the repository do:--soi-mode fullandstate_cd), labelled by_congressional_district_label. They disagreed with the population targets on at-large districts: "AK at-large congressional district" against "AK congressional at-large";So I chose the Census Bureau's name for both Microcosm producers: "Congressional District 1 (119th Congress), Alabama", "Congressional District (at Large) (119th Congress), Alaska", and "Delegate District (at Large) (119th Congress), District of Columbia". It comes from one public function,
congressional_district_labelinmicrocosm.build.us_runtime.congressional_district_vintage. It spells the state the way the state geography does, and a feed that adds the Census district facts will agree with it.Docs.
docs/shared-constants.mddocuments the table and the district function.docs/calibration-target-hierarchy.mdgets a short "One label per geography" section.Not changed.
_geography_fallback_labelinledger_targets.pystill reads only the UK catalog._validate_chronicle_hierarchy_labelsrequires labels owned by Chronicle rather than built from identifiers, and the US facts all carry names. Medicaid's Rhode Island substitution keeps its reviewedstate_name, which equals the table.Change 2: a check that fails early
Where.
TargetRegistry.__init__(microcosm.calibrate.registry). Every assembly site therefore runs it: US, UK, NZ, AM, BE and test registries, plusselect()andfrom_json. It runs where targets are assembled into a registry, before calibration.geography_label_conflicts(specs)returns{id: {label: first target}}.Scope. A
usregistry raisesGeographyLabelConflictError(aValueError). The message names the id, every label and the first target carrying each, for the first five ids plus a count of the rest. Every other country's registry emits aGeographyLabelConflictWarning. The list of refusing countries isGEOGRAPHY_LABEL_REFUSING_COUNTRIES.Why UK only reports. UK publishers name one code differently, and those names reach the ledger labels. In Chronicle's UK packages:
The UK releases are private, so I could not check them. Refusing would stop UK builds on names nobody has reconciled yet. Choosing one label per UK code (for example from
UK_GEOGRAPHY_ID_TO_LABELandlocal_authority_names.json) is follow-up work; the warning names every case.Earlier refusal in the ACS local build. Its admin targets and population targets first share a registry in
write_lean_checkpoint, after the engine pass over every staged household.do_materializenow reads the ladder and assembles both into one registry (require_one_label_per_geography) right after the admin compile, before it reads the staging frame.population_target_nameintools/us_acs_local_cd_surface.pygives both paths the same target names.Old checkpoints. A lean checkpoint written before this change, with two labels for one US id, is refused when
--stage calibratereloads it. The message tells the operator what to change; re-run--stage materialize.Sweep before refusing
.json/.jsonl/.ndjsonfiles were scanned. None stores a calibration hierarchy. Two carry source-fact geography names (5,432 records), with no id named two ways.TargetRegistryconstruction in the 74 engine-free test modules that assemble registries with hierarchies. That is about 10% of the test files, not the full suite.Before the fix: 7,088 constructions (us 3,643; uk 1,006; nz 323; am 8; be 5; test country 2,103), 6,142 of them with labelled specs, in 38 modules. Conflicts appeared only in US fixtures: 131 constructions in 24 tests in two modules.
test_us_fiscal_targets.py: the fixture facts name the nation "Test geography 0100000US" in some builders and "United States" in others.test_us_acs_local_target_loss_weights.py: admin targets labelled with their ids.Both fixtures now name ids the way production facts do, through the shared table and function.
After the fix, with refusal off in the plugin: 7,113 constructions and no conflicts other than the three my new tests create on purpose.
No engine test (
engine_contract,engine_scenario,engine_workflow,engine/uk) compiles a labelled registry.populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z: all 5,694 targets are accepted as published (52 ids).irs_soi.ty2023.congressional_district_2022.all_returnsat5001700US.irs_soi/county_2022truncates names to 20 characters ("Aleutians East Borou"), whilecensus/pep_county_2024has "Aleutians East Borough". Neither package is in the pinned feed's scope, and no US registry compiles county rows today. A feed update that adds both would not be refused, because no US compile path accepts county facts (see Review fixes); a change that starts compiling county targets from both would need one name per county first.Red and green by commit
bf12d2d8adds the tests. Onmain, the four test files give 8 failed, 80 passed, each failure for its stated reason:assert 'ME' == 'Maine': state population label;assert {'ME', 'Maine'} == {'Maine'}: population and ledger labels for one state;AssertionError: the staging frame was read before the geography labels were checked;DID NOT RAISE <class 'ValueError'>: US registry with two labels;DID NOT WARN: UK registry with two labels;AttributeError: ... no attribute 'US_STATE_FIPS_TO_NAME';assert 'CA congressional district 1' == 'Congressional District 1 (119th Congress), California'.afc64901adds the fix and leaves those tests unchanged: 88 passed.test_us_acs_local_target_loss_weights.py(8). The engine-free modules that import the changed fixture helper also ran:test_us_fiscal_targets.py,test_us_eitc_decomposition_uprating.pyandtest_us_soi_congressional_district_vintage.py, all passing apart from 5 skips that need the private pinned feed.ruff checkandruff format --checkpass on the 13 changed Python files, andtools/ci_test_plan.py verifyis ok. CI runs the rest.Not in scope: dimension value labels
In
populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z, dimensionus:statutes/26/62#adjusted_gross_incomevalueunder_1is "No adjusted gross income" on 106 targets (Historic Table 2 state AGI rows). It is "No adjusted gross income and deficit" on 2 targets (irs_soi.ty2024.filing_season_week47.eitc_by_agi.under_1.*).irs_soi/filing_season_week47_2024package. Its row label forunder_1is the publication's row header, "No adjusted gross income and deficit", although that package's own value map says "No adjusted gross income", as Historic Table 2, Table 1.1 and Table 2.5 do._inherited_dimensionsinledger_targets.pytakes the value label from the fact'slayout.groupby_value_label._validate_chronicle_hierarchy_labelscompares labels only among one target's member facts, never across a registry.adjusted_gross_income/allis "All returns" (47) and "All returns, total" (53).age/85_plusis "Age 85 plus" (51, Census PEP state) and "Age 85 and over" (1, Census PEP national).Overlap with open PRs
packages/microcosm-build/tests/engine_free/us/test_us_acs_local_target_loss_weights.pyis also changed by #1298 (stack #1296 → #1297). #1298 adds an import and a test; this PR changes the fixture's_hierarchylabel and adds two imports. A three-way merge of the file against #1298's head has no conflicts. No other file overlaps #1296, #1297 or #1298, and this PR does not touchdocs/agent-guide.md, which all three change.uv.lockis unchanged. No workflow, Docker, Terraform or environment-variable change.Review fixes
A first review checked the state names against the release file (all 51 equal), the district names against the Census Bureau's own ACS 2024 names stored in Chronicle (all 436 districts equal; DC compared with the Census row
5001900US1198), the red and green counts above, and the overlap with #1296, #1297 and #1298. It found one defect and corrected three statements.d1ef7474addstest_calibrate_refuses_an_earlier_checkpoint_and_names_the_remedytotest_us_acs_local_geography_labels.py. A checkpoint written by the earlier materialize stage ("ME" beside "Maine") made--stage calibratestop with the registry'sGeographyLabelConflictError, which names the labels but not the remedy. Red: 1 failed, 4 passed in the module:GeographyLabelConflictErrorwas raised instead ofSystemExit.fe235980:load_checkpoint_surfaceturns that error into the tool's usualSystemExitfor an unusable checkpoint. The message names the registry file, says that checkpoints written before Give each US geography one label across target sources #1335 give a geography two labels, says to re-run--stage materializewith the current tool, and keeps the ids and labels. The changelog fragment says so. The test is unchanged. Green: 5 passed.bb3f7c88(comment only): the note onACS_LOCAL_PER_DISTRICT_METADATAgave the Census district name as the example for bothledger_fact_labelandledger_layout_groupby_value_label. The vintage translation sets only the group value label and the geography name; it copies the source fact's label unchanged.Corrections to this description:
_soi_reference_from_factand_population_age_reference_from_facttake only thecountry,stateandcongressional_districtlevels, and_direct_reference_from_factonlystateandcountry. The ACS local admin surface uses the same compiler. The two county names would conflict only in a change that starts compiling county targets from both packages, and that change should choose one name per county first.98(5001900US1198). Microcosm's crosswalk and PUMA population file use00(5001900US1100). So those facts agree with the labels here for the 435 seats, but for DC they would add a second id with the same label. The registry check does not object, because it checks one label per id. This predates the PR.--stage materializeis true fromfe235980.Locally, only the changed test file ran (5 passed), plus
ruff check .,ruff format --checkon the changed Python files, andtools/ci_test_plan.py verify(ok).uv.lockand the workflows are unchanged.🤖 Generated with Claude Code