[SciPy-Dev] Updates to VODE and ZVODE solvers in single step mode

Paul Nation nonhermitian at gmail.com
Mon Mar 2 00:49:19 EST 2015


When using the single-step mode in either the VODE or ZVODE ode solver, the default mode (2) called in:

    def step(self, *args):
        itask = self.call_args[2]
        self.call_args[2] = 2 	# Step mode is here
        r = self.run(*args)
        self.call_args[2] = itask
        return r

results in taking a single step that (typically) goes beyond the output time requested in the solver.  When doing, for example, monte carlo algorithms, this leads to a big performance hit because one must take a step back, reset the solver  and then use the normal mode to go to the requested stop time.  Instead, these solvers support a mode (5) that will never step beyond the end time.  The modified step function is in that case:

def step(self, *args):
        itask = self.call_args[2]
        self.rwork[0] = args[4]    #Set to stop time
        self.call_args[2] = 5       #Set single step mode to stop at requested time.
        r = self.run(*args)
        self.call_args[2] = itask
        return r

Currently in order to implement this, one needs to create their own ODE integrator subclass of VODE or ZVODE, overload the step function, then create an ode instance and then finally add the custom integrator using ode._integrator.  I think supporting both options natively would be a nice thing to have in SciPy.

In addition, often it is not necessary to do a full reset of the ode solver using ode.reset().  Often times one just needs to change the RHS vector (and possibly the time) and set the flag for the solver to start anew (ode._integrator.call_args[3] = 1).  This to results in a large performance benefit for things like monte carlo solving. Right now I need to call

ode._y = new_vec
ode._integrator.call_args[3] = 1

when I want to accomplish this.  Adding support for a “fast reset” might also be a good thing to have in SciPy.  

All of the code to accomplish such things are already being used in the QuTiP monte carlo solver(https://github.com/qutip/qutip/blob/master/qutip/mcsolve.py <https://github.com/qutip/qutip/blob/master/qutip/mcsolve.py>) and would therefore be fairly painless to add to SciPy.

Best regards,

Paul


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150302/9703c6ab/attachment.html>


More information about the SciPy-Dev mailing list