Can sim.save() and sim.load() save and restore the whole Sim object? #765
|
I am trying to see whether I can run the simulation using starsim in python, save the whole simulation into a file using I did a simple simulation and saved it into file
However, when I opened a new jupyter notebook and tried to load the file
|
Replies: 1 comment 2 replies
|
Hi @lampk , thanks for your inquiry! The issue is that import starsim as ss
# Run and save the sim
sim = ss.Sim(diseases='sir', networks='random')
sim.run()
sim.save('sim.obj')
# Load and plot the sim
sim2 = ss.Sim.load('sim.obj')
sim2.plot()(Note that by default this saves a "shrunken" version of the sim, which includes the results but not all the details of all the agents. To save the complete sim exactly as-is, for example if you want to save partway through a run and then restart the run, use However, I agree this is confusing behavior, so I've created an issue here to change it from |
Hi @lampk , thanks for your inquiry! The issue is that
Sim.loadis a static method, which means that it creates a newSiminstance rather than modifying the existing one. If you assignSim.load()to a new variable, then it works, e.g.:(Note that by default this saves a "shrunken" version of the sim, which includes the results but not all the details of all the agents. To save the complete sim exactly as-is, for example if you want to save partway through a run and then restart the run, use
sim.save(sh…