Repository navigation
Shared calibration machinery for local areas: weight rules, loss caps, area support, weight bound and a spine diagnostic - #1735
Conversation
microcosm.calibrate.target_loss_rules computes a target's loss weight and loss cap from its level, family, value basis and value. A country says what each row is (TargetLossRows) and declares the rule by name with its parameters (TargetWeightRule). The rules are uniform, level_equal, level_family_equal (with an optional count power) and sqrt_value_concept_budget; any rule may carry family multipliers. target_loss_caps gives one number by default and a row vector when a level or a family declares its own cap. single_cap_equivalent gives the one-cap loss that equals the loss with a cap for each row, so a declared vector needs no change to the solver, whose cap stays one number. The module is new and nothing reads it yet, so no build output changes. Part of microcosm#1729 (items 2 and 3). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…S rules us_runtime.target_loss_weights keeps what a US row is (the row mappings) and calls the shared rule for the arithmetic. US_FISCAL_TARGET_WEIGHT_RULE and US_ACS_LOCAL_TARGET_WEIGHT_RULES declare the rules as data. The weights are the same bytes as before: the tests hold the shared rule to a verbatim copy of the formula as it stood at ac7ab99. The ACS local tool takes --target-weight-rule. Its default is the formula every build has used, and the default solver stamp is unchanged, so a resume across this commit compares equal. level_family_equal_sqrt_count gives each geography level one equal share of the loss; it changes the weights, so a build must ask for it, and the stamp then records the rule. Part of microcosm#1729 (item 2). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
uk_runtime.target_weight_declarations states each name of the UK local vocabulary as one shared rule with its parameters, and how a UK row maps to a level. uk_shared_rule_loss_weights computes a rule's vector through the shared code. The UK solve does not read this module. uk_runtime.target_weights is part of the UK graph's code identity (uk.full.problem@1 and the rotated holdout hash its bytes), so this commit leaves it and local_doctrine untouched. The test holds the shared vector equal to uk_rule_loss_weights bit for bit under all six rules, on synthetic rows, so a later switch changes which code computes the vector and not the vector. Part of microcosm#1729 (item 2). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
--county-target-loss-cap-scope county_rows gives the county rows the county cap and leaves the state and district rows at --target-loss-cap. The caps are declared by level (target_loss_caps), and the solver gets the one-cap loss that equals them (single_cap_equivalent): the same loss value, the same contribution of each row and the same gradient, with no change to the solver. The default scope is run: the county cap applies to every row of a county build, the profile and the solver stamp are as before, and calibrate gets the same keywords. The scope is part of the stamp, so a resume refuses weights of the other scope. The weight ratio is a bound on records, so it stays one number for the run under both scopes. Under county_rows the summary's target_loss_cap is the solver's equivalent cap, which is the largest value the loss can take, so the finalize check "final loss below the cap" keeps its meaning; target_loss_caps records the declared row caps. Part of microcosm#1729 (item 3). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
microcosm.build.area_support holds the Kish ESS of each area (effective_sample_size_by_group, moved from the US district surface tool with the same arithmetic), the long-form support table built from a weight vector (area_support_table), and one gate whose floors are each optional: rows, distinct sources, an absolute ESS floor, and a floor relative to the area's starting ESS, the rule microcosm#1078 adopted. area_support_floor_table gives the same verdict area by area. With the three absolute floors and no relative floor the gate calls gates.area_support_gate, so the UK gate and this one cannot disagree. A test holds the general rule equal to that function wherever both apply. gates.py is part of the UK graph's code identity (uk.full-gates@1 hashes its bytes), so this commit does not edit it. The ACS local release's district_ess_collapse_gate keeps its name, its signature and its entry, and now declares its floors to the shared gate. Its entry equals the entry of the code as it stood at ac7ab99 on every generated case. It stays report-only unless the existing --district-ess-gate-blocking is passed, and no floor is added. tools/us_acs_local_cd_surface.py no longer has ess_by_group, and spine_composition reads the shared Kish ESS. Part of microcosm#1729 (item 4). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
microcosm.calibrate.spine_target_shares reports, for each target, the share of its weighted total that each set of rows (spine) carries, against that spine's share of the weight among the records the target is about (its scope: an area, or every record). A target one spine carries almost alone pulls weight onto that spine; excess and lift rank such targets. It reads a constraint matrix, a weight vector and each record's spine. It solves nothing and changes nothing, so it runs at the starting weights or at any calibrated weights, for any pooled build. Carriers count a source household once. minimum_carriers withholds a target that a spine carries with few distinct carriers, for a build under a disclosure rule. tools/spine_target_shares.py runs it without a build, from an ACS local checkpoint directory (design weights, and calibrated weights when saved) or from a saved sparse matrix, weights and spine labels. Part of microcosm#1729 (item 6). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
--l2-anchor and --l2-anchor-weights reach calibrate's l2_anchor and l2_anchor_weights. With the initial anchor the --l2-lambda penalty pulls toward the starting weights, so ESS cannot pass their ESS. uniform pulls toward the mean starting weight. --l2-anchor-weights FILE pulls toward a declared design (one positive weight per checkpoint household), named by --l2-anchor; the starting weights, the weight bound and the mass do not change. The default is initial with no vector: calibrate gets no new keyword and the solver stamp gets no new key, so a resume across this commit compares equal. A non-default anchor is in the stamp, with a digest of the vector, so a resume refuses weights calibrated toward another anchor. The refresh recipe names the anchor and the weight rule when a build asked for them. Part of microcosm#1729 (item 1). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
microcosm.calibrate.weight_bound states one contract for max_weight_ratio (microcosm#493): the bound is against each record's weight on the frame the solve was given. It is never against the warm start, so the batches of an epoch-batched solve do not compound it. A stage whose frame carries an earlier stage's weights bounds against those, so two stages at ratio R admit R ** 2 against the first stage's weights. The bound is relative, so a record that starts heavier gets a larger absolute bound. The tests run the solver and hold it to each statement. weight_bound_reference declares another reference: the mean starting weight, or the mean starting weight of the record's area. weight_bound_report measures any weight vector against a reference: the largest ratio, the records above the bound, the records that start above it, and whether the bounds admit the starting mass. It is report-only. The solver does not enforce a declared reference in this commit. That needs an edit to solve.py, whose bytes are part of the calibrate.adam@1 fingerprint that every UK solve node embeds, so it waits for a decision. docs/calibration-local-area-machinery.md is the reference page for all the shared pieces of microcosm#1729 and what each country declares. Part of microcosm#1729 (item 5). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main moved by 46 commits (the SPI forest release and the ACS donor patch). The merge is clean. It comes before the solver edit so that the re-pin of the calibrate kernel is computed on the current main. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
calibrate and solve_constraint_system take max_weight_reference: one positive weight for each record. The bound is then max_weight_ratio times that reference instead of max_weight_ratio times the record's own starting weight, so a record that starts heavier than the others gets no larger a bound for it. The frame's weights still set the starting point, the mass, the L2 anchor and the diagnostics. A record may start above its bound. The solve then starts from the starting weights held to the bound and, under mass conservation, brought back to the input total below it, the projection a warm start already gets. Under mass conservation the bounds must admit the total, or the solve refuses with a named error. The option needs max_weight_ratio and the Adam solve without L0 gates. A solve under a reference records options["weight_bound"]; no other solve has that key. Without a reference every expression is the historical one. The whole calibrate test package passes, including the tests that hold the default path to the pre-change optimizer bytes, and a reference equal to the starting weights returns the same bytes as no reference. The four pinned helpers are not edited. solve.py is in the calibrate.adam@1 fingerprint, so its parity pin is re-recorded with tools/graph_parity_repin.py calibrate. The tool writes only when the kernel's direct output bytes are unchanged, and they are. Every UK solve node embeds this fingerprint, so those nodes re-key on the next run (María's go, 25 Nov 2026). Part of microcosm#1729 (item 5), microcosm#493. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
--weight-bound-reference says what --max-weight-ratio multiplies for each household. own (default) is its own starting weight, as every solve has used. mean, state_mean and district_mean are one shared weight: the mean starting weight overall, or of the household's state or district. The tool builds the vector with the shared weight_bound_reference and passes it to the solver as max_weight_reference. In the pooled file a donor row starts about 27 times heavier than an ACS row, so under own its absolute bound is about 27 times higher. Under a shared reference every household of a group has one bound. A household that starts above it is pulled down to it before the solve, which moves starting mass off the heavy rows, so the option changes the weights. The default adds no keyword to calibrate and no key to the solver stamp. A non-default reference is in the stamp, so a resume refuses weights solved under another bound, and the summary records the solver's weight_bound block. Bounds that cannot hold the conserved total stop the stage before the solve. Part of microcosm#1729 (item 5). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The UK local and national builds now take every loss weight from microcosm.calibrate.target_loss_rules, as the US does. - uk_runtime.target_weights says what a UK row is (its weighting grain, its family, its value basis) and declares each local rule name as a shared rule. The doctrine's nation_grain_family_equal_sqrt_count is level_family_equal with a count power of 0.5. uk_target_loss_weights_for_rows calls the shared rule. - uk_runtime.national_doctrine declares family_equal as the shared level_equal with each family as one level. The local grain_equal rule calls it, so it moves too. - The declarations that commit b4372d2 kept in a file of their own are now in these two modules, and that file is removed. The vectors are the same, bit for bit. The tests hold the row-metadata rules, the grain rule and family_equal to verbatim copies of the UK arithmetic as it stood at fccd9a6, on synthetic rows, and the refusals keep their wording. The shared module now decides UK loss weights, so the kernels that bind them hash it: uk.full.problem@1 (its loss-weight hash), the two national kernels and the rotated holdout. An edit to a shared rule re-keys them. The closure test records one new edge, graph_targets -> calibrate.target_loss_rules, for the target, selection and measures kernels: graph_targets imports the module only to build the problem's hash, like the three existing edges of that kind. These UK nodes re-key on the next run, with the same outputs: target_compilation, target_selection, measures and problem of the full graph, the national targets and problem, and the rotated holdout (María's go, 25 Nov 2026). Part of microcosm#1729 (item 2). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gates.area_support_gate is the one area support gate. Each floor is now optional, and it gains minimum_effective_sample_size_ratio: an area fails when its ESS is below that share of its starting ESS, the rule microcosm#1078 adopted. area_support_shortfalls and area_support_below_floor take the same floors. The general rule that commit b5254f7 kept in microcosm.build.area_support moves here, and that module keeps the measurement: the Kish ESS of each area, the support table and the per-floor flags. It re-exports the gate, so there is one function. The UK local build declares the three absolute floors, and its result does not change. The tests hold the gate, the per-area flag and the wording to a verbatim copy of the code as it stood at fccd9a6 on 300 generated tables, reviewed exclusions included. uk/gates.json is not edited, so no gate digest or gate replay moves. The US district gate keeps its entry and stays report-only by default. gates.py is in the hash of uk.full-gates@1 and of the transport gate kernel, so those nodes re-key. With this commit and 657ae0c, every kernel defined in uk_runtime/graph_targets.py, graph_national.py and graph_terminal.py re-keys, because each hashes its own module: the full graph's target compilation, selection, measures and problem; the national targets, problem, gates and readback; the rotated holdout, the full gates and their preflight, and the three export kernels. The outputs are the same (María's go, 25 Nov 2026). The reference page lists them. Part of microcosm#1729 (item 4). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
vahid-ahmadi
left a comment
There was a problem hiding this comment.
Reviewed at d4f5cd983. The design is sound: shared mechanics, each country declaring its choices as data, and defaults that leave outputs unchanged. The equivalence tests against verbatim copies of the old code are a good way to prove that. There's one CI failure to sort out first, and a few smaller points.
1. engine-us fails, and this PR causes it. In run 45659006236, both engine-us jobs fail on test_spec_engine_coverage_tool.py::test_us_coverage_is_exact_complete_and_honest:
seed_protocol_and_owner_map_digests_exact: ['seed protocol content digest differs', 'compiled seed map digest differs']
Main at this PR's merge base (fccd9a68b) passes engine-us, so the change comes from this branch. Some file this PR edits feeds the US seed protocol hash: the ACS local tool or the solver are the likely ones. Before re-recording EXPECTED_HASHES in spec_engine/inventory_coverage.py, it's worth confirming which change moved it. If only the source bytes changed, re-record the hash and say so in the body. If the compiled seed map itself changed, a default build may draw different random numbers, which would contradict "no default changes an output". The body's "CI did not run: nothing is pushed" is also out of date now.
2. The row-cap identity holds. I checked the algebra against the loss in _target_loss_attribution.py: each row contributes weight_share × min(|e|/s, cap), which is linear in the capped term. Choosing cap0 = Σ(w·c)/Σw keeps Σw' = Σw, so the shares are unchanged, and w'/Σw × min(|e|·cap0/(s·c), cap0) = w/Σw × min(|e|/s, c). Row by row it's exact, as the body says. You already list the limit: the diagnostics record the transformed weights and scales, and the past-cap census reads each row against cap0. Under county_rows, someone reading calibration_diagnostics.json would be misled. I'd record the per-row caps in the diagnostics, or flag the census as not applicable when the scope isn't run.
3. UNCLASSIFIED_IMPORTS grows, and the file says it may only shrink. The reason given is reasonable: hashing the shared rules in three more kernels would re-run target compilation on every rule edit. But it breaks a rule the file states. I'd either get an explicit OK from whoever owns the UK graph identity, or change the rule's wording to allow this kind of edge (imported only to hash the loss weights).
4. Sign-off for the UK re-key. The body says the UK modules were edited "with María's go of 25 Nov", and María is also the author. Nothing changes in the outputs, but every UK solve node re-keys. It would help to name a second person who agreed, as was done for earlier graph-identity changes.
5. Weight bound against a reference. The checks look right: the reference requires max_weight_ratio and the Adam solve without L0 gates, it must be positive and aligned, and under conserve the caps must admit the total. The start is clamped to the cap and projected back to the total. One question: is the softmax mass path (softmax_cap from bound_base) covered by a test with a declared reference? I only found the projection path tested.
6. Scope. The PR has 13 commits and +6.4k lines covering six separate features. The default-identity proof makes it safe to merge as one piece. But the diagnostic tool (commit 6) and the L2 anchor flag (commit 7) don't depend on the rest. Splitting them out would make the parts that touch the UK graph and the solver quicker to review.
7. A build before merging. I agree with "Not verified". With the defaults unchanged, the equivalence tests are strong evidence. But every UK solve node re-keys on the next run, so one UK national build on this branch would confirm the same weights at full scale before main relies on it.
Checked: the solver diff in full, the cap identity against the loss code, the CI logs at the head, and main's engine-us result at the merge base. Not checked: the UK and US equivalence tests themselves (not run locally), spine_target_shares.py, and area_support.py beyond the gate signature.
Review drafted with AI assistance and checked against the code at d4f5cd983.
solve.py is one of the direct kernel modules whose source bytes the US seed protocol attests (spec_engine/seeds.py), so commit 9dac441 moved the protocol's digest and the digests that carry it. engine-us failed on test_us_coverage_is_exact_complete_and_honest with "seed protocol content digest differs" and "compiled seed map digest differs". Only source bytes moved. Compared with origin/main fccd9a6: - of the modules in the protocol's two source lists, the digest of microcosm.calibrate.solve alone differs; - the seed protocol differs in two fields, the direct kernels' source_sha256 and the implementation_sha256 derived from it. Its sites, streams and boundary are the same; - the compiled seed map differs in one field, the implementation_sha256 it carries. Its sites and owners are the same. So no draw site, stream or owner changed, and a default build draws the same random numbers. Every value below was written by its tool; none by hand. tools/repin_us_spec_engine_contracts.py (two passes, then --check rc 0): - inventory_coverage.py seed_map 1dda5e09 -> 8a635713, seed_protocol 90d566bb -> ecf21269 - test_spec_engine_loader.py golden 6ba1402e -> 33b4f1a2 - test_us_multispine_pool_tool.py spec_sha256 2e3093b6 -> 2908dda7 - test_spec_engine_coverage_tool.py: pass 1 moves its count, pass 2 restores it; no change. tools/spec_engine_coverage.py (two passes, then --check rc 0; 42404/42404 configuration fields, 41/41 inventory checks): us-f0-coverage.json's eight digest lines to match. ruff format changed only the quotes the repinner writes. Part of microcosm#1729. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of PR 1735, point 3. Commit 657ae0c added an edge to UNCLASSIFIED_IMPORTS, a mapping its file says may only shrink: graph_targets imported the shared loss rules to put them in the hash of uk.full.problem@1, and the target, selection and measures kernels, which share that module, do not hash them. The problem's loss-weight modules are now named in uk_runtime/target_compile_modules.py (UK_FULL_PROBLEM_LOSS_WEIGHT_MODULE_NAMES) and resolved by name, as the target kernels' modules already are. graph_targets no longer imports calibrate.solve, calibrate.target_loss_rules, national_doctrine or geography_constants, which it read only to build that hash. So the new edge is gone, and two edges of the same kind that were recorded before this branch go with it (graph_targets -> calibrate.solve and graph_targets -> national_doctrine). Against origin/main the mapping shrinks by two and gains none. The problem kernel hashes the same six modules in the same order, so its hash does not move again. The test holds the hashed modules to the declared tuple and checks that graph_targets does not import them. Part of microcosm#1729. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of PR 1735, point 2. Under --county-target-loss-cap-scope county_rows the solver runs the one-cap loss that equals the row caps. The past-cap census of calibration_diagnostics.json, and each target's loss scale and weight in it, are the solver's, so they read every row against the equivalent cap. A reader of that file was misled about which rows are past their cap. row_cap_census (microcosm.calibrate.target_loss_rules) is the census against each row's own cap, on the declared scales. A solve under row caps now records a target_loss_caps block in calibration_summary.json and in the build block of calibration_diagnostics.json: the default cap, the cap of each level, the rows at each cap, each row that is not at the default, that census, and a line that says how to read the file's own census. A run with one cap records no such block, so default outputs do not change. The test shows the difference on a small solve: two rows miss by 200%, the row with cap 1 is past its cap and the row with cap 10 is not, and the solver's census against the equivalent cap of 5.5 sees neither. The reference page also describes the change of the commit before this one. Part of microcosm#1729 (item 3). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review of PR 1735, point 5. The softmax parametrization builds its cap from the declared reference too. The test that covered it now also checks the in-loop receipt (no weight the loop evaluated passed its declared cap) and compares with the same solve against the starting weights. A second test covers a record that starts above its bound. Part of microcosm#1729 (item 5). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main moved the US seed protocol pins too: the shared SIPP read (PR 1686) and the shared worker pool (PR 1726) edit modules whose source the protocol attests. Both sides rewrote the same tool-written digest lines, so the four pin files conflicted and nothing else did. Resolution: main's side of the four files, then the pins re-recorded on the merged tree. Every value was written by its tool; none by hand. tools/repin_us_spec_engine_contracts.py (two passes, then --check rc 0): - inventory_coverage.py seed_map 74aa4ed4 -> 3785072f, seed_protocol 24bb6217 -> 3ff54daa (from main's values) - test_spec_engine_loader.py golden c0431e2b -> a44fde61 - test_us_multispine_pool_tool.py spec_sha256 499389d4 -> 3187fe3a - test_spec_engine_coverage_tool.py: pass 1 moves its count, pass 2 restores it; no change. tools/spec_engine_coverage.py (two passes, then --check rc 0; 42404/42404 configuration fields, 41/41 inventory checks): us-f0-coverage.json's eight digest lines to match. Against main 63e22f9 the merged tree still differs only through source bytes: of the modules in the protocol's source lists, the digest of microcosm.calibrate.solve alone differs; the seed protocol differs in its source_sha256 and implementation_sha256, and the compiled seed map in the implementation_sha256 it carries. Sites, streams and owners are the same. Main did not touch the calibrate parity pin's modules or uv.lock. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thanks. All seven points, at head 1. engine-us and the seed protocol. The solver edit moved it, and only through source bytes.
So no draw site, stream or owner changed, and a default build draws the same random numbers. 2. Row caps in the diagnostics. Done in 3. 4. Sign-off for the UK re-key. I don't think this re-key needs a second sign-off. It changes no output: the body lists each node that re-keys, the equivalence tests hold the loss weights and the gate result to the old code, and 5. Softmax path. 6. Scope. I will keep one PR with ordered commits. The diagnostic (commit 6) and the L2 anchor flag (commit 7) are each one commit and can be read alone. The commits that touch the solver and the UK graph are 10 and 12 to 15. 7. A build before merging. No build is planned for this PR alone. The equivalence tests hold the UK loss-weight vectors and the gate result to the old code byte for byte, the default solver path is held to the pre-change optimizer bytes, and the UK engine and integration jobs pass on the head. The next UK build runs on main with these changes. The body's "Not verified" section keeps the limit: only a full build proves the same weights at full scale. |
Main moved the US seed protocol pins again (the SIPP donor revision re-pin and the source-vintage edits), so the four pin files conflicted: - docs/evidence/spec-engine/us-f0-coverage.json - spec_engine/inventory_coverage.py - tests/engine_free/shared/test_spec_engine_loader.py - tests/engine_workflow/us/test_us_multispine_pool_tool.py The merge takes main's side of the four files and re-records the pins on the merged tree with tools/repin_us_spec_engine_contracts.py and tools/spec_engine_coverage.py (two passes each; both pass --check: 42404/42404 configuration fields, 41/41 inventory checks). No value is written by hand. Against main the four files differ only in the digests the tools write. Main did not edit the solver, the calibrate package, gates.py, the UK graph modules or spec_engine/seeds.py. tools/us_acs_local_cd_surface.py merges without conflict (main edits one comment there). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
vahid-ahmadi
left a comment
There was a problem hiding this comment.
Follow-up at 3a564cd1c. Thanks, María. Points 1, 2, 3 and 5 are resolved, and I've checked each:
- Seed protocol (1).
fbcd52f29re-pins only the digests, and your comparison shows that onlysolve.py's source digest and theimplementation_sha256derived from it moved, with sites, streams and owners the same. That settles my concern: a default build draws the same numbers. engine-uk, integration-uk, lint, installed-emitter and wheels pass at the head; engine-free and engine-us were still running when I looked. - Row caps in the diagnostics (2).
3f4edd47frecords each row's cap and a census against it, with a test where the equivalent-cap census misses both rows. That's what I was after. UNCLASSIFIED_IMPORTS(3).a4734af99resolves the loss-weight modules by name. The test file now loses thegraph_targets -> national_doctrineandgraph_targets -> calibrate.solveedges, so the mapping shrinks, as its rule says.- Softmax path (5).
24aadedafchecks the in-loop cap receipt against the reference, and covers a record that starts above its bound. Good.
On 4, 6 and 7: understood, and I'm fine with your reasoning. The byte-equivalence tests and green UK engine jobs make the re-key low-risk, and the commits read well on their own. I'd still keep the "Not verified" line in the body, as you have, so the first UK build on main is read as the full-scale check.
Nothing further from me.
Review drafted with AI assistance and checked against the code at 3a564cd1c.
main's #1735 (microcosm#1729) moved the UK national loss weights onto the shared target_loss_rules and declared family_equal as the shared level_equal. The UC split's loss_family_equal (#1710) is the same arithmetic over loss families, so national_doctrine.py now declares it as level_equal too, computes every national rule through the shared rule, and drops the Counter it no longer needs; the weights don't change. #1735's declarations test now lists loss_family_equal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry and New Zealand's integer outputs (#931) Main took two pull requests since 268156c: #1735 (the shared calibration machinery of #1729: the loss-weight rules in calibrate.target_loss_rules, the weight bound, the shared area-support gate and the spine-target shares diagnostic) and #1752 (New Zealand's axiom outputs as integers and decimals). No feed or engine pin moves. Nine files conflicted. - The four pin files both sides moved: the US spec-engine seed map and seed protocol, the loader's golden spec vector and the US spec pin of the multispine pool test, each computed on the merged tree, and the US F0 coverage report, regenerated (--check passes, and so does the US re-pinner's --check). - Five UK graph files, where both sides changed how the UK target kernels hash what they compute through. #1735 has the full problem hash its loss-weight modules through the new names-list uk_full_problem_loss_weight_modules, not module-level imports, and has the national kernels and the rotated holdout hash target_loss_rules. This branch has each target and problem kernel hash every module its code computes through, held by the derived binding rule in test_uk_graph in place of #1497's import record. The merge keeps both: the problem hashes #1735's names-list for its weights and this branch's frame and monetary modules for the problem; the holdout and national kernels hash target_loss_rules beside this branch's lists; the measures kernel, which computes through local_rowwise's national rows, imports local_rowwise in its own hash now that graph_targets no longer imports it at module level; target_compile_modules' docstring keeps both paragraphs; and the compile modules test keeps this branch's hash-input record, without the unclassified-import record #1735 shrank, with #1735's new checks of the names-list. Checks: the engine-free tests the merge touches, among them the compile modules and target-weight tests, the shared loss-rule, weight-bound, area-support and spine-share tests, the transport binding rule, the evidence kernels, the contract and battery pins, the graph parity pins and the cross-grain tests (833 pass); the UK graph test with its binding rules, the loader and the coverage tool's tests (19 pass). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…no Orrery projection, untagged build folders (#931) Main took three pull requests since 51d952c: #1746 (each UK kernel builds its Frame from one copy of its input tables, through microcosm.frame.table_copies and Frame.adopt), #1748 (the graph package keeps the Orrery inputs and drops its projection, orrery_document among it) and #1740 (the build-folder switch tool reads untagged folders). No feed or engine pin moves. Three files conflicted. - uk_runtime/graph_kernels.py, _minimal_frame: both sides cut the stage kernel's Frame to one copy. This branch passed the frozen tables to the Frame constructor, whose own copy still stacked each dtype's columns; #1746 copies each column once with copy_table and stores the copies with Frame.adopt, and the strata with copy_series. The merge takes #1746's copy and keeps this branch's mass_log and metadata parameters, through which the spine gate kernel builds this one Frame, and both imports. - uk_runtime/graph_population.py: the import of the copy helpers beside Frame. This branch had removed the code that used Weights, so the merged import leaves Weights out; context_frame is #1746's. - tests/engine_free/uk/test_uk_graph.py: the imports. #1748 replaced the Orrery document check with a schema check (validate_graph_schema); the merge keeps this branch's binding-rule imports and drops the two that only the old check used. The derived binding rule then asked every UK kernel that builds its frame through _minimal_frame or context_frame to hash the new microcosm.frame.table_copies, and the merge adds it where each computes through it: every stage kernel (_implementation_hash), the spine gates, the calibration kernels' shared hash, the measures, problem and holdout, the three national kernels, the export preparations and the terminal phase's own code. It also brings the size search and refit to #1735's rules, which the merge at c18c0ae missed: they compute through target_weights and national_doctrine, so they hash calibrate.target_loss_rules too. Checks: CI's test plan and workflow verify; the tests the merge touches, main's changed tests among them (1,498 pass, then the UK graph test's binding rules, 65, after the hash additions); the parity pins, the graph evidence, the kernel frame copies, the FRS spine, the calibration graph, the transport binding identity and the battery pins (808); H2 parity and the UK graph on the engine (3); and the staging smoke (2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What this does
Part of #1729 (epic #1730). It moves the calibration pieces that the UK and US local builds each had in country code to shared code. Each country declares its choice as data.
The reference page is
docs/calibration-local-area-machinery.md.Commits
microcosm.calibrate.target_loss_rules). A loss weight and a loss cap for each target from its level, family, value basis and value. Rules:uniform,level_equal,level_family_equal(optional count power),sqrt_value_concept_budget.us_runtime.target_loss_weightskeeps what a US row is and calls the shared rule. New flag--target-weight-rule(default: the formula every build has used).--county-target-loss-cap-scope county_rowskeeps--target-loss-capon the state and district rows of a county build. Defaultrun, as before.microcosm.build.area_support). The Kish ESS of each area and the support table. The US district gate declares its floors to the shared gate.ess_by_groupand the inline Kish arithmetic are gone from the US tools.microcosm.calibrate.spine_target_shares,tools/spine_target_shares.py). For each target: the share each set of rows carries against its share of the mass. It reads a saved checkpoint and needs no build.--l2-anchor,--l2-anchor-weights(defaultinitial).microcosm.calibrate.weight_bound, max_weight_ratio anchors differently per arm: 5x vs design (dense) but ~25x effective (sparse refit re-anchors) — declare one stretch contract #493). The contract, tests that hold the solver to it, declared references and a report-only measurement.main(fccd9a68b), clean.max_weight_reference, opt-in), and the calibrate parity pin is re-recorded.--weight-bound-referencein the ACS local tool (defaultown).uk_runtime.target_weights(local rules) anduk_runtime.national_doctrine(family_equal) call the shared module. The UK problem, national and rotated-holdout kernels hash it.gates.area_support_gatetakes each floor as optional and gains the floor relative to the starting ESS (the Chi-square design-weight penalty and softmax mass parametrization for calibration; ACS local ESS frontier #1078 rule).solve.pyedit (see "US seed protocol").main(63e22f9d7). Main had moved the US seed protocol pins too, so the four pin files conflicted. They are re-recorded on the merged tree with the same two tools.main(268156c8f). Main moved the same US pins again. The four pin files are re-recorded on the merged tree with the same two tools.How the loss cap for each row works without a solver change
The solver's loss has one cap. For row caps
c, weightswand scaless, takecap0 = sum(w * c) / sum(w),w' = w * c / cap0,s' = s * c / cap0. Then each row's contribution, the loss value and the gradient are those of the loss with row caps. It is an identity, tested row by row.The solver records the transformed weights and scales, so its own past-cap census reads every row against
cap0, not against the row's own cap. For that reason a solve under row caps records atarget_loss_capsblock incalibration_summary.jsonand in thebuildblock ofcalibration_diagnostics.json: the default cap, the cap of each level, the rows at each cap, each row that is not at the default, the census against each row's own cap (row_cap_census), and a line that says how to read the file's own census. A run with one cap records no such block.UK identity
The UK graph hashes the bytes of each module a kernel names. This PR edits some of them, with María's go of 25 Nov. The outputs are the same, so these nodes compute again on the next run instead of reading a cached result:
calibrate/solve.pycalibrate.adam@1uk_runtime/graph_targets.py,target_weights.pyuk.full.target_compilation@1,target_selection@1,measures@1,problem@1uk_runtime/national_doctrine.py,graph_national.pyuk.full.national_targets@1,national_problem@1,national-gates@1,national-readback@1uk_runtime/graph_terminal.py,build/gates.pyuk.full-gates@1and its preflight, the threeuk.full-exportkernelsEach kernel hashes its own module, so an edit to a graph module re-keys every kernel it defines. Outside the UK, the transport gate kernel hashes
build/gates.pyand re-keys too.packages/microcosm-graph/tests/fixtures/parity/kernels/calibrate/pins.json) is re-recorded withtools/graph_parity_repin.py calibrate. The tool writes only when the kernel's direct output bytes are unchanged, and they are.uk/gates.jsondigest, gate replay or receipt moves. The UK spine kernels anduk_spine.jsonare not touched.UNCLASSIFIED_IMPORTSintest_uk_target_compile_modules.pyshrinks by two edges and gains none. The modules that decide the problem's loss weights are named inuk_runtime/target_compile_modules.py(UK_FULL_PROBLEM_LOSS_WEIGHT_MODULE_NAMES) and resolved by name, as the target kernels' modules already are. Sograph_targetsno longer importscalibrate.solve,national_doctrineor the shared rules only to hash them, and the two edges recorded for that before this PR are deleted.US seed protocol
solve.pyis one of the direct kernel modules whose source bytes the US seed protocol attests (spec_engine/seeds.py). The solver edit of commit 10 moved the protocol digest and the digests that carry it, and the first CI run failedengine-usonseed_protocol_and_owner_map_digests_exact. Commit 14 re-records them withtools/repin_us_spec_engine_contracts.pyandtools/spec_engine_coverage.py(both pass--check).Only source bytes moved. Against
origin/main(checked atfccd9a68b, and again at63e22f9d7after the second merge):microcosm.calibrate.solvealone differs;source_sha256and theimplementation_sha256derived from it. Its sites, streams and boundary are the same;implementation_sha256it carries. Its sites and owners are the same.No draw site, stream or owner changed, so a default build draws the same random numbers.
At the third merge (
268156c8f) the comparison was not repeated. Main edits neither the solver norspec_engine/seeds.pythere, and the four pin files differ from main only in the digests the two tools write.Proof that the results are the same
test_us_acs_local_shared_calibration.pyruns the realdo_calibrateon a small checkpoint. The default run passescalibrateexactly the 13 keywords of before, with the same values. The loss weights equal, byte for byte, a verbatim copy of the formula atac7ab99ae. The calibrated weights equal the bytes of a direct call with the historical arguments.family_equalequal verbatim copies of the UK arithmetic atfccd9a68b, byte for byte, on synthetic rows.fccd9a68bon 300 generated tables, reviewed exclusions included.origin/main(fccd9a68b) and on the final tree gives identical solver calls, weights,calibration_summary.json,calibration_diagnostics.jsonand gate entry, at 6 and at 200 epochs.Not verified
level_family_equal_sqrt_count,county_rows, a non-default anchor, a non-default weight-bound reference) are tested on small fixtures only. Each changes the weights and needs a build to measure.engine-us,engine-uk) did not run locally: the local environment has no country engine. CI is their only run. They passed at1ffa4cfce, and so didintegration-uk. The head after that is a merge of main (3a564cd1c); the checks on this PR show its run.Overlap with the open drafts
us-local-area-ready-2145): a trial merge of the final tree shows one conflict hunk intools/build_us_acs_local_release.py, in the import block.origin/mainhas the same hunk against Ready the US ACS local-area lane for the next national build on policyengine-us 2.145.3 (#1661, #1675, #1154) #1719 without this PR, and this PR adds no file to the conflicts.claude/us-soi-target-corrections): the trial merge is clean.Test plan
ruff check .andtools/ci_test_plan.py verify.1ffa4cfce, including the engine jobs andintegration-uk(first run:engine-usfailed on the seed protocol pin, re-recorded in commit 14).🤖 Generated with Claude Code