Repository navigation
ACS local: full-size materialize and calibrate refuse a staging H5 that is not the one run_identity.json records - #1855
Merged
Conversation
…olds `materialize --sample-fraction` loads the whole staging H5 before it draws the 1%, 4%, 10% or 25% household sample. These tests write a staging H5 fixture and check that a reduced-size run: - hands the steps after the draw the frame, take-up receipt and sampling receipt the whole-file load gives, at every fraction and at full size; - writes the same run identity, target matrix, roles, registry, assignment file and lean checkpoint tables (the lean checkpoint's file digest is left out: PyTables records modification times in it); - never calls the whole-file staging load; - uses less traced memory at smaller fractions; - still refuses hours and self-employment rows outside the sample, a staging file replaced between its reads, and the sampling refusals. Before the change, the whole-load, peak-memory and replaced-file tests fail on their assertions; the others pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`materialize --sample-fraction` below 1 now reads the staging H5 in two parts instead of loading it whole before the draw: 1. `_load_staging_columns` reads the columns the hours and self-employment refusals, ACS take-up and the draw read (`_materialize_columns_before_draw`), for every row, through `load_legacy_calibrated_us_h5_columns`. The refusals, take-up and `sample_staging_frame` run on that frame unchanged (`_checked_staging_rung`), so they still cover every household. 2. `_with_drawn_households` reads every stored column of the drawn households' rows only, through `LegacyCalibratedUSH5Households.select`, and puts the drawn frame's columns (take-up's filled cells among them), weights, strata, mass log and metadata on it. Each read refuses every file the whole load refuses. After the second read, `_require_staging_unchanged` refuses a staging file whose bytes are not the ones hashed for the run identity, so a file replaced between the reads is not mixed into one frame. A full-size run keeps the whole load. The county materialize fixture runs a 1% rung with a stand-in frame, so it now stands that frame in for both reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e run Real builds evaluate the hours and self-employment refusals a second time through the check registry, on the frame materialize hands them. The test switches that evaluation on (the test suite turns it off) and checks that a 10% run records the same observations for both entries as a full-size run of the same staging file, with no evaluation error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The staging fixture gives some ACS persons a complete source identity and some ACS SPM units a source id, so ACS take-up's draws for them are keyed on those columns. Removing the person source-identity columns from `_materialize_columns_before_draw` now changes ACS TANF take-up and fails the identity test; removing `spm_unit_source_id` is refused by the column loader's guard. - The whole-load test also watches `load_legacy_calibrated_us_h5`, which both partial loaders call when a table cannot be read in parts. - `_staging_rung`'s docstring, the target-surface doc and the changelog say which memory does not shrink with the fraction: the listed columns for every row and, during the second read, every string, object and nullable-Boolean column for every row. - The memory test says `tracemalloc` does not count pyarrow or HDF5 buffers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 found no bugs. Its notes on the wording: - The household reader keeps whole only the nullable-Boolean columns that hold a missing value (with every string and object column), not every nullable-Boolean column. - `_with_drawn_households` decodes string, object and nullable-Boolean columns whole and keeps the drawn rows; only number and Boolean columns are read for the drawn rows. - The check after the second read refuses a file whose bytes then differ from the run identity's; it does not catch a file replaced before one read and restored before the next. - Read time does not shrink with the fraction. - The county fixture helper's comment no longer names a tracker task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`test_release_checks_self_employment_wherever_it_loads_staging` read `do_materialize`'s statements for the hours check followed by the self-employment check. Materialize now loads the staging H5 only in `_staging_rung` (whole at full size, a column subset for a reduced-size run) and hands each load straight to `_checked_staging_rung`, which runs both checks. The test now checks that `do_materialize` reaches the staging only through `_staging_rung`, that both of its loads are passed to `_checked_staging_rung`, and that the self-employment check follows the hours check there, as it still checks for the calibrated-H5 write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Anthony decided on 1 December that the shared loaders' `expected_sha256` argument is added in this pull request. These tests fail before it exists: - `load_legacy_calibrated_us_h5`, `load_legacy_calibrated_us_h5_columns` and `LegacyCalibratedUSH5Households` take `expected_sha256`; given the file's digest they load what they load without it, and given another digest they refuse the file, naming it and both digests. Each is checked on a file read in parts and on one read whole because its family table cannot be read in parts. - A reduced-size materialize refuses a staging file replaced after the draw, and one replaced after materialize hashed it and restored after the draw (each read is then consistent with itself, and the hash after both reads matches), with the loaders' new refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shared legacy calibrated US H5 loaders take an optional `expected_sha256` (Anthony's decision of 1 December: added in this pull request). `refuse_unexpected_h5_digest` refuses a file whose digest when the loader opens it is not the expected one, before any table is read: - `load_legacy_calibrated_us_h5`; - `load_legacy_calibrated_us_h5_columns`, when it reads in parts and when it falls back to the whole load; - `LegacyCalibratedUSH5Households`, likewise. Each loader already refuses a file that changes while it holds it open, so a read that is not refused read exactly the bytes the caller hashed. A reduced-size materialize passes the run identity's digest to both of its reads, so a staging file replaced before the first read or between the two is refused instead of being mixed into one frame. The extra full-file hash after both reads (`_require_staging_unchanged`) is no longer needed, so a reduced-size run hashes the file five times instead of six. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 found one low-priority bug, left as it is: a full-size materialize, like calibrate, still loads the whole staging H5 without comparing it with the run identity's digest, as before this pull request. Its other findings: - A test now reaches each partial loader's whole-load fallback with a wrong digest: the file's digest is right when the partial loader opens it and wrong when the fallback does, and the fallback must refuse it. With the fallbacks not passing the digest on, both cases fail. - The materialize structure test now checks every loading call in `_staging_rung`, not only their names: each is a staging load and each is the frame `_checked_staging_rung` receives. - Docstrings no longer claim more than the code does: the denied-pool check reads the stored household weights before the digest is compared, both digests are taken by path, the digest is compared as given (lower-case hex), and a full-size run is not compared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lize branch One conflict, in `test_release_checks_self_employment_wherever_it_loads_staging`: main now searches every nested block of a stage for the hours check followed by the self-employment check (the calibrated write runs them inside a try); this branch moved materialize's checks into `_checked_staging_rung` and adds checks that `do_materialize` reaches the staging H5 only through `_staging_rung`. Both are kept: the structure checks, then main's nested-block search over `_checked_staging_rung` and `_write_calibrated_artifact`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since the calibrated H5 write merged, calibrate no longer loads the whole staging frame to re-draw a development rung: it reads the person columns its steps read and the other tables whole. The development-rung memory note said it still loaded the whole frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng file (1.7 · 5) Two tests that fail before the change: - a full-size materialize whose staging H5 is replaced after it was hashed for the run identity, and put back once the whole load returns, must be refused before ACS take-up runs and before run_identity.json is written; - calibrate's write must refuse a staging H5 whose digest is not the one run_identity.json records, before any table is read. Stand-ins for _load_staging_frame and _open_staging_for_calibrated_write now accept keyword arguments, and the calibrated-write tests pass a run identity holding the staging file's digest, as materialize records it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (1.7 · 5) A full-size materialize now passes the staging digest it hashed for the run identity to _load_staging_frame, which passes it to load_legacy_calibrated_us_h5; calibrate's _StagingRead compares the digest it computes when it opens the staging H5 with the staging_sha256 run_identity.json records, before it opens the HDF store. A staging file replaced after materialize hashed it is refused before any table is read. _load_staging_frame calls load_legacy_calibrated_us_h5 directly (the multispine base tool's _load_base_frame is that call) and keeps the keyword optional, since the county AGI support check loads a staging file with no run identity. _StagingRead and _open_staging_for_calibrated_write require it. The comparison reuses the digest each read already computes, so it adds no hashing and leaves outputs unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ead (1.7 · 5) Review round 1 found no bugs; these strengthen the tests it named. The stand-in for _open_staging_for_calibrated_write in the do_calibrate tests now asserts that the write passes the run identity's staging_sha256, on the solve's path and on a completed resume's; and the calibrate refusal test also checks that consumer_export.json is not written. Against the release tool before the change, every do_calibrate test that reaches the write fails on that assertion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The check against refused pool files reads the stored household weights before the digest comparison, so the docstrings and the target-surface document now say the refusal comes before any table is read for the frame or the write, as #1840's loaders say. The changelog fragment no longer describes the unreleased state between #1840 and this change, and names no private functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
December 2, 2026 20:51
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 #1854
What this changes
tools/build_us_acs_local_release.py --stage materializehashes the staging H5 before it reads it and records the digest inrun_identity.jsonasstaging_sha256. Two reads of the staging H5 did not compare the file with that digest when they opened it. Both now do, so a staging file replaced after materialize hashed it is refused before any table is read for the run.--sample-fraction 1.0)._staging_rungpassesstaging_sha256to_load_staging_frame, which passes it toload_legacy_calibrated_us_h5(..., expected_sha256=...)(the keyword materialize --sample-fraction: load only the sampled households instead of the whole staging frame #1840 adds). Before, a staging file replaced after it was hashed, and put back once the whole load returned, gave a checkpoint built from one file whilerun_identity.jsonand every receipt named the other. The reduced-size reads compare since materialize --sample-fraction: load only the sampled households instead of the whole staging frame #1840, so every read of the staging H5 by materialize now compares._write_calibrated_artifactpassesidentity["staging_sha256"]to_open_staging_for_calibrated_write, and_StagingReadcallsrefuse_unexpected_h5_digestright after the check against refused pool files and before it opens the HDF store. Before,do_calibratecompared the digest only when the stage started (_verify_run_identity), and the write opens the file again after the solve, which can take hours. This covers both calls of the write: after a solve, and on a resume whose calibration is already complete.The comparison uses the digest each read already computes when it opens the file, so it adds no hashing. For a staging file that was not replaced, every output is byte-identical: H5 datasets, calibrated weights, target values and diagnostic values.
Interface
_load_staging_frame(path, *, expected_sha256=None): the keyword is optional becausetools/check_us_acs_county_agi_support.pyalso loads a staging file with it, with no run identity. It now callsload_legacy_calibrated_us_h5directly instead ofbuild_us_acs_multispine_base._load_base_frame, which is exactly that call._StagingRead(path, *, expected_sha256)and_open_staging_for_calibrated_write(path, *, expected_sha256)require it: their only caller always has the run identity. This matches materialize --sample-fraction: load only the sampled households instead of the whole staging frame #1840's_load_staging_columnsand_open_staging_households.refuse_unexpected_h5_digest'sValueError("… is not the file the caller hashed …"), as materialize --sample-fraction: load only the sampled households instead of the whole staging frame #1840's reduced-size reads refuse it.Other files
docs/us-acs-local-soi-target-surface.md: the "Refusals" bullet says which reads compare the staging H5 withstaging_sha256.changelog.d/us-local-staging-digest-check.changed.md.Built on #1840
This branch is built on #1840's branch
claude/us-local-sample-fraction-load(tracker task 1.7 · 4, heade1dc7ef18), which adds theexpected_sha256keyword and_staging_rung. The PR targetsmain, so until #1840 merges its diff also shows #1840's commits. This PR's own commits are the four aftere1dc7ef18:9b8f6348a: the tests that fail before the change;802f712f8: the change;97c3bad15: tests strengthened after review round 1;f52d38eb0: wording after review round 1.Tests
Added
test_us_acs_local_sampled_materialize.py::test_full_size_materialize_refuses_a_file_swapped_and_restored_around_its_load: a full-size run whose staging H5 is replaced after materialize hashed it, and put back once the whole load returns, is refused withis not the file the caller hashed. ACS take-up never runs andrun_identity.jsonis not written.test_us_acs_local_calibrated_h5_stream.py::test_a_staging_file_replaced_since_materialize_hashed_it_is_refused: the calibrated write is given a valid staging H5 with other values than the one whose digest the run identity records. It is refused before the frame builder runs, and no fill manifest, consumer manifest or calibrated H5 is written.Changed
do_calibratetests' stand-in for_open_staging_for_calibrated_write(_calibrate_through_the_write) asserts that the write passes the run identity'sstaging_sha256, on the solve's path and on a completed resume's._load_staging_frameand_open_staging_for_calibrated_writeaccept the keyword (county-surface and no-county regression tests)._write_calibrated_artifactto the real staging read pass a run identity holding the staging file's digest, as materialize records it. This covers the calibrated-H5 streaming tests, the block-location writer helper and the county export fixture. The county fixture writes the staging H5 after its materialize stand-in hashed placeholder bytes, so its identity now names the written file.Local results
Each test was run by pytest node ID, only those added or changed; no full suite was run.
9b8f6348a(tests only): both added tests failed withFailed: DID NOT RAISE <class 'ValueError'>.802f712f8(the change): the 34 added or changed tests passed, 59 cases with parameters (by test: streaming 20, release tool 8, county surface 4, sampled materialize 1, no-county regression 1).97c3bad15): with the release tool frome1dc7ef18put back in the working tree, all 8 cases that reach the write failed on the new assertions, for exampleassert {} == {'expected_sha256': 's'}. At the change, all 9 cases passed.ruff checkandruff formatare clean on every changed file.CI
No CI results read yet.
Review
One round, in a fresh subagent following the review-code skill: round 1 at
802f712f8. No bugs found (high, medium or low). The reviewer also ran the added and changed tests by node ID, at the tests-only commit and at the head. Since the round found no bugs, review stopped there.I acted on three of its code-quality findings:
do_calibratestand-in now asserts the digest it is given, where it used to discard it;consumer_export.jsonis absent;Left as they are
Nonedigest.identity["staging_sha256"]missing would give a bareKeyError, andNonewould turn the comparison off. No path reaches either:do_calibrate's_verify_run_identityexits unless the recorded value equals a fresh digest of the file.h5_io'sValueError, as materialize --sample-fraction: load only the sampled households instead of the whole staging frame #1840's reads and the existing "changed while being read" refusal are; the check when the stage starts names the remedy (re-run materialize).What the merge waits for
--sample-fractionloads only the sampled households): must be merged. This PR is built on its branch and uses itsexpected_sha256keyword and_staging_rung. A merge to microcosm'smaindeploys and publishes nothing, so merged is enough.The task has no dependency of its own, and substage 1.7 depends on none. Nothing waits for a release or for a manual step.
🤖 Generated with Claude Code