💾 Saving and Loading Simulation State
Memory
You can dump the current simulation state to memory by calling dump_state
:
If you want to save the state to a flat array, you can call dump_state
with serialized=True
:
You can then load the state back into the simulator by calling load_state
:
load_state
assumes object permanence!
load_state
assumes that the objects in the state match the objects in the current simulator. Only the state of the objects will be restored, not the objects themselves, i.e. no objects will be added or removed.
If there is an object in the state that is not in the simulator, it will be ignored. If there is an object in the simulator that is not in the state, it will be left unchanged.
Disk
Alternatively, you can save the state to disk by calling save
:
The number of json files should match the number of scenes in the simulator (by default, 1).
You can then load the state back into the simulator by calling og.clear()
first and then restore
:
restore
assumes an empty simulator!
Always remember to call og.clear()
, which clears the entire simualtor, before calling restore
.
Otherwise, the saved scenes will be appended to the existing scenes of the current simulator, which may lead to unexpected behavior.