Skip to content

Add Microcosm dataset and certification selectors - #763

Draft
MaxGhenis wants to merge 12 commits into
mainfrom
max/microcosm-dataset-selection
Draft

MaxGhenis wants to merge 12 commits into
mainfrom
max/microcosm-dataset-selection

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Accept microcosm_us_2024 and microcosm_us_2024_acs_local as US dataset selectors alongside populace_us_2024 and populace_us_2024_acs_local. Dataset selection uses an exact bundle key when present and falls back to the corresponding spelling when that key is absent. If the bundle records both spellings, each exact key selects its own artifact.

The current bundle has one US artifact per filename stem. With that bundle, existing bundle keys and calls without a selector keep main’s artifact selection, artifact SHA-256, result values and result keys. They still populate the repository-relative raw cache. Runtime provenance records the pin-specific path the model uses. Distinct same-stem sources must be requested separately, and managed flat year files require the bundle’s source hash. Local keys and filenames retain the full stem. When the bundle has a pin for the same stem, unpinned requests read and write only their source-specific year-file path. If the file is missing, build it with ensure_datasets(..., allow_unmanaged=True) or create_datasets(..., allow_unmanaged=True). When both spellings resolve to the same entry, they produce the same results and reuse the same year files. create_datasets, load_datasets and ensure_datasets key bundle results by artifact filename stem and year. For a local file such as sample@local.h5, the 2024 key is sample@local_2024 and the year filename is sample@local_year_2024.h5.

Separate derived US year files by source SHA-256 when the bundle records more than one distinct source SHA-256 for that filename stem. Each such source writes and reads its year files under .policyengine-us-year-files/ in the data folder, in a subdirectory named by a hash of the source’s SHA-256, so each exact selector loads its own source’s year files. An explicit URI that identifies a bundle pin uses managed materialization. Materialization verifies the temporary download against the bundle’s SHA-256 before replacing the raw cache file. It also verifies any pinned metadata sidecar. Managed microsimulation records verified provenance for opt-in Hugging Face URIs that exactly match a bundle pin. US runs derive any legacy SPM declarations registered for that pin from the full verified source and align them to the selected cohort and its reform branches. This includes state and congressional-district runs that use the registry’s dataset URI and row filter.

In any batch, create_datasets, load_datasets and ensure_datasets now refuse distinct sources that would share a result key, such as two explicit URIs whose files share a stem (e54b0d892); main returned one entry for them, and its create_datasets overwrote the shared year file. The three functions resolve local paths before they compare them, so they return one result for a relative and an absolute path to one file, as main did (47eb2d63f). They still refuse other pairs of spellings for one artifact, such as a Hugging Face URI with and without @main, or a bundle key and a local path to its cached file; main returned one entry for these. Before materializing any source, create_datasets rejects result-key collisions and raises ValueError for missing explicit local files that no earlier request can produce. It then cuts each source’s year files before it materializes the next source, as main did (47eb2d63f).

Record the source SHA-256 in flat year files (47eb2d63f). create_datasets writes a bundled US artifact’s year files straight into the data folder, as main did, unless the bundle records more than one distinct source SHA-256 for that filename stem. It now adds the artifact’s bundle SHA-256 to the stamp of each of these flat year files as source_sha256. load_datasets requires a managed flat year file to match the bundle’s pin. ensure_datasets can regenerate it from the bundle key or an exact pinned URI. By default, regeneration from an exact URI uses its bundle key. With allow_unmanaged=True, regeneration preserves the explicit URI’s ordered raw-cache updates. An unpinned request with no same-stem bundle pin requires an unbound stamp on its flat year file. Main could reuse a flat year file after an updated bundle pinned a different SHA-256 for the same filename stem. Releases from 6.3.3 up to this change read a stamp that holds source_sha256 as malformed. When one of them and a release with this change share a data folder, each one’s ensure_datasets regenerates the flat year files the other wrote. Unpinned year files omit source_sha256. When their stem has a bundle pin, they are written to a subdirectory keyed by the resolved local path or URI. Managed year files in per-source subdirectories omit the hash because the directory identifies the pin. The changelog.d/microcosm-dataset-selectors.changed.md fragment says that load_datasets refuses year files without the matching hash and that ensure_datasets regenerates them (1e8b78986). docs/microsim.md defines flat year files and describes the same check and regeneration.

