Repository navigation
Carry each hierarchy dimension value's source order, so FSA debt-size bands sort naturally - #1598
Conversation
The calibration dashboard lists FSA's nine debt-size bands alphabetically
("100K to 200K", "10K to 20K", "200K+", ...) because HierarchyDimension
carries no value order and the dashboard falls back to sorting labels
(Max Ghenis on #1357; PolicyEngine/calibration-diagnostics#276).
- HierarchyDimension gains an optional value_rank, the value's position
from 0 in the order its source lists the dimension's values.
_inherited_dimensions takes it from layout.groupby_ordinal for the
group-by dimension when every selected fact gives the same non-negative
integer; derived facts and other dimensions give none, and a Medicaid
enrollment substitution drops the template state's rank.
- to_dict leaves out an absent rank, so TargetSpec.to_dict, the UK local
surface and the diagnostics rows encode a rank-less dimension as before
and registries written before this keep their version.
- Diagnostics schema 8 dimensions carry value_rank; schema 9 catalog
values carry rank when no value of the dimension is ranked two ways, and
expansion gives it back to the rows. Row references stay {id, value_id}.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Probe on the pinned US feed: the USDA SNAP state tables give several states one row number, so ranks shown together in one category would not order them. Also re-pin the national_state surface version the ranks move (3aa2a0830e7d -> c698e70d33ce) and give the ledger rank tests' facts their group-by dimension label. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…s frame in one concat The USDA SNAP state tables number the states within each region, so seven states share row 0; the changelog and the hierarchy doc said only that the tables list states by region. The schema 9 export test now adds the FSA measures to the household table with one concat instead of one column at a time. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… Schemas On this branch's merge of main (c9e2211): - The schema 8 and 9 diagnostics JSON Schemas gain value_rank and rank (tools/generate_calibration_diagnostics_json_schema.py). - The US F0 spec pins. us_runtime/medicaid_take_up.py is an attested seed kernel module, so its edit moves the seed map, the seed protocol and the US bundle's spec_sha256 (3dabec5c to ab3f3aa9), and the loader's golden vector with them (repin_us_spec_engine_contracts.py, generate_us_bundle_from_constants.py, spec_engine_coverage.py, in the order the repinner documents; all three pass --check afterwards). - calibrate.adam@1's H1 parity pin. The kernel hashes microcosm.calibrate sources this branch edits, so its implementation hash and node key move; direct.csv does not. tools/graph_parity_repin.py refuses off the one pinned platform (arm64/darwin/py3.14), and this ran on x86_64/linux. The case is numeric "bitwise", so its key carries no platform and test_h1_kernel_parity asserts the authoring platform's key and bytes everywhere. The tool's repin() therefore ran unchanged with only the fingerprint it uses to choose its own pin entry set to the authoring platform: the direct call's bytes, the dependency versions, the old pin against its recorded hash and the executed key against the derived one were all checked on Linux. The pinned-feed national_state surface stays at c698e70d33ce after the merge (6,102 of 33,250 targets); compiled with the rank lookup turned off it is main's 3aa2a0830e7d. Run on Modal (Linux, Python 3.14.2, uv.lock with the US engine). Afterwards on the re-pinned tree: ruff check; the spec-engine, calibrate, diagnostics, graph parity, ledger, fiscal and FSA target tests (1,656 passed, none skipped, the pinned feed present); the engine-contract coverage tool and inventory tests (9 passed); the engine-workflow multispine pool tool tests (31 passed). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MaxGhenis
left a comment
There was a problem hiding this comment.
Thanks, David. The FSA debt-size bands come out in source order, and the export test fails if the ranks drop out at any step on the way to the published file. I found nothing blocking, and most of the five small points come down to wording.
-
The docs tell readers to sort a dimension's values by rank, but ranks order values only within one category.
catalogs.py:254-256checks for ties within each category, and that fits the calibration dashboard, which builds facets only after someone picks a category.schema.py:861("Readers sort by it") anddocs/calibration-target-hierarchy.md:210leave out that limit. On the pinned US feed,agespans the Census population and SSI recipient tables, with 21 values on 18 ranks, so sorting the catalog's list puts "Age 0 to 4" next to "SSI federal payment recipients under 18". I'd say in both places that ranks order values within one category. -
The Medicaid substitution's comment gives the wrong reason, and no test covers the line.
medicaid_take_up.py:845-846says the substituted state "has no row there", but the pinned feed has Rhode Island's December 2024total_medicaid_enrollmentrow in that same CMS table (value 0,groupby_ordinal39). Dropping the rank still makes sense, since the template's rank belongs to another state.test_substituted_spec_carries_its_own_state_in_a_labelled_hierarchybuilds its template with novalue_rank, so every test still passes if someone deletesvalue_rank=None. Giving that template a rank would cover the line. -
UK targets gain ranks too.
ledger_targets.py:1681runs for every country, anduk_runtime/graph_targets.py:148stores the hierarchy'sto_dict(), so the next UK build moves UK registry versions, local-surface records and diagnostics. No committed UK pin breaks, and engine-uk passes, but the description and changelog name only the US pins that move. -
Older readers fail on the new files.
registry.py:60keeps the registry at format 3, so main's reader accepts a ranked registry and then raises aTypeErroron the unexpectedvalue_rankkeyword (hierarchy.py:161on main). A format bump would give that reader the clear unsupported-revision error. Main's diagnostics models (extra="forbid",schema.py:78) and main's v9 JSON Schema also reject the catalog'srank. Adding the hierarchy bumped the format from 2 to 3, so a bump here would match. Otherwise the changelog could say which readers break. -
Two doc nits. Under the rule "where every value has one", a reader can't order any of
cms_medicaid.state_abbreviation, because the nationalusvalue has no rank while the other 51 do; "unranked values last" would keep the order. Andhierarchy.py:70calls a rank the value's position "in the order the source lists the dimension's values". The rank gives the row's place in the source table, so SSI's under-18 row and the Census ages 0 to 4 row both carry rank 1. The doc's "among the source table's rows" has it right.
I also checked the pins. The parity tool, which I ran unchanged on a Mac, writes the committed pins.json byte for byte. Every moved seed and spec hash traces to medicaid_take_up.py, and stripping the ranks brings the registry and surface versions back to main's.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…edicaid test - Ranks order values within one category, not a dimension's whole list: say so in HierarchyDimensionValueEntry, the catalog module and the hierarchy doc, and tell readers to put unranked values last instead of sorting only where every value has a rank. - A rank is the position of the value's row among its source table's rows. HierarchyDimension (both packages) and the changelog said "in the order the source lists the dimension's values". - The Medicaid substitution drops the template's rank because that rank is the template state's row, not because the substituted state has no row in the CMS table. The labelled template in the substitution test now carries a rank, so the test fails without value_rank=None. - Registry files are format 4; formats 2 and 3 stay readable. A reader from before the field refuses a new file by its revision instead of failing on the unexpected value_rank keyword. - The changelog says that UK targets gain ranks too, and which diagnostics readers refuse the new fields. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…as after the review edits On 081c025, which merges main at d5a9322: - The US F0 spec pins again. The corrected comment in us_runtime/medicaid_take_up.py changes an attested seed kernel module's bytes, so the seed map, the seed protocol, the loader's golden vector and the US bundle's spec_sha256 move (ab3f3aa9 to 98d58365), with the same three tools in the repinner's order; all three pass --check. - The schema 8 and 9 diagnostics JSON Schemas, whose descriptions follow the reworded model docstrings. Not moved: calibrate.adam@1's parity pin (its pin tests pass before any re-pin; the kernel hashes neither hierarchy.py nor registry.py), and the pinned-feed national_state surface, still c698e70d33ce and 3aa2a0830e7d with the rank lookup off. The registry format number is outside the content version. The hierarchy doc now gives the pinned feed's counts for its two examples, read from the compiled registry: age has 21 values on 18 ranks across the Census population and SSI recipient categories, and the CMS Medicaid state dimension ranks 51 of its 52 values. Run on Modal (Linux, Python 3.14.2, uv.lock with the US engine), on the re-pinned tree: ruff check, ruff format --check and ci_test_plan verify; the spec-engine, calibrate, diagnostics, graph parity, ledger, fiscal, Medicaid take-up and FSA target tests with the pinned feed present (2,155 passed, none skipped); the engine-contract coverage tool and inventory tests (9 passed); the engine-workflow multispine pool tool tests (31 passed). With value_rank=None deleted from the substitution, the substitution test fails ("assert 4 is None"). The previous re-pin commit's "1,656 passed" undercounted that run, which passed 2,153. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thanks, Max. All five are in
Pins. The corrected comment in One correction to the description: it said 1,656 tests passed in the first Modal run. That was my miscount of 2,153; this round's run passed 2,155. |
MaxGhenis
left a comment
There was a problem hiding this comment.
Thanks, David. 081c025 covers all five points, and the PR can merge.
The Medicaid substitution test now fails if the clone keeps the template state's rank, and the new format 4 test fails if the writer goes back to format 3. I planted each change to check. A reader built from main before this PR now refuses a format 4 registry by its revision, where it used to raise a TypeError. No need for a schema 10: the changelog names the diagnostics readers that refuse the new fields.
The docs' rule that ranks order values within one category holds on the pinned US feed. Two dimensions that the catalog ranks draw more than one value from several tables in one category: age, across the national and state population tables, and geography, across the state EITC tables. Both take their ranks from one row order that all their tables share, so neither interleaves. The re-pinned seed protocol also passes main's new test_legacy_v1_seed_protocol_equals_the_pinned_inventory_digest, which reads this PR's inventory_coverage.py. Main hasn't touched the PR's files since d5a9322ef.
|
My review at e0bcd3d raised five small points, and 081c025 fixes all five. c4981f1 merges main at d5a9322, and e7055a9 re-pins the US spec identity. An Opus 5.5 check of the delta found nothing open, and a mutant against the Medicaid substitution test or the new format 4 test fails only that test. In run 43474383601, all 12 checks passed on e7055a9 merged with main at d5a9322. Main has since gained #1605, #1590, #1047 and #1592, none of which touch this PR's files. GitHub reads the PR as mergeable, so it merges at e7055a9 as one squashed commit. |
…and #1545 Main (68bbff7) gained #1592 (the delete-old-layout step), #1598 (hierarchy dimension value order) and #1545 (SCF education-debt fit tables) since the last merge (a60b164). #1598 changes medicaid_take_up, an attested kernel module, and regenerated the shared pins, so four pin files conflict. Each is resolved per hunk: main's text for every conflicted hunk, this branch's microcosm#767 comment sentences kept after main's, and the values then written by the tools. - docs/evidence/spec-engine/us-f0-coverage.json (five hunks): main's text, then rewritten by tools/spec_engine_coverage.py. - spec_engine/inventory_coverage.py (one hunk): main's hierarchy-rank comment, then this branch's microcosm#767 comment, then the three values. - engine_free/shared/test_spec_engine_loader.py (one hunk): the golden vector; this branch has no comment of its own there. - engine_workflow/us/test_us_multispine_pool_tool.py (one hunk): main's comment, then this branch's microcosm#767 comment, then the value. Pins, written by tools/repin_us_spec_engine_contracts.py (twice, with tools/spec_engine_coverage.py between and after), then ruff format for the quotes the repinner writes: - seed_map 635d852b76cc727616d9c6982f6f391165c9ba66d47dabe66aa3ef8db423a69a - seed_protocol 540e44ea16ed38d923e9a1d5163a3f58a358277f9830c7960ee2857cf2871d7a - US spec_sha256 b296b865b2bdd5434f605b4bceedc44abbb1a828db523c4e487f67b97352dacd - loader golden vector 5ddc96347093d4b0f1732e9ecd02e7f6d78fdbf9cd5561fb9d65e8193f6c0271 - source_manifest stays this branch's e9a70a60c3db9250066ee607d5e1fb07cd9d6a54424ab9eb9405f5e65b5a59b8; main did not move it. The calibrate parity pin is main's: this branch does not change microcosm-calibrate. Both pin tools pass with --check, and so do the repinner's --legacy-only --check and tools/ci_test_plan.py verify. Two more files change on both sides and merge without conflict. tools/build_us_fiscal_refresh_release.py: this branch's humanitarian stock specs, its time_period on the composition gate and its final gate at delivered weights, and #1545's fit tables under the release directory and the scf_education_debt argument to _build_manifests, sit on disjoint lines of _main; the merged body is the base plus exactly both sets of lines. test_us_fiscal_refresh_builder.py: no test changes on both sides. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained #1600, #1605, #1590, #1047, #1592, #1598 and #1545 since the 1e88319 this branch last merged. #1598 changed microcosm-calibrate (hierarchy value ranks) and an attested kernel module and regenerated the shared pins, so the five pin files conflicted. Each conflict hunk takes main's text, with this branch's #1096 comment sentence kept after main's, and the tools then wrote the values for the merged tree: - docs/evidence/spec-engine/us-f0-coverage.json: main's five hunks, then rewritten by tools/spec_engine_coverage.py (two map, two protocol, two implementation and two spec digests; 42394/42394 fields, 41/41 checks). - spec_engine/inventory_coverage.py: main's hunk and its hierarchy comment, plus the #1096 sentence; tools/repin_us_spec_engine_contracts.py wrote seed_map d29d95be and seed_protocol f3738669 (main: 0c19b903, 15e6cad1). - test_spec_engine_loader.py: main's hunk plus the #1096 comment line; the repinner wrote the golden 0b417bfc (main: 99f9b82e). - test_us_multispine_pool_tool.py: main's hunk plus the #1096 comment line; the repinner wrote spec_sha256 c79a1d3f (main: 98d58365). - parity/kernels/calibrate/pins.json: main's line, then tools/graph_parity_repin.py calibrate wrote implementation_hash 20180a24 and node_key 86ae2227 (main: 0c669ad2, fbab5f42). direct.csv, graph.json and inputs.csv did not move, so the default path's bytes are main's. The repinner and the coverage tool ran twice each, then both passed --check. ruff format changed only the quotes the repinner writes. tools/build_us_acs_local_release.py and its test merged without conflict. Main's #696 and this branch both changed do_package and _parse_args, in separate statements: main swapped the refresh recipe's staging value and added --block-ladder; this branch renamed one calibration key and reworded the --mass-parametrization help. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained #1600, #1605, #1590, #1047 (US household location v1, the opt-in block_v1 rule), #1592, #1598 and #1545 since the 1e88319 this branch last merged. Seven files conflicted: - us_runtime/acs_multispine.py: the base_pool import block only. Union: main's ACS_POOL_BLOCK_LOCATION_METADATA_KEY and this branch's acs_pool_local_jurisdiction_rungs. The function body merged cleanly. - us_runtime/base_pool.py: __all__ only. Union of main's two new names and this branch's one. - tests/engine_free/us/test_us_spine_blindness.py: the pool tool's runtime-graph count. Main counted 83 (81 plus block_location.py and cps_source_geography.py), this branch 82 (81 plus local_jurisdictions.py). The test's own graph helper reaches 84 on the merged tree, with all three modules in it and none unclassified; the comment keeps both explanations. - spec_engine/inventory_coverage.py, tests/engine_free/shared/ test_spec_engine_loader.py, tests/engine_workflow/us/ test_us_multispine_pool_tool.py and docs/evidence/spec-engine/ us-f0-coverage.json: digests only. Each conflicted hunk takes main's value and main's comment, and keeps this branch's comment sentences beside it. The values are stale until the pin tools rewrite them in a later commit. Functions both sides changed and git merged without conflict: build_optional_acs_multispine, with_optional_acs_spine, the fiscal refresh builder's _main and the pool tool's _validate_stacked_geography_assignment_receipt. The last two are independent edits. The first two are not: under block_v1 the merged pool still picks the flag rungs from the PUMA ladder alone, so it removes every flag from a block-located pool, and the receipt can name rungs the pool did not use. A later commit fixes that. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main gained #1605, #1590, #1047, #1592, #1598, #1545 and #1612 since this branch's last merge. Git merged all of them without a conflict. #1592's delete-old-layout step calls publishes_to_build_folder to tell a folder named by a release from a folder named by one build's tag. With this branch, it no longer counts a UK local-area name the registry does not name as such a release. The next commit pins what the step reports for such a folder. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main (52aea14) moved the same pins this branch moves: #1598 changes medicaid_take_up, an attested module. The five pin files conflicted. Both sides' reason comments are kept, and every value is recomputed on the merged tree: - the documented sequence (repin --legacy-only, the bundle generator, repin, spec_engine_coverage, repin again), with all three --check modes passing and 42395/42395 fields and 41/41 inventory checks; - tools/graph_parity_repin.py calibrate, with the case's direct output unchanged. Merged values, against main's: - seed_protocol 15e6cad1… -> a696ad74…, seed_map 0c19b903… -> 270cf649… - US spec_sha256 98d58365… -> bd526d8c… (pool tool pin) - loader golden 99f9b82e… -> 1ff3b42c… - calibrate parity implementation_hash 0c669ad2… -> 018974ad… The release tool and test_spec_engine_seeds.py (#1047) merged without conflict. The venv is resynced for main's microcosm-emitter-interface 0.15.0. Tests on the merged tree: seeds 13, loader 10, field usage 14, engine-free spec bundle 4, graph parity pins 11, keyed draws 64, recertification parity 4, post-export scoring 48, batched target materialization 37, the builder's signed-component tests 2, head-to-head scorer 54, coverage tool 7, engine-contract spec bundle 22, the pool tool's pin test 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Each calibration hierarchy dimension value now carries the position its source gives it, so a reader can list a dimension's values in the source's order.
HierarchyDimensiongains an optionalvalue_rank: the position, from 0, of the value's row among its source table's rows._inherited_dimensionstakes it from Chronicle'slayout.groupby_ordinalfor the group-by dimension, when every selected fact gives the same non-negative integer. Other dimensions, facts that disagree and Microcosm-derived facts get no rank. A Medicaid enrollment substitution drops the template state's rank.value_rank. In schema 9, each catalog value carriesrank. A dimension gets no ranks when its rows rank one value two ways, or when one category gives two of its values the same rank: the IRS SOI tables place50k_to_75kat rows 5, 9 and 10, and the USDA SNAP state tables number the states within each region. Ranks order values within one category, with unranked values last; values from different categories can share a rank.Why
The calibration dashboard lists Federal Student Aid's nine debt-size bands alphabetically ("100K to 200K", "10K to 20K", "200K+", …) instead of from "Less than 5K" to "200K+". PolicyEngine/calibration-diagnostics#276 found this while checking the student debt pilot's target family. Its first follow-up names the cause: Microcosm drops each fact's
layout.groupby_ordinal, so the dashboard has nothing to sort by. This PR carries the order through to the diagnostics file. The dashboard's hierarchy reader still has to read it, in that repository.Pins this moves
us_runtime/medicaid_take_up.pyis an attested seed-kernel module, so its edit moves the seed map, the seed protocol, the loader's golden vector and the US bundle'sspec_sha256(3dabec5c…on main to98d58365…). Re-pinned withrepin_us_spec_engine_contracts.py,generate_us_bundle_from_constants.pyandspec_engine_coverage.py, in the order the repinner documents. No draw, RNG rule or QRF target changes.calibrate.adam@1parity pin. The kernel hashesmicrocosm.calibratesources this PR edits, so its implementation hash and node key move.direct.csvis unchanged.generate_calibration_diagnostics_json_schema.py.national_statesurface version, which hashes the hierarchy:3aa2a0830e7dtoc698e70d33ce, still 6,102 of 33,250 targets. Compiled with the rank lookup turned off, it is3aa2a0830e7dagain. CI has no feed and skips that test.to_dict()) and diagnostics. No committed UK pin moves.For review: how the parity pin was re-recorded
tools/graph_parity_repin.py calibraterefuses on a platform that carries no pin, and the calibrate case pins onlyarm64/darwin/py3.14. The re-pin ran onx86_64/linux. The case is"numeric": "bitwise", so its node key carries no platform, andtest_h1_kernel_parityasserts the authoring platform's key and bytes on every platform. So the tool's ownrepin()ran on Linux with one substitution: the fingerprint it uses to pick "this platform's" entry was set toarm64/darwin/py3.14. Its checks ran unchanged: the direct call's bytes againstdirect.csv, the dependency versions, the old pin against its recorded hash, and the executed key against the derived one. In review, the tool run unchanged on a Mac wrote the committedpins.jsonbyte for byte. The later review edits leave this pin where it was.Older readers
value_rankkeyword.value_rankandrankare optional additions, as schema 8's earlier optional fields were. A reader that validates with an earliermicrocosm-diagnostics, whose models forbid unknown fields, or with an earlier copy of the JSON Schemas refuses a file that carries either field. A reader that ignores unknown fields reads it unchanged.Tests
New tests cover the field and its validation, the registry round trip, version and format, the compile from
groupby_ordinal, the catalog rules, the Medicaid substitution's dropped rank, and the FSA family end to end (test_compiled_bands_carry_fsa_row_order_as_value_rank,test_exported_diagnostics_list_fsa_values_in_source_order).Run on Modal (Linux, Python 3.14.2,
uv.lockwith the US engine), on081c025f0(which merges main atd5a9322ef) after the re-pin:ruff check .,ruff format --checkon the changed Python files, andtools/ci_test_plan.py verify: pass.generate_us_bundle_from_constants.py --check,spec_engine_coverage.py --checkandrepin_us_spec_engine_contracts.py --check: pass.engine_contract/uscoverage tool and inventory tests: 9 passed.engine_workflow/us/test_us_multispine_pool_tool.py: 31 passed.value_rank=Nonedeleted from the Medicaid substitution,test_substituted_spec_carries_its_own_state_in_a_labelled_hierarchyfails (assert 4 is None).One doc sentence was tightened after those runs. The full suites are left to CI.
🤖 Generated with Claude Code