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

Benny Malengier benny.malengier at gmail.com
Mon Mar 2 03:43:47 EST 2015


2015-03-02 6:49 GMT+01:00 Paul Nation <nonhermitian at gmail.com>:

> 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:
>

You do obtain the output at the requested time though, it is only an
interpolated value of the actually computed solutions.
So, the only reason you should do above is if something is happening at a
certain time and you want to change data or so. You mention monte carlo,
but I don't see how that is related to such a usecase in general. I suppose
in your application probably yes, but in general MC does not need this

The docs say only to use endtime if you have changing RHS or Jacobian, and
to otherwise not try to outsmart the solver, as the solver needs extra work
in case you set the endtime.

Note that (Z)VODE was replaced by CVODE by the authors of VODE, which has
many improvements and several python bindings, all of which expose setting
a stop time. In my view, VODE is only present in scipy as a first attempt
solver, to be replaced by more modern solvers for heavy lifting.

Benny


>
> 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) and would
> therefore be fairly painless to add to SciPy.
>
> Best regards,
>
> Paul
>
>
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150302/fbff180f/attachment.html>


More information about the SciPy-Dev mailing list