New tests in 47eb2d63f cover a flat year file with a stale or missing hash after the bundle pins two same-stem keys to one SHA-256, a pin change that keeps a same-stem artifact’s URI, a download whose bytes do not match the bundle SHA-256 for its URI, the order in which create_datasets materializes sources, and relative and absolute spellings of one local file. Another checks that create_datasets refuses a batch of two URIs whose files share a stem before it downloads either. The batch refusal test now runs create_datasets, load_datasets and ensure_datasets, and the recertification warning test renames keys in both directions.

Accept --data-producer microcosm in scripts/bundle.py certify-data and scripts/certify_data_release.py as an alias for populace, and use it in the two US commands in docs/engineering/skills/data-certification.md. Either spelling records populace as the producer and keeps the release’s published dataset names in certification summaries, generated changelog fragments and bundle records. UK examples still pass --data-producer populace, the producer that the UK release metadata records. Recertification now applies the same alias fallback when it checks which previously certified selectors still resolve through the new release or the bundle’s dataset overlays. It no longer warns about a Populace selector that resolves to a Microcosm key (ddac5afc9).

Correct the US certification examples and the microsimulation guide (ada238e06):

  • The US commands in docs/bundles.md, docs/release-bundles.md and docs/engineering/runbooks/build-m-us-populace-certification.md now certify a national build and an ACS-local build that releases.json lists. The old commands used tag-based manifest paths, which the CLI refuses once the repository has a releases.json index, and one omitted --data-producer, which selects the unsupported legacy producer for the US. The commands now pin the commit that published each build, read the manifest from that build’s own release folder and pass --data-producer microcosm. The build-m-us-populace-certification.md runbook now says state and congressional-district simulations use the ACS-local release through the bundle’s regional routes, not the national release, and it names the changelog fragment after the national build. docs/bundles.md also puts the UK example’s manifest URI in double quotes, so the shell does not read the < and > around its <release> placeholders as redirections.
  • docs/engineering/runbooks/canonical-spm-development.md adds --regional-manifest-uri to its certification command, because certification refuses a national-only run while the bundle routes regions.
  • docs/microsim.md separates the source check against the bundle SHA-256 from the checks on derived year files. It describes load_datasets as loading the default dataset’s current year files, and its local-area examples use the registered key populace_us_2024_acs_local.

#786 tracks two follow-ups: matching a bare hf:// URI with its @main spelling, and a year-file stamp revision bump.

Verification

  • The lanes run static checks only (py_compile, git diff --check, ruff format --check, ruff check); CI runs the test matrix and the documentation build at the head. The runs below predate 47eb2d63f and 1e8b78986, so none of them covers the code or tests that 47eb2d63f adds.
  • Every Python run below used CPython 3.14.10 with the development extras.
  • At 646963a39, this PR’s first commit, the three test files this PR changes recorded 123 passed. With those files taken from cdb13de60, 127 passed and 16 failed at 646963a39, and all 143 passed at cdb13de60. Five further checks of the documentation wording, run outside the test suite, failed at 646963a39 and passed at cdb13de60.
  • At cdb13de60 with the new same-stem and recertification tests copied in, six test files covering year files, dataset materialization, certification and release manifests recorded 333 passed and 8 failed: test_us_year_file_stamp.py, test_dataset_materialization.py, test_certify_data_release.py, test_release_manifests.py, test_local_data_manifest.py and test_us_legacy_spm_integration.py. The failures were six national and ACS-local same-stem year-file cases in test_us_legacy_spm_integration.py and two recertification warning cases in test_certify_data_release.py. At ed22ad6d3, all 341 cases in those files passed.
  • At ed22ad6d3, the remaining 138 of the 144 test files recorded 4,599 passed, none failed and 20 skipped. The skipped cases need unpublished or credentialed inputs, opt-in local setups, other package versions, or Python before 3.14. The passes include the four test_preparation_generates_new_sidecars_and_verifies_the_exact_pair cases, which ran against a local not-found response instead of a request to a Hugging Face index that needs a credential. Without that credential they fail at that request; this PR does not change that test.
  • With local releases.json and release-manifest fixtures, the five US certification commands in the four certification documents failed at cdb13de60. At ed22ad6d3, docs/release-bundles.md has one US command where it had two, and all four commands passed. All 27 Bash blocks in the four certification documents that ada238e06 changes passed bash -n at ed22ad6d3.
  • At ed22ad6d3, Ruff 0.17.6 lint and format checks (the unpinned release CI installs), scripts/bundle.py check and git diff --check passed, and git merge-tree reported no conflicts with main at ddfef2a8e.
  • Not checked: downloads from the live release index and its artifacts, a live UK certification, and test_the_certified_dataset_projects_to_2030, which needs a certified UK dataset the run could not download.
  • 705324d8f changes only spelling (artifact, materialize, re-normalizes) in docs/microsim.md, the US certification runbook and two comments in us/datasets.py, so the results at ed22ad6d3 hold for it.

