Repository navigation
Split the artifact and Stage 12 cache precompute modules under the file-length limit - #938
Merged
Merged
Conversation
anth-volk
force-pushed
the
file-length-split-precompute
branch
from
October 27, 2026 13:45
b509b93 to
64f1b35
Compare
2 tasks done
anth-volk
force-pushed
the
file-length-split-precompute
branch
4 times, most recently
from
October 27, 2026 16:30
91e5eec to
bafaee6
Compare
Base automatically changed from
file-length-split-stage12-runtime-tests
to
main
October 27, 2026 16:52
precompute.py (931 lines), stage12_cache/precompute.py (844 lines) and tests/test_precompute.py (1,835 lines) were over the file-length limits. The code moves unchanged. Each precompute module keeps its manifest functions, its functions dataclass and run_precompute, and re-exports every public name in __all__, so the Modal precompute apps, which import the step functions from it when they run, are unchanged. The steps move to three modules next to it: - precompute_planning.py: cohorts or baseline identities, the state dataset targets, plan_artifacts_impl and select_work - precompute_datasets.py: the national and per-state dataset builds - precompute_baselines.py: computing the baselines and checking that they are deterministic Private names another module now uses are public: the artifact precompute's _cohort_resolution, and the cache precompute's _scoped_planned_simulation (with a new docstring) and _baseline_identity. stage12_worker_validation.py imports scoped_planned_simulation from the cache's precompute_planning.py. tests/test_precompute.py keeps the schema, planning and orchestration tests; the rest move to test_precompute_planning.py, test_precompute_datasets.py and test_precompute_baselines.py, all 71 tests unchanged apart from patch targets. Each patch now targets the module whose code reads the name: the planning tests patch state_dataset_targets and cohort_identity in precompute_planning, the state dataset tests patch state_dataset_targets in precompute_datasets, and the determinism tests patch _prepare_cohort_baseline in precompute_baselines. In the cache tests, the planning fixture and the state-target test patch precompute_planning, the state build fixture patches precompute_datasets, the determinism tests patch precompute_baselines, and the store helper replaces Stage12CacheStore in all four modules, each of which opens the store. The file-length baseline drops the three files (count 7 to 4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
file-length-split-precompute
branch
from
October 27, 2026 16:52
bafaee6 to
710debe
Compare
anth-volk
marked this pull request as ready for review
October 27, 2026 17:00
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 #937
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
Sixth of nine stacked PRs; it builds on #936. It splits the artifact precompute, the Stage 12 cache precompute and the precompute tests without changing behaviour, and removes all three from the file-length baseline (count 7 to 4). For each source file, a script compared every top-level statement of the old module with the new modules: all appear exactly once and unchanged apart from the renames below, in their original order.
precompute.py(931 lines) andstage12_cache/precompute.py(844 lines)Both are split the same way. The original module keeps the manifest functions, the functions dataclass and
run_precompute, and re-exports every public name in__all__. The Modal precompute apps import the step functions from it inside their function bodies, so they, and the app tests that replace those functions on the module, are unchanged.precompute.py: manifest, functions dataclass,run_precompute, re-exportsprecompute_planning.py: cohorts or baseline identities, state dataset targets,plan_artifacts_impl,select_workprecompute_datasets.py: national and per-state dataset buildsprecompute_baselines.py: computing baselines and checking determinismRenames
Private names another module now uses are public:
_cohort_resolutiontocohort_resolution(artifact precompute), and_scoped_planned_simulationtoscoped_planned_simulation(docstring added) and_baseline_identitytobaseline_identity(cache precompute).stage12_worker_validation.pyimported_scoped_planned_simulationfrom the cache precompute; it now importsscoped_planned_simulationfromstage12_cache/precompute_planning.py.Tests
tests/test_precompute.py(1,835 lines) keeps the schema, planning and orchestration tests (575 lines); the rest move totest_precompute_planning.py(428),test_precompute_datasets.py(443) andtest_precompute_baselines.py(417). 71 tests before and after, with the same names; a script compared every class method and statement: all unchanged apart from patch targets.TestPlanArtifactsImplpatchescohort_identityandstate_dataset_targetsinprecompute_planning;TestBuildStateDatasetsImplpatchesstate_dataset_targetsinprecompute_datasets, where the state dataset build reads it;TestVerifyDeterminismImplpatches_prepare_cohort_baselineinprecompute_baselines.tests/test_stage12_cache_precompute.py, not split): thestubbed_planningfixture andtest_states_on_the_default_dataset_add_no_state_datasetspatchprecompute_planning, whichplan_artifacts_implreads;test_state_targets_follow_how_a_request_for_the_state_resolvespatches_country_modulethere too; thestate_buildfixture patchesprecompute_datasets; the determinism tests patch_ensure_dataset_file,scoped_planned_simulationandStage12CacheStoreinprecompute_baselines; and the_use_storehelper replacesStage12CacheStorein all four modules, each of which opens the store.test_planned_baseline_file_is_the_one_the_worker_saves_and_loadscallsscoped_planned_simulationfromprecompute_planning.tests/test_stage12_worker_validation.pystill patchesstate_dataset_targetson the cache precompute module, which the validation reads as a module attribute.Environment variables
No change: the moved code reads the same variables, in the same functions, and no workflow, image or deployment file changes.
Testing
python scripts/run_quality_guards.pyandpython -m scripts.rules guard --base-ref origin/file-length-split-stage12-runtime-tests: passed;python -m scripts.rules renderleaves no diff.Only the lowest PR in the stack runs full CI, so this PR's
CI completecheck fails by design until the PRs below it merge.🤖 Generated with Claude Code