diff --git a/changelog.d/1800-be-release-files-and-assembly.added.md b/changelog.d/1800-be-release-files-and-assembly.added.md new file mode 100644 index 0000000000..87e936df18 --- /dev/null +++ b/changelog.d/1800-be-release-files-and-assembly.added.md @@ -0,0 +1,7 @@ +A spec country's transport build can now be assembled into a release build that `microcosm-publish-release-build` publishes, with the three files BE's release contract adds to the base three (microcosm#1800). Until now nothing wrote `source_coverage.json`, `demographics.json` or `reform_validation.json` for BE, so no new BE build could pass the contract #1744 put in force. + +- **The release files.** `microcosm.build.spec_release_files` builds each from the country's spec and the build's calibration diagnostics, reading no population. `source_coverage.json` has the US file's fields under the contract name `be_source_coverage`: each target category (or each reference's `family`, where the spec declares no category, as NZ's does) with an executable calibration reference is a hard target, each whose references are all parked is a source gap, and each held-out one is validation-only, under its own ID even where a target family has the same name; the check fails when the build left out an executable reference or calibrated a held-out one. `demographics.json` has the US file's fields (each age band without `min_age` and `max_age`, which the spec does not give) for the spec's demography references (BE: Statbel population by NUTS1 region, sex and age band), with each cell's calibrated population and benchmark and their sums by age band; BE calibrates these cells, so the file reports in-sample fit (`in_sample` true). `reform_validation.json` lists no reforms until scored BE reforms exist (microcosm#264), and records `out_of_sample_simulated` true, as the US writer does when no out-of-sample reform exists, so publication does not refuse it. +- **The release step.** `tools/assemble_spec_release_dir.py --build-dir --country be` (`microcosm.build.spec_release_assembly`) reads what the transport build wrote, as the UK national assembler reads its candidate's outputs. It refuses a build that still owes outputs; records no clean Microcosm commit, no runtime or no spec digests; ran on a spec whose resources differ from the one the step loads; has an H5, export descriptor, diagnostics file or run manifest that changed after the build wrote it, or an H5 that does not read back against its descriptor (which needs the pandas and NumPy versions the build used); has a gate that did not pass; has a year with no release that publishes into build folders; or fails its source coverage check. It also refuses to replace an earlier assembly. It writes `releases//` with each file the release contract requires, puts the H5 (`populace_be_.h5`) and a weights file from its household table (`populace_be__calibration.npz`) beside the build, validates the directory with the release contract, and prints the publish and promote commands. It uploads nothing. The build is named `microcosm-be--chronicle--`. +- **Transport builds record what they ran on.** `build-status.json` now records the Microcosm commit of the checkout that tracks the transport command's code and whether a tracked file differed from it (`microcosm.graph.reconstruction.code_revision`), the Python and package versions (`transport_build_provenance`), and the digest of each JSON spec resource the graph was composed from; its `produced` record now also gives the run manifest's digest. + +Out of scope: a BE transport graph (BE's spec declares none yet, so no BE build runs through the release step until it does), scored BE reforms, and a BE registry entry or staging. diff --git a/docs/agent-guide.md b/docs/agent-guide.md index 360d334d20..0472a0e4b2 100644 --- a/docs/agent-guide.md +++ b/docs/agent-guide.md @@ -388,6 +388,10 @@ chooses the tier (certified, or `--evidence-release`), runs the release's post-export checks, places the build in that tier's release directory, writes the manifests and prints both commands (microcosm#1585 item 11). The ACS package stage prints both commands itself. +A spec country's transport build (BE's releases) goes through +`tools/assemble_spec_release_dir.py`, which reads the build's `--out` folder, +writes the release directory with the files the country's release contract +lists and prints both commands (microcosm#1800). `tools/preflight_us_release_gates.py` runs the US national release checks that need no calibration on the base before a build, and again with the finished build's `--release-manifest`. The emitter changes @@ -707,7 +711,10 @@ The transport build driver (`tools/build_transport.py`, a shim over `microcosm.build.transport.cli`) composes a country's graph from its `transport_graph.json` spec resource and runs it locally: every file it writes, including its `.graph-store`, lies under `--out`, and it has no -upload or staging path. Before it opens the store it refuses any link in an +upload or staging path. Its `build-status.json` records the Microcosm +commit, whether a tracked file differed from it, the Python and package +versions and the digest of each JSON spec resource the build ran on, which the +release step reads. Before it opens the store it refuses any link in an existing store tree (the root, `objects`, `tmp` or a shard), because the store creates those directories by following links; it does not guard against links planted while a build is running. Activation checks run before diff --git a/docs/release-contract.md b/docs/release-contract.md index ab7d85e959..e25acab3f4 100644 --- a/docs/release-contract.md +++ b/docs/release-contract.md @@ -1122,6 +1122,35 @@ work. BE builder in this repository stages and the collector registers no BE staging repository; a BE build whose manifest records no staging is not refused for it. + - *BE's release files and release step* (microcosm#1800). A BE build's + three added files come from `microcosm.build.spec_release_files`, which + reads only the country's spec and the build's calibration diagnostics: + `source_coverage.json` has the US file's fields under the contract name + `be_source_coverage`, with the spec's target categories (or, where it + declares none, each reference's `family`) as its source families; + `demographics.json` has the US file's fields (each age band without + `min_age` and `max_age`, which the spec does not give) for the spec's + demography references, whose fit is in-sample because BE calibrates + them; and `reform_validation.json` lists no reforms, with + `out_of_sample_simulated` true as the US writer records it when no + out-of-sample reform exists, until microcosm#264. The release step for a + transport build, `tools/assemble_spec_release_dir.py` + (`microcosm.build.spec_release_assembly`), reads the build's `--out` + folder as the UK national assembler reads its candidate's outputs: + `build-status.json` (nothing owed; a clean Microcosm commit, the runtime + and the digest of each JSON spec resource, which a transport build + records there and which must equal those of the spec the step loads), + the H5 read back against its export descriptor (under the pandas and + NumPy versions the build used, which the descriptor records), the + calibration diagnostics and the run manifest (every gate passed). It + writes `//` with each file the country's release + contract requires, puts the H5 and a weights file beside the build under + the manifests' names, validates the directory and prints the publish and + promote commands; it uploads nothing. The release is + `microcosm---national` for the export's year, and only a + name `publishes_to_build_folder` admits is taken. BE's spec declares no + transport graph yet, so no BE build runs through this step until it + does. - *The first build of a new UK `k`* (2026-11-13). `validate_release_dir` refuses every layout of a local-area release until a registry entry names it, and `build_folder_identity` and `microcosm-publish-release-build` diff --git a/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py new file mode 100644 index 0000000000..3a91073485 --- /dev/null +++ b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py @@ -0,0 +1,879 @@ +"""Assemble a spec country's transport build into a release build. + +The release step for a country whose builds run through the spec-driven +transport command (:mod:`microcosm.build.transport.cli`), as +``tools/assemble_uk_release_dir.py`` is for the UK national release and +``tools/certify_us_national_build.py`` for the US national one (tracker +5b · 13). Like them it reads the build's own outputs, here what the transport +command wrote under ``--out``: + +- ``build-status.json``: the outputs the build still owes (it refuses unless + there are none), the Microcosm commit, the Python and package versions and + the digest of each JSON spec resource the build ran on (they must equal + those of the spec this step loads), and the digests of the H5, its + descriptor, the diagnostics and the run manifest it wrote; +- ``skeleton.h5`` and ``export-descriptor.json``: the population, read back + against its descriptor, and its period and weight entity; +- ``calibration-diagnostics.json``: the calibration's diagnostics; +- ``manifest.json``: the run manifest, whose gate nodes must all have passed. + +From the country's spec it reads the release contract (the dataset file name, +the release repository and the required files), the target and holdout +references and the Chronicle pin. It then writes the release directory +``//``, holding each file the contract requires +(:mod:`microcosm.build.spec_release_files` writes the source coverage, the +demographics and the reform validation), puts the H5 and a weights file +beside the build under the names the manifests give them, validates the +directory with the release contract and prints the +``microcosm-publish-release-build`` commands that publish the build and then +make it current. Nothing is uploaded. + +The release is ``microcosm---national`` for the export's +period, refused unless :func:`microcosm.data.contract.publishes_to_build_folder` +admits it. The build is ``microcosm---chronicle--