Related to #490, the issue on adopting Microcosm naming.

axiom: n/a: dataset selection, US year-file caching and certification inputs; no policy-rule changes.

🤖 Generated with Claude Code

MaxGhenis and others added 9 commits November 18, 2026 13:58
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The repository spells artifact, materialize and normalize the American way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns and match local path spellings

Round 3 found that create materialized every source before using any, that an old flat year file could load after two stems' pins converged, and that two spellings of one local file were refused as different sources. Create now checks result-key collisions first and uses each source before materializing the next. Managed flat files carry their source SHA-256, and a file with a stale or missing hash is regenerated. Local sources compare by resolved path. Tests cover each case, batch refusal across create, load and ensure, and recertification in both rename directions. The microsim guide and changelog record the cache migration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_datasets now refuses a managed US flat year file whose recorded source SHA-256 is missing or differs from the bundle's pin, so files written by earlier releases need regenerating once. The changelog lists this under changed, and the microsim guide defines flat year files and says that ensure_datasets regenerates them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis and others added 3 commits December 2, 2026 23:16
…er local preflight

- ensure_datasets maps an exact pinned URI to its bundle key and rebuilds a
  pre-upgrade flat year file through it; opt-in creation derives the legacy
  SPM declarations from the verified pin. load_datasets still refuses a
  pre-upgrade managed flat file until ensure_datasets rebuilds it.
- A download whose URI exactly matches a pinned bundle artifact is verified
  before it replaces the raw cache, and year files are staged, stamped and
  validated before they replace a warm cache.
- The batch planner treats absolute paths, symlinks and planned outputs as
  local inputs without resolving them, and checks each file when its
  request runs, so an earlier request in the batch can create it.
- A flat file that records a source SHA-256 is refused for a request
  without an exact pin, conflicting URI pins are refused, and an unpinned
  same-stem entry no longer forces a split cache; the guide's split
  condition needs more than one distinct source SHA-256.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng, document local keys

- Materialization returns the bundle provenance after it verifies a
  download whose URI exactly matches a bundle pin, so managed
  microsimulation records verified provenance for that URI and US runs
  apply the legacy SPM declarations registered for the pin.
- Opt-in creation raises ValueError during planning for an explicit local
  file that no earlier request in the batch can produce.
- New unpinned year files go to a source-specific path when their stem has
  a bundle pin, so alternating managed and unpinned requests reuse their
  own files instead of overwriting one flat file.
- The guide and changelog cover full local stems such as sample@local,
  unpinned requests refusing hash-stamped flat files, and moving to
  source-specific paths.

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ck, read year files from one snapshot

Round 5 found five P1s in the cache-identity and provenance code. Legacy SPM
declarations now come from the full verified input and align to scoped
regional runs. Models receive pin-specific raw paths that other downloads
cannot replace. Unpinned requests for a stem with a bundle pin use only their
source-specific year file. Opted-in URI rebuilds keep the ordered raw-cache
updates. Stamp, SPM record and tables load from one file snapshot. Exact URIs
verify pinned metadata sidecars, ambiguity checks include the package name,
and explicit relative paths and unpinned bundle keys fail in preflight.

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants