Repository navigation
Request 1 CPU and 10 GiB for the segment workers - #1126
Merged
Merged
Conversation
A segment child calculates one household group in one process. Measured on Modal, it keeps one CPU busy and peaks at about 3.4 GiB of resident memory with both countries' models loaded, so the 8 CPUs and 32 GiB it requests are mostly unused. The test now expects the SimulationSegmentWorker class and the plain run_simulation_segment function to request 1 CPU and 6 GiB, and the national workers to keep 8 CPUs and 32 GiB. It fails until the requests change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A segment child calculates one household group in one process. Measured on Modal, it keeps 0.9-1.0 of a CPU busy, calculates as fast with 1 CPU and 6 GiB as with 8 CPUs and 32 GiB, and peaks at 3.0 GB without memory snapshots and at about 3.4 GiB in a restored container that holds both countries' models. So the SimulationSegmentWorker class and the plain run_simulation_segment function now request 1 CPU and 6 GiB. At list price, the 20 children of a segmented national run cost about a sixth as much. The memory value is a request, not a hard limit. The national workers keep 8 CPUs and 32 GiB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The precompute app's description said its baseline containers are sized like the production run_simulation_segment workers, and its test was named for matching them. The segment workers now request 1 CPU and 6 GiB, while the baseline containers keep 8 CPUs and 32 GiB, so the description states that size and the test is named for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on Modal testing with memory snapshots and both countries' models loaded, a segment child peaks at about 3.4 GiB for a year whose dataset and current-law baseline are baked into the image (2026), and at about 6.9 GiB for a year whose dataset and baseline it builds itself (2028). 6 GiB covers only the first. The test now expects the SimulationSegmentWorker class and the plain run_simulation_segment function to request 1 CPU and 10 GiB. It fails until the request changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A measurement on Modal testing ran four segment worker classes with memory snapshots: 8 or 1 CPU, with or without a warm-up calculation in the snapshot hook. On the same machine type, restored 1-CPU containers calculated within 5 % of 8-CPU ones, and started within 1-2 s of them. For 2026, whose dataset and baseline are baked into the image, peak memory was the same on both CPU counts: about 3.4 GiB, or 3.6 GiB with the warm-up. A 2028 calculation, run only on 1 CPU, builds its year's dataset and baseline itself and peaked at about 6.9 GiB, or 7.2 GiB with the warm-up. So the SimulationSegmentWorker class and the plain run_simulation_segment function now request 10 GiB instead of 6 GiB. At list price, 1 CPU and 10 GiB cost about a fifth as much per second as 8 CPUs and 32 GiB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
anth-volk
marked this pull request as ready for review
November 26, 2026 14:49
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 #1125
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed. (changelog.d/1125.changed.md)Summary
The segment children of a segmented national run now request
cpu=1.0, memory=10240(1 CPU, 10 GiB) instead ofcpu=8.0, memory=32768, in both places that size them:SimulationSegmentWorkerclass, which has memory snapshots and is whatsegmented_national.pyspawns;run_simulation_segmentfunction, kept without snapshots for callers still running the code from before the classes.SimulationWorkerand the plainrun_simulationkeep 8 CPUs and 32 GiB. The diff touches only those resource arguments, their test and a changelog fragment; it doesn't change the snapshot hooks or the telemetry code.The precompute app's description said its baseline containers are sized like the segment workers. They keep 8 CPUs and 32 GiB, so the description now states that size, and the test
test_compute_baseline_matches_segment_worker_shapeis renamedtest_compute_baseline_requests_8_cpus_and_32_gib.Why 1 CPU
A child calculates one region group (a set of states) in one process, which uses one CPU. Measured on Modal
testing, 20 groups for 2026, 2 repetitions per request size, without memory snapshots:Measured with memory snapshots, and why 10 GiB
A second measurement on Modal
testingdeployed four segment worker classes with memory snapshots: 8 or 1 CPU, with or without a warm-up calculation in the snapshot hook (a planned change, tracker task 1.5 · 8). Each class ran 8 containers that took snapshots, then 8 restored containers. 128 calculations, no failures.Starting: containers that took the snapshot started a median 52.8 s after being queued on 1 CPU, against 57.7 s on 8 CPUs (123.2 s against 145.4 s with the warm-up). Restored containers started within 1–2 s of 8-CPU ones, sooner in one batch and later in the other.
Calculating: on the same machine type, restored 1-CPU containers ran 0.98–1.03 times the 8-CPU medians, with or without the warm-up. Results were identical across all four classes on each machine type.
Memory (peak container memory, highest of 8 containers; it doesn't depend on the CPU count):
A year outside the precomputed ones (2025–2027) builds its dataset and current-law baseline in the call, which needs more than 6 GiB. 10 GiB leaves 3.1 GiB for that case, or 2.8 GiB with the warm-up. An integer
memory=is a request, not a hard limit, so a call that needs more isn't stopped by a limit.Cost: CPU and memory are each billed by the larger of the request and the use. At list price, 1 CPU and 10 GiB costs about a fifth as much per second as 8 CPUs and 32 GiB. The first measurement's 1-CPU container time for the 20 groups comes to $0.084–$0.088 at that rate, against $0.36–$0.46 with 8 CPUs and 32 GiB.
Checked in production after deploy
The production check compares the medians of restored segment children's time from enqueue to models loaded, and of their calculation time, with the same medians for restored 8-CPU segment children before this change. Each may be at most 5 % slower. Snapshots are tied to the CPU type, so the 1-CPU class takes new snapshots after deploy.
Merge order
This was to merge only after the restore check (tracker task 1.5 · 3) had recorded production times for restored segment children on 8 CPUs, so that its before-and-after numbers measure the snapshots alone. That's done: 17 restored segment children from one report took a median 8.1 s from enqueue to models loaded, and calculated in a median 86.5 s under that report's reform. Those are the "before" figures for this change's production check. Calculation time depends on the reform, so the check should compare a report with the same reform where it can. When to merge is the maintainer's call.
#1124, which also edits
src/modal/app.py, merged before this branch's last push; the branch merges withmainwithout conflicts. Task 1.5 · 8's warm-up would raise a restored container's peak memory by 0.2–0.3 GiB; the measurement above covers it.Environment variables
The change reads and declares none. Both changed workers keep
secrets=[gcp_secret, hf_secret](Modal secretsgcp-credentialsin environmentmain, andpe-uk-private-hf-read-token, which must holdHUGGING_FACE_TOKEN), and the test asserts them.Testing
tests/test_modal_bundle_image.py::test_simulation_workers_are_classes_restored_from_memory_snapshots: failed before each resource change (1 CPU and 6 GiB, then 10 GiB), passes after it.tests/test_precompute_app.py::test_compute_baseline_requests_8_cpus_and_32_gib(renamed) passes.scripts/run_quality_guards.py, and the changelog fragment check.🤖 Generated with Claude Code