Skip to content
Draft
1 change: 1 addition & 0 deletions changelog.d/1146.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The v2 app's US workers, `SimulationSegmentWorkerUS` and `SimulationWorkerUS`, now run one warm-up calculation before Modal takes their memory snapshot, so a container restored from the snapshot starts with the year's parameter values built. The warm-up calculates the reform side of the first region group the v2 cache precomputes (Hawaii, Iowa and Wisconsin) for 2026, under a raised Child Tax Credit base amount, only in a container Modal takes a snapshot from. It reads no Modal Secret, opens no connection, sends no telemetry, doesn't count as a worker call and leaves nothing for later calls; a failure only logs a warning. Containers that take a snapshot start later by about one segment's calculation. The UK worker doesn't warm up yet.
6 changes: 5 additions & 1 deletion docs/engineering/skills/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ How a call tells them apart, in Modal 1.6.4:
the one serving the call.

Neither the restore nor the snapshot hook runs inside a call, so no span
measures them. Modal's container records (its `TaskGetInfo` call) give the
measures them. That includes the warm-up calculation that the versioned app's
workers and the v2 app's US workers run in the hook of a container Modal
snapshots (`src/modal/snapshot_warm_up.py`, `src/modal/v2_snapshot_warm_up.py`):
it opens no span or operation and takes no call number, so the container's
first call is still number 1. Modal's container records (its `TaskGetInfo` call) give the
times each container was queued and became ready (`enqueued_at` and
`started_at`), which include scheduling as well as the restore. A call's spans show the setup still left
in it:
Expand Down
43 changes: 19 additions & 24 deletions projects/policyengine-simulation-executor/src/modal/v2_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
from policyengine_simulation_executor.stage12_timeouts import (
COORDINATOR_TIMEOUT_SECONDS,
HOUSEHOLD_FUNCTION_TIMEOUT_SECONDS,
UK_SIMULATION_TIMEOUT_SECONDS,
US_SIMULATION_TIMEOUT_SECONDS,
)
from policyengine_simulation_observability.observability import (
init_process_observability,
Expand Down Expand Up @@ -77,6 +75,12 @@
uk_worker_image,
us_worker_image,
)
from src.modal.v2_snapshot_warm_up import warm_up_first_us_calculation
from src.modal.v2_worker_resources import (
SEGMENT_WORKER_RESOURCES,
UK_SIMULATION_WORKER_RESOURCES,
US_SIMULATION_WORKER_RESOURCES,
)

import modal

Expand Down Expand Up @@ -187,34 +191,22 @@ def validate_worker_uk() -> dict:
# code from before the classes: an entry service revision (the stable one
# during a deploy, or one a rollback routes traffic back to), and a coordinator
# or US worker call running while this app is redeployed in place. Both run the
# same calculation.
# same calculation. Their CPU, memory, time and container limits are in
# src/modal/v2_worker_resources.py.
_SEGMENT_WORKER_OPTIONS: dict[str, Any] = {
**SEGMENT_WORKER_RESOURCES,
"image": us_worker_image,
"cpu": 8.0,
"memory": 32768,
"timeout": 3600,
"retries": 0,
# Every segment of every US simulation call that may run at once: a
# segment queued behind this limit counts against its caller's wait.
"max_containers": 1000,
"secrets": worker_secrets,
}
_US_SIMULATION_WORKER_OPTIONS: dict[str, Any] = {
**US_SIMULATION_WORKER_RESOURCES,
"image": us_worker_image,
"cpu": 8.0,
"memory": 32768,
"timeout": US_SIMULATION_TIMEOUT_SECONDS,
"retries": 0,
# Both simulations of every coordinator call that may run at once. The
# simulation runs and cliff calculations the simulation service starts
# directly share the same containers.
"max_containers": 50,
"secrets": report_run_writer_secrets,
}
_UK_SIMULATION_WORKER_OPTIONS: dict[str, Any] = {
**_US_SIMULATION_WORKER_OPTIONS,
**UK_SIMULATION_WORKER_RESOURCES,
"image": uk_worker_image,
"timeout": UK_SIMULATION_TIMEOUT_SECONDS,
"secrets": report_run_writer_secrets,
}


Expand Down Expand Up @@ -386,9 +378,11 @@ class _V2CountryModelsLoadedBeforeSnapshot:
Modal runs ``snap=True`` hooks in every container that isn't restored, and
takes the memory snapshot from such a container when it starts it with
snapshots enabled; every container restored from the snapshot starts with
the loaded models in memory. ``snap=False`` hooks run after each restore.
Observability is configured per call instead, after the restore, so each
restored container reports its own process identity.
the loaded models in memory. The US workers' hook also runs one warm-up
calculation in a container Modal snapshots (``v2_snapshot_warm_up``).
``snap=False`` hooks run after each restore. Observability is configured
per call instead, after the restore, so each restored container reports
its own process identity.
"""

# The image's own country: a failed import of one country's models can't
Expand All @@ -398,10 +392,11 @@ class _V2CountryModelsLoadedBeforeSnapshot:

@modal.enter(snap=True)
def load_country_models(self) -> None:
"""Load the class's country models, and for the US the SPM capability."""
"""Load the country models, and for the US the SPM capability and a warm-up."""
with contextlib.suppress(Exception):
_CONTAINER_CALLS.record_snapshot_hook()
preload_country_models(self.snapshot_countries)
warm_up_first_us_calculation(self.snapshot_countries)

@modal.enter(snap=False)
def reseed_random_after_restore(self) -> None:
Expand Down
Loading