Repository navigation
Plan, build and look up prebuilt year files and baselines through country and dataset-level handlers - #1132
Merged
Conversation
Record what main (544ff62) produces for fixed inputs, so moving the US precompute, manifest and runtime lookup onto handlers that take a country and a dataset level can show the US results are unchanged: - the plan from plan_artifacts_impl: three default-dataset year files, one baseline per year and each of the 20 region groups, and one state-level year file per year and state, with every key, store path, simulation ID and folder, with and without an SPM capability; - the entries select_work picks with and without force; - the key schema labels and the store paths, manifest_path and deployed_marker_path; - the manifest's entry order, its exact published bytes and its digest for the full US plan (with and without SPM) and for a small plan; - which requests get a fixed baseline ID, the hit, incomplete and miss outcomes ArtifactBaselineSimulation records, and the folder baked_state_data_folder returns. The inputs are stand-ins with no GCS, Hugging Face or Modal access: identity_stubs' version-set, the 51 US state regions with their real codes and FIPS numbers, and a fake GCS client. The national partition is the real one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests for the approved design of prebuilt files by country and dataset level, which fail until the handlers exist: - the handlers: six dataset levels, the US and UK settings, how a run gets its level, each level's year-file and baseline targets, the year file a run reads, its fixed-ID scope and its prebuilt/ folder, and that the handler modules import no run_simulation feature module; - one yf1 year-file identity and one bl3 baseline identity for every level, golden digests computed from the design's payloads; - plan_artifacts_impl(bucket, country): the same US files as before, each with its new identity, and an empty UK plan; - the mf2 manifest, with each file's recorded SHA-256 and size, and run_precompute for one country; - the download step placing files under prebuilt/, refusing a hash or size mismatch, a file already in the image, another schema and another policyengine-core version; - a national run reading its prebuilt folder. The identity stubs gain the default dataset's certified hash and fixed installed-package versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The run_simulation app's prebuilt year files and current-law baselines go through handlers that take a country and a dataset level, as the approved 1.6 · 1 design sets out: - stage12_cache/levels.py, levels_us.py and levels_uk.py: six dataset levels, per-country settings, and key-free handlers that say which files a year builds, write the year files, and tell a run which year file and prebuilt folder it reads and whether its baseline gets a fixed ID. The US settings build today's files: 3 national year files, 153 state year files and 60 group baselines. UK settings build nothing yet and keep the UK-wide fixed ID. - artifact_keys: one yf1 year-file identity and one bl3 baseline identity for every level, with policyengine-core's version in the key, and store paths under year-files/ and baselines/. - plan_artifacts_impl(bucket, country) plans through the handlers; one build function serves every level's year files; the baseline builder loads its year file through the level's prebuilt lookup; the precompute app takes --country, default us. - One mf2 manifest per country, recording each stored file's SHA-256 and size; the image's download step checks both, places files only under prebuilt/<country>/, refuses a file already in the image, another schema and another policyengine-core version. - The runtime reads every run's year file through the handlers, a national run's included; qualifying_baseline_identity asks the level handler for the baseline scope. - state_datasets.py is deleted; national_region_groups returns Stage 12's groups. The old tests of the replaced code are ported to the handlers. The US pins' digests, paths and IDs change in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The approved 1.6 · 1 design (section 2, "the cleaner version") replaces the ds1, sds1 and bl1 keys with one yf1 year-file identity and one bl3 baseline identity, adds policyengine-core's version to every key, moves the image's prebuilt files under prebuilt/<country>/<dataset>/<subset>/, and (section 4) publishes one mf2 manifest per country that records each file's SHA-256 and size. Section 8 lists which US pins that changes: every digest, store path, simulation ID and image folder, the key and manifest schema labels, and the manifest's entry order, bytes and digest. Those values are re-recorded from the new code for the same fixed inputs. What section 8 says must not change stays pinned as recorded on main (544ff62): the plan's targets (3 national year files, 60 group baselines in the 20 groups' order, 153 state year files sorted by code), select_work with and without force, which requests get a fixed baseline ID and which a random one, the refusal of an SPM selection without a capability, the hit, incomplete and miss outcomes, write-once republishing, the MANIFEST_DIGEST= output line, and the deployed marker's path and overwrite. The tests now build the fixed-ID requests with a dataset selection, which replaced dataset_is_default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The run_simulation app's images install neither persistence package, but levels_us and national_partition import stage12_runtime.partition, whose package __init__ imports policyengine_stage12_persistence. Each check runs in a fresh interpreter with both packages blocked. Found by the 1.6 · 4 environment-variable check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stage12_runtime/__init__.py imports the v2 database packages, which the run_simulation app's images don't install, so importing stage12_runtime.partition from levels_us and national_partition would stop those images from planning a precompute, looking up a run's prebuilt file, and importing the segmented national runner. The groups move to stage12_cache/partition.py, which imports nothing; stage12_runtime.partition, levels_us and national_partition all import them from there, so there is still one list. The user chose this over adding the database packages to the images (2026-11-26). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing) From review round 1: - test_each_setting_rotates_artifact_identity still called the deleted ds1 and bl1 key functions. It now checks that each SPM setting rotates the yf1 year-file key and the bl3 baseline key and storage ID; it passes. - On main, a UK current-law macro run over a group of nations on the default dataset gets a fixed baseline ID; the handlers gave it none. The new tests expect main's behaviour (failing). - prebuilt_dataset_folder must return no folder, not raise, when a country's settings fail to load (failing). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review round 1: - A UK current-law macro run over a group of nations on the default dataset is a national-level run again, whose scope is the group's cache key, so it keeps the fixed baseline ID it has on main. - prebuilt_dataset_folder loads a country's settings inside its error handling, so a failure there falls back to today's folders instead of failing the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review round 2: the identity stubs, the wrapper storage-ID fixture and a baseline-builder test still named the removed identity classes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One conflict, in the precompute app's module docstring: main states the baseline containers' own size (8 CPUs and 32 GiB), since the segment workers now request less, and this branch rewrote the docstring for the level handlers. The docstring keeps the handler wording with main's size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review round 3: a source file's manifest entry must carry its sf1 identity digest, as the other kinds carry theirs, and run_precompute, which has nothing to copy source files with yet, must stop before starting any build when a plan needs one, instead of failing to publish after every other build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review round 3: - A source file's plan entry carries its sf1 identity digest, and its manifest entry records that digest, as the other kinds do. - run_precompute stops before starting any build when the plan needs a source file, since nothing copies one into the store yet (2.2 · 4 adds it), instead of failing to publish after every other build. - The executor README describes the prebuilt/ image folders, the per- country download step and its checks, and prebuilt_dataset_folder, in place of the state-datasets/ folders and the deleted baked_state_data_folder. - The import check without the v2 database packages also covers simulation_runtime, baseline_artifacts and precompute. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 26, 2026 17:58
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
Since the precompute moved onto the level handlers (#1132), the image keeps year files and baselines under prebuilt/<country>/<dataset>/<subset>/, and a run finds its year file through simulation_runtime._prebuilt_folder, which returns no folder for a year file the image lacks or .py wouldn't reuse. The tests now expect the warm-up to: - calculate group 1's precomputed current-law request from the US group-of-states handler, for the first prebuilt year, with a reform added; - look up its baked inputs as a run of that request does: the region and dataset resolution, the prebuilt-folder lookup and the precompute's baseline identity, with the baseline beside the year file; - clean up in the prebuilt folder, where outputs are now saved; - read none of the workers' Secrets, under any name the code reads them by. A new test fails the old module outright: with a module the warm-up uses made unimportable, the app must still import and the hook only log a warning. With main merged in, the old module's import-time imports made the whole app fail to import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
#1132 moved the precompute onto the level handlers: it deleted state_datasets.py, replaced the precompute planning names the warm-up imported, and moved baked files under prebuilt/<country>/. With that in main, the warm-up module failed to import, and app.py, which imports it, failed with it. - The group and year come from the US group-of-states handler: group 1's current-law request for the first prebuilt year, with the reform added. Group 1 is still state/hi+state/ia+state/wi, the group both measurements used. - The baked inputs are found as a run of that request finds them: region and dataset resolution, then simulation_runtime._prebuilt_folder, which returns no folder for a year file the image lacks or .py wouldn't reuse; the baseline is the precompute's own identity for the group, beside the year file. Either missing skips the warm-up with a warning. - The cleanup looks in the prebuilt folder, where outputs are now saved. - Every executor module the warm-up uses is imported when it runs, so a later move or rename in them only costs the warm-up, with a warning, instead of stopping the app from importing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
…anch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
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 #1127
What changes
The run_simulation app's prebuilt year files and current-law baselines are planned, built, listed and looked up through handlers that take a country and a dataset level, as the approved design for tracker task 1.6 · 1 sets out. The US builds the same files as before and its results don't change, but the files get new keys and a new place in the image.
stage12_cache/levels.py,levels_us.py,levels_uk.py). Six dataset levels: US national, group of states, state and district; UK national, nation and local area. Each handler is key-free. It says which year files and baselines a year builds and writes the year files. For a run, it gives the year file and prebuilt folder the run reads, and whether the run's current-law baseline gets a fixed ID. The US settings build today's files: 3 national year files, 153 state year files and 60 group-of-states baselines, for 2026, 2027 and 2025. The UK settings build nothing yet and keep the UK-wide fixed ID. The handlers sit instage12_cache/so the v2 report app can use them next (task 1.6 · 3). They import none of the run_simulation modules that the Stage 12 import test forbids.artifact_keys.py). Oneyf1year-file key and onebl3baseline key for every level, plussf1for source files copied whole (no handler returns one yet). Every key includes policyengine-core's version, and the default dataset's hash now comes from the release manifest, like a state file's. Store paths areyear-files/…andbaselines/…. Simulation IDs change frombl1-…tobl3-….precompute_planning.py,precompute_datasets.py,precompute_baselines.py,precompute.py,src/modal/precompute_app.py).plan_artifacts_impl(bucket, country)asks each level for its files. One build function serves every level's year files. The baseline builder downloads its year file into the prebuilt folder and loads it through that level's lookup, so each stored baseline is computed on the file the image holds.run_precomputestarts each baseline once the year file it reads has been built, and runs one determinism check (a fresh recompute of one stored baseline, compared column by column) per level that computed baselines. The precompute takes--country, defaultus, somodal-precompute.shand the workflow run unchanged.precompute_models.py,artifact_store.py,src/modal/_image_setup.py,src/modal/app.py). Onemf2manifest per country. Each entry records the stored file's SHA-256 and size, which uploads now record as object metadata. The download step checks both on every file before moving it into place. It places files only underprebuilt/<country>/, and refuses a file already in the image, a manifest of another schema, and a manifest built for another policyengine-core version.app.pyresolves each country's manifest from its own variable; only the US has one,POLICYENGINE_MANIFEST_DIGEST, as before.baseline_artifacts.py,simulation_runtime.py). Every run with a level reads its year file through the handlers, a national run included: it now readsprebuilt/us/<default dataset>/all/. A run falls back to today's folders when its file is missing or fails .py's reuse checks.qualifying_baseline_identityasks the level handler for the baseline scope. A lookup failure never fails a request.state_datasets.py, theds1/sds1/bl1identities, the per-state plan and manifest models, and the hard-codedPRECOMPUTE_COUNTRYandPRECOMPUTE_YEARS.stage12_cache/partition.py, which Stage 12's partition, the US handlers andnational_partitionall import. The design namedstage12_runtime.partitionas their home, but that package's__init__imports the v2 database code, which the run_simulation images don't install, so importing it there would stop those images from starting and planning.tests/test_prebuilt_imports.pyimports the handlers with those packages blocked. The groups are the same, group for group and in order.Where the code differs from the design
main, a UK current-law run over a group of nations (for example England plus Wales) on the default dataset gets a fixed ID. The design's UK levels leave that case out, so the UK national handler also covers it, reading the UK national year file, and the set of runs with fixed IDs is the same as onmain. Results don't change either way, since nothing UK is prebuilt.POLICYENGINE_CORE_VERSION, which comes from the version .py's bundle declares. Both are 3.33.3. If a relock ever made them differ, the image build would stop at the download step with a stale-manifest error.What stays the same, and how it's shown
The first commit pins what
main(544ff628) did, for fixed inputs: the plan's files, which requests get a fixed baseline ID, thehit,incompleteandmissoutcomes, the state-folder lookup rule, write-once publishing, theMANIFEST_DIGEST=output line and the deployed marker. Those assertions are unchanged. The design changes the keys, paths, IDs, image folders and manifest bytes, so their pinned values change in their own commit, with the design's reason. The newyf1,bl3andmf2golden digests were computed from the design's payloads withhashlib, independently of the code, and the code produces them.Rollout
src/modal/app.pyis also edited by draft Report in worker telemetry whether each call's container was restored from a memory snapshot #1124, in other functions. Whichever merges second resolves any text conflict.POLICYENGINE_CORE_VERSION, which the deploy job passes from the bundle's versions intoVERSION_ENVinapp.py, so it is set in the image. Unverified without GitHub or Modal settings access, and unchanged here: thePOLICYENGINE_ARTIFACT_BUCKETvariable andGCP_CREDENTIALS_JSONsecret in each GitHub environment, and the key names in the Modal secretgcp-credentials.Checks run
mainwas merged in, found no bug either, and four small items, all fixed: a source file's manifest entry now records itssf1key; the precompute stops before any build when a plan needs a source file it can't copy yet; the executor README describes theprebuilt/layout; and the database-free import check also covers the runtime and precompute modules.main(8ef36e5d) is merged in. The one conflict, the precompute app's module docstring, keeps main's statement of the baseline containers' size.src; Pyright passes for the executor package.🤖 Generated with Claude Code