Checkpoints

You can easily save and load a REBOUND simulation to a binary file. The binary file includes all information about the particles (mass, position, velocity, etc), as well as the current simulation settings such as time, integrator choise, etc.

Let's add three particles to REBOUND and save them to a file.


In [1]:
import rebound
sim = rebound.Simulation()
sim.add(m=1.)
sim.add(m=1e-6, a=1.)
sim.add(a=2.)
sim.integrator = "whfast"
sim.save("checkpoint.bin")
sim.status()


---------------------------------
REBOUND version:     	3.8.0
REBOUND built on:    	Feb  3 2019 13:37:32
Number of particles: 	3
Selected integrator: 	whfast
Simulation time:     	0.0000000000000000e+00
Current timestep:    	0.001000
---------------------------------
<rebound.Particle object, m=1.0 x=0.0 y=0.0 z=0.0 vx=0.0 vy=0.0 vz=0.0>
<rebound.Particle object, m=1e-06 x=1.0 y=0.0 z=0.0 vx=0.0 vy=1.000000499999875 vz=0.0>
<rebound.Particle object, m=0.0 x=2.000000999999 y=0.0 z=0.0 vx=0.0 vy=0.7071081347393496 vz=0.0>
---------------------------------

The binary files are small in size and store every floating point number exactly, so you don't have to worry about efficiency or losing precision. You can make lots of checkpoints if you want!

Let's delete the old REBOUND simulation (that frees up the memory from that simulation) and then read the binary file we just saved.


In [2]:
del sim
sim = rebound.Simulation("checkpoint.bin")
sim.status()


---------------------------------
REBOUND version:     	3.8.0
REBOUND built on:    	Feb  3 2019 13:37:32
Number of particles: 	3
Selected integrator: 	whfast
Simulation time:     	0.0000000000000000e+00
Current timestep:    	0.001000
---------------------------------
<rebound.Particle object, m=1.0 x=0.0 y=0.0 z=0.0 vx=0.0 vy=0.0 vz=0.0>
<rebound.Particle object, m=1e-06 x=1.0 y=0.0 z=0.0 vx=0.0 vy=1.000000499999875 vz=0.0>
<rebound.Particle object, m=0.0 x=2.000000999999 y=0.0 z=0.0 vx=0.0 vy=0.7071081347393496 vz=0.0>
---------------------------------

Note that you will have to re-set any function pointers manually (if you're using them)