laser.measles.abm.snapshot
laser.measles.abm.snapshot
Snapshot save/load for the laser-measles ABM.
Snapshots capture the full population and patch 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 | |
Notes
save_snapshotmodifies the model in place: R agents are squashed and vaccination dates are normalized. Do not continue using the model after saving.- The caller is responsible for setting
params.start_timein the resumed segment to match the snapshot date (printed byload_snapshot). WPPVitalDynamicsProcessis supported with the same guard mechanism.
laser.measles.abm.snapshot.load_snapshot(path, params, components=None, verbose=True)
Load an ABM from an HDF5 snapshot file and return it ready to run.
Restores the population, patch state, scenario, and metadata saved by
save_snapshot. Components
that modify the people frame (e.g.
VitalDynamicsProcess)
detect the snapshot context via model._from_snapshot and skip frame
setup. Set params.start_time to the snapshot date printed by
save_snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the HDF5 snapshot file written by
|
required |
params
|
ABMParams
|
|
required |
components
|
list | None
|
Ordered list of component classes to attach — same list as used when building the original model. |
None
|
verbose
|
bool
|
Print a loading summary. |
True
|
Returns:
| Type | Description |
|---|---|
ABMModel
|
A configured |
Example:
1 2 3 4 5 6 7 8 9 10 11 | |
laser.measles.abm.snapshot.save_snapshot(model, path, squash_recovered=True, verbose=True)
Save ABM state to an HDF5 snapshot file.
Call this after ABMModel.run()
to persist the full population and patch state. The resulting HDF5 file
can be resumed with
load_snapshot to continue
the simulation from exactly where it left off — useful for warm-start
parameter sweeps, segmented cluster jobs, or reproducible checkpoints.
Warning
This function mutates model: recovered agents are squashed
(if squash_recovered=True) and future vaccination dates are
normalized. Do not continue running the model after calling this
function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
ABMModel
|
A fully-run (or mid-run)
|
required |
path
|
str | Path
|
Destination HDF5 file path (created or overwritten). |
required |
squash_recovered
|
bool
|
If |
True
|
verbose
|
bool
|
Print a progress summary. |
True
|
Example:
1 2 3 4 5 6 7 8 9 10 11 | |