Skip to content

laser.measles.compartmental.snapshot

laser.measles.compartmental.snapshot

Snapshot save/load for the laser-measles compartmental model.

Snapshots capture the full patch SEIR state at a given point in time and allow the simulation to be resumed exactly from that point.

Typical usage::

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import laser.measles as lm
from laser.measles.compartmental import save_snapshot, load_snapshot
from laser.measles.compartmental.components import InfectionProcess

# --- Segment 1 ---
model1 = lm.CompartmentalModel(scenario, params1)
model1.components = [InfectionProcess]
model1.run()
save_snapshot(model1, "checkpoint.h5")

# --- Segment 2 ---
params2 = lm.CompartmentalParams(start_time="2001-01", num_ticks=365)
model2 = load_snapshot("checkpoint.h5", params2, components=[InfectionProcess])
model2.run()

Notes

  • Do not include InfectionSeedingProcess in the components list for a resumed run — infections are already encoded in the restored patch states.
  • Snapshots persist SIACalendarProcess's implemented_sias state. When resumed with SIACalendarProcess in the components list, campaigns already applied before the snapshot will not fire again; only campaigns not yet implemented in the schedule remain eligible.

laser.measles.compartmental.snapshot.load_snapshot(path, params, components=None, verbose=True)

Load a compartmental model from an HDF5 snapshot file and return it ready to run.

Restores the patch SEIR state, scenario, and metadata saved by save_snapshot. Set params.start_time to the snapshot date printed by save_snapshot. Do not include InfectionSeedingProcess in the components list — infections are already encoded in the restored patch states.

Parameters:

Name Type Description Default
path str | Path

Path to the HDF5 snapshot file written by save_snapshot.

required
params CompartmentalParams

CompartmentalParams for the resumed segment. Set start_time to the snapshot date and num_ticks to the remaining duration.

required
components list | None

Ordered list of component classes to attach — same list as used when building the original model, minus InfectionSeedingProcess.

None
verbose bool

Print a loading summary.

True

Returns:

Type Description
CompartmentalModel

A configured CompartmentalModel instance. Call model.run() to continue the simulation.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
```python
import laser.measles as lm
from laser.measles.compartmental import load_snapshot
from laser.measles.compartmental.components import InfectionProcess

params2 = lm.CompartmentalParams(num_ticks=365, seed=42, start_time="2001-01")
model2 = load_snapshot(
    "checkpoint.h5", params2, components=[InfectionProcess]
)
model2.run()
```

laser.measles.compartmental.snapshot.save_snapshot(model, path, verbose=True)

Save compartmental model patch state to an HDF5 snapshot file.

Call this after CompartmentalModel.run() to persist the full patch SEIR state. The resulting HDF5 file can be resumed with load_snapshot to continue the simulation from exactly where it left off.

Parameters:

Name Type Description Default
model CompartmentalModel

A fully-run (or mid-run) CompartmentalModel instance.

required
path str | Path

Destination HDF5 file path (created or overwritten).

required
verbose bool

Print a progress summary.

True

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
```python
import laser.measles as lm
from laser.measles.compartmental import save_snapshot
from laser.measles.compartmental.components import (
    InfectionSeedingProcess,
    InfectionProcess,
)

params = lm.CompartmentalParams(num_ticks=365, seed=42, start_time="2000-01")
model = lm.CompartmentalModel(scenario, params)
model.components = [InfectionSeedingProcess, InfectionProcess]
model.run()

save_snapshot(model, "checkpoint.h5")
```