How to snapshot and resume a simulation
This guide shows how to save a simulation checkpoint and resume from it in a new segment. For background on why snapshotting works this way and what is preserved, see Snapshotting.
Save an ABM snapshot
Run the first segment to completion, then save:
1 2 3 4 5 6 7 8 | |
save_snapshot prints a summary:
1 2 3 4 5 | |
Note the Resume with: line — you need this value for the next step.
Do not use the model after saving
save_snapshot mutates the ABM model (squashes R agents, normalizes
vaccination dates). Treat it as a terminal operation on model1.
Resume an ABM from a snapshot
Create new params with start_time matching the snapshot date, then load:
1 2 3 4 | |
You can also use the classmethod alias:
1 2 | |
start_time must match the snapshot date
Setting the wrong start_time causes date-dependent components (SIA
calendars, importation, age-based vaccination) to fire at incorrect
calendar times.
Save and resume a compartmental model
The procedure is the same, using compartmental classes:
1 2 3 4 5 6 7 8 9 10 | |
1 2 3 4 | |
Or using the classmethod alias:
1 2 | |
Exclude seeding from the second segment
Pass the same component list you used in segment 1 — except for InfectionSeedingProcess. Infections are already present in the restored state; re-seeding would create spurious infections.
1 2 3 4 5 | |
Similarly, do not include InitializeEquilibriumStatesProcess in the second segment — it would overwrite the loaded state.
Inspect a snapshot file
Snapshots are standard HDF5 files, readable with any HDF5-compatible tool:
1 2 3 4 5 6 7 8 | |
Or from the command line:
1 | |
See also
- Snapshotting — concepts, what is preserved, and ABM-specific behavior
- Worked examples — complete runnable scripts for all model types
- Troubleshooting — common pitfalls and error resolution