<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>The zvode docs say that mode 5 returns the exact time answer and not an interpolated result.</div><div><br></div><div>Paul<br><br></div><div><br>On Mar 2, 2015, at 17:43, Benny Malengier <<a href="mailto:benny.malengier@gmail.com">benny.malengier@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-03-02 6:49 GMT+01:00 Paul Nation <span dir="ltr"><<a href="mailto:nonhermitian@gmail.com" target="_blank">nonhermitian@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">When using the single-step mode in either the VODE or ZVODE ode solver, the default mode (2) called in:<br><br> def step(self, *args):<br> itask = self.call_args[2]<br> self.call_args[2] = 2 <span style="white-space:pre-wrap"> </span># Step mode is here<br> r = self.run(*args)<br> self.call_args[2] = itask<br> return r<br><br><div>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:</div></div></blockquote><div><br></div><div>You do obtain the output at the requested time though, it is only an interpolated value of the actually computed solutions. <br></div><div>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 <br><br></div><div>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. <br></div><div><br></div><div>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.<br></div><div><br></div><div>Benny<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><div>def step(self, *args):</div><div> itask = self.call_args[2]</div><div> self.rwork[0] = args[4] #Set to stop time</div><div> self.call_args[2] = 5 #Set single step mode to stop at requested time.</div><div> r = self.run(*args)</div><div> self.call_args[2] = itask</div><div> return r</div></div><div><br></div><div>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.</div><div><br></div><div>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</div><div><br></div><div><div>ode._y = new_vec</div><div>ode._integrator.call_args[3] = 1</div></div><div><br></div><div>when I want to accomplish this. Adding support for a “fast reset” might also be a good thing to have in SciPy. </div><div><br></div><div>All of the code to accomplish such things are already being used in the QuTiP monte carlo solver(<a href="https://github.com/qutip/qutip/blob/master/qutip/mcsolve.py" target="_blank">https://github.com/qutip/qutip/blob/master/qutip/mcsolve.py</a>) and would therefore be fairly painless to add to SciPy.</div><div><br></div><div>Best regards,</div><div><br></div><div>Paul</div><div><br></div><div><br></div></div><br>_______________________________________________<br>
SciPy-Dev mailing list<br>
<a href="mailto:SciPy-Dev@scipy.org">SciPy-Dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/scipy-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/scipy-dev</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>SciPy-Dev mailing list</span><br><span><a href="mailto:SciPy-Dev@scipy.org">SciPy-Dev@scipy.org</a></span><br><span><a href="http://mail.scipy.org/mailman/listinfo/scipy-dev">http://mail.scipy.org/mailman/listinfo/scipy-dev</a></span><br></div></blockquote></body></html>