Solution with lambdas
It looks like I can do this job using lambdas to generate unique function descriptors when initializing my objects. For odeint compatibility, I need to define my functions so that the first two arguments are time and initial state:
def my_ode(t, y, u, K, tau): return K*u/tau - y/tau
Next, I can initialize MyThing objects using lambdas to set K and tau as:
thing1 = MyThing(lambda t, y, u: my_ode(t, y, u, 10.0, 0.5), 0.0)
The function descriptor assigned to thing1.ode is now the function descriptor returned by the lambda (this may not be the right way to say this) with values ββfor K and tau . Now in thing1.update I need to make some changes to make it work with odeint :
def update(self, t_step, t_end, u): t_array = np.arange(self.time, t_end, t_step)
One thing that confused me a bit is that any additional arguments in ODE should be passed as a tuple to odeint . It looks like what I want.
There is also a more object-oriented approach using scipy.integrate.ode , which allows for the phased integration of the function and is great for my modeling goals. To do this, I install the ODE object and update it with something like:
class MyThing(): def __init__(self, ode, y0): self.ode = integrate.ode(ode) # define the ODE self.ode.set_integrator("dopri5") # choose an integrator self.ode.set_initial_value(y0) def update(self, u, t_step): """Update the ODE step-wise.""" self.ode.set_f_params(u) # need to pass extra parameters with this method self.ode.integrate(self.ode.t + t_step) # step-wise update return self.ode.successful() def get_output(self): """Get output from ODE function.""" return self.ode.y