The Simulation Archive (SA) is a binary file that can be used to restart a simulation. This can be useful when running a long simulation. REBOUND can restart simulation exactly (bit by bit) when using a SA. There are some restriction to when a SA can be used. Please read the corresponding paper (Rein & Tamayo 2017) for details.
We first setup a simulation in the normal way.
In [1]:
import rebound
sim = rebound.Simulation()
sim.integrator = "whfast"
sim.dt = 2.*3.1415/365.*6 # 6 days in units where G=1
sim.add(m=1.)
sim.add(m=1e-3,a=1.)
sim.add(m=5e-3,a=2.25)
sim.move_to_com()
We then initialize the SA and specify the output filename and output cadence. We can choose the output interval to either correspond to constant intervals in walltime (in seconds) or simulation time. Here, we choose walltime. To choose simulation time instead replace the walltime
argument with interval
.
In [2]:
sim.automateSimulationArchive("simulationarchive.bin", walltime=1.,deletefile=True)
Now, we can run the simulation forward in time.
In [3]:
sim.integrate(2e5)
Depending on how fast your computer is, the above command may take a couple of seconds. Once the simulation is done, we can delete it from memory and load it back in from the SA. You could do this at a later time. Note that this will even work if the SA file was generated on a different computer with a different operating system and even a different version of REBOUND. See Rein & Tamayo (2017) for a full discussion on machine independent code.
In [4]:
sim = None
sim = rebound.Simulation("simulationarchive.bin")
print("Time after loading simulation %.1f" %sim.t)
If we want to integrate the simulation further in time and append snapshots to the same SA, then we need to call the automateSimulationArchive
method again (this is fail safe mechanism to avoid accidentally modifying a SA file). Note that we set the deletefile
flag to False
. Otherwise we would create a new empty SA file. This outputs a warning because the file already exists (which is ok since we want to append that file).
In [5]:
sim.automateSimulationArchive("simulationarchive.bin", walltime=1.,deletefile=False)
Now, let's integrate the simulation further in time.
In [6]:
sim.integrate(sim.t+2e5)
If we repeat the process, one can see that the SA binary file now includes the new snapshots from the restarted simulation.
In [8]:
sim = None
sim = rebound.Simulation("simulationarchive.bin")
print("Time after loading simulation %.1f" %sim.t)
A few things to note when restarting a simulation from a SA:
exact_finish_time=0
in a call to sim.integrate
.
In [ ]: