Skip to content

Instantly share code, notes, and snippets.

@pfeffer90
Created January 5, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfeffer90/d72da2dae55b2d85890f94b99a69e6ba to your computer and use it in GitHub Desktop.
Save pfeffer90/d72da2dae55b2d85890f94b99a69e6ba to your computer and use it in GitHub Desktop.
How to pickle and repickle a scipy vode ode solver, see [stackoverflow question](https://stackoverflow.com/questions/48096655/scipy-pickle-an-ode-solver-instance)
import scipy.integrate
import dill
## Restart the ode solver
file_name='ode_instance.pkl'
with open(file_name, "r") as ode_file:
ode_solver = dill.load(ode_file)
ode_solver.integrate(2)
print ode_solver.t, ode_solver.y
import scipy.integrate
import dill
# Solve a simple ode up to some time t
rhs= lambda t, y: -y
ode_solver = scipy.integrate.ode(rhs).set_integrator('vode')
ode_solver.set_initial_value(1)
ode_solver.integrate(1)
print ode_solver.t, ode_solver.y
## Stop solving and persist ode solver to a file
file_name='ode_instance.pkl'
with open(file_name, "w") as ode_file:
dill.dump(ode_solver, ode_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment