Add ensemble / scenario-sweep runner#10
Open
RyadT wants to merge 1 commit into
Open
Conversation
simulator/ensemble.py runs many simulations in parallel over two axes: replicates (same scenario, different seed -> uncertainty bands) and scenarios (different inputs, e.g. interventions -> comparison). The cross-product gives intervention comparison WITH confidence bands. Pure orchestration around the existing run_simulator (no core changes): a ProcessPoolExecutor runs each (scenario, replicate) with randseed=True and a reproducible per-task seed (SeedSequence.spawn); workers reduce the in-memory output to a per-timestep cumulative-infected series; results are aggregated into per-scenario percentile bands + a cross-scenario table. Throughput is memory-bound, not core-bound: under spawn (macOS dev) each worker re-decompresses the large patterns file, so unbounded workers thrash and run slower than serial. Mitigations: under fork (Linux deploy) the read-only data is shared via copy-on-write (loaded once in the parent); under spawn max_workers is capped. Measured (8 runs, dmp off, 96h): serial 6.2 runs/min, 9 workers 1.9 (thrash), 3 workers 12.7. Validated: masks_0.7 -> 479 [3,1025] vs baseline -> 16514 [2595,24547] cumulative infected; per-replicate variation confirmed (one seed fizzled at 1, others reached 24k); identical across worker counts (reproducible). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
A parallel runner for many simulations at once, over two axes:
The cross-product gives the headline capability: intervention comparison with confidence bands — e.g. masks-at-day-0 → 479 [3, 1025] vs no-intervention → 16,514 [2,595, 24,547] cumulative infected.
Pure orchestration around the existing
run_simulator— no core-simulator changes (so the golden still guards every underlying run).simulator/ensemble.py:ProcessPoolExecutorover(scenario, replicate)tasks; each runs withrandseed=Trueand a reproducible per-task seed (SeedSequence.spawn).python -m simulator.ensembleruns a baseline-vs-masks demo.Throughput is memory-bound, not core-bound (important)
Each worker needs the (large) patterns data. Measured — 8 runs, dmp off, 96h:
Under spawn (macOS dev) each worker re-decompresses the 65MB patterns → too many workers thrash RAM and run slower than serial. So:
max_workersis capped (defaultmin(cores, 4)).This is why the win is ~2× on this Mac but should scale closer to core-count on the Linux deploy. Tune
max_workersto RAM.Validated
[1, 17297, 24139, 24619]— one seed fizzled, others took off.Test plan
python -m simulator.ensemble ... --dmp-mode off— comparison + bands + variationmax_workersscale to cores--scenarios <json>for arbitrary intervention sweeps (librun_ensemble()already takes arbitrary scenarios)🤖 Generated with Claude Code