Created
January 5, 2018 10:13
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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