Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1125.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Segment children of segmented national runs (the `SimulationSegmentWorker` class and the plain `run_simulation_segment` function) now request 1 CPU and 10 GiB instead of 8 CPUs and 32 GiB. A child calculates one region group (a set of states) in one process, so it uses one CPU. With both countries' models loaded it uses about 3.4 GiB for a precomputed year (2025–2027), and about 6.9 GiB for another year, whose dataset and current-law baseline it builds itself. At list price, the 20 children of a segmented national run cost about a fifth as much.
15 changes: 11 additions & 4 deletions projects/policyengine-simulation-executor/src/modal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,14 @@ def run_simulation(

@app.cls(
image=simulation_image,
cpu=8.0,
memory=32768,
# A segment child calculates one region group in one process, so it
# keeps one CPU busy. Measured on Modal with both countries' models
# loaded, it peaks at about 3.4 GiB for a year whose dataset and
# baseline are baked into the image, and at about 6.9 GiB for a year
# whose dataset and baseline it builds itself. The memory is a request,
# not a limit.
cpu=1.0,
memory=10240,
timeout=3600,
retries=0,
max_containers=300,
Expand Down Expand Up @@ -586,8 +592,9 @@ def run_simulation(

@app.function(
image=simulation_image,
cpu=8.0,
memory=32768,
# The same resources as SimulationSegmentWorker.
cpu=1.0,
memory=10240,
timeout=3600,
retries=0,
max_containers=300,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Wave 1 builds the single-year US datasets (one container per year), wave 2
computes the 20 per-cohort national baselines per year (one container per
cohort, sized like the production ``run_simulation_segment`` workers).
cohort, requesting 8 CPUs and 32 GiB).
Alongside both waves, one container per year and dataset filters the
regional dataset that state regions load into one year file per state. See
the library module for the idempotency, ``--force``, and determinism-gate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,35 +133,40 @@ def test_simulation_workers_are_classes_restored_from_memory_snapshots(monkeypat
function_options = dict(app.app.function_calls)
worker_options = {
"image": app.simulation_image,
"cpu": 8.0,
"memory": 32768,
"timeout": 3600,
"retries": 0,
"secrets": [app.gcp_secret, app.hf_secret],
"enable_memory_snapshot": True,
}
simulation_worker_resources = {"cpu": 8.0, "memory": 32768, "max_containers": 100}
# A segment child calculates one region group in one process, so it
# keeps one CPU busy. With both countries' models loaded it peaks at about
# 3.4 GiB for a year whose dataset and baseline are baked into the image,
# and at about 6.9 GiB for a year whose dataset and baseline it builds
# itself. 1 CPU and 10 GiB fit both.
segment_worker_resources = {"cpu": 1.0, "memory": 10240, "max_containers": 300}
# Two classes, so the segment children keep their own container pool: a
# blocking segmented parent must never share a bounded pool with the
# children it waits on.
assert class_options == {
"SimulationWorker": {**worker_options, "max_containers": 100},
"SimulationSegmentWorker": {**worker_options, "max_containers": 300},
"SimulationWorker": {**worker_options, **simulation_worker_resources},
"SimulationSegmentWorker": {**worker_options, **segment_worker_resources},
}
# Plain functions with the same names and limits stay, without a snapshot,
# for callers still running the code from before the classes: the gateway
# while a deploy is under way, and runs that started before it.
# Plain functions with the same names and resources stay, without a
# snapshot, for callers still running the code from before the classes:
# the gateway while a deploy is under way, and runs that started before it.
function_form_options = {
option: value
for option, value in worker_options.items()
if option != "enable_memory_snapshot"
}
assert function_options["run_simulation"] == {
**function_form_options,
"max_containers": 100,
**simulation_worker_resources,
}
assert function_options["run_simulation_segment"] == {
**function_form_options,
"max_containers": 300,
**segment_worker_resources,
}
# The budget-window parent stays a small plain function with no snapshot.
assert "enable_memory_snapshot" not in function_options["run_budget_window_batch"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_every_worker_function_carries_gcp_secret(precompute_module, name):
)


def test_compute_baseline_matches_segment_worker_shape(precompute_module):
def test_compute_baseline_requests_8_cpus_and_32_gib(precompute_module):
kwargs = _function_kwargs(precompute_module, "compute_baseline")
assert kwargs["cpu"] == 8.0
assert kwargs["memory"] == 32768
Expand Down