scipy: LSODA implementation of dense output yields incorrect result
I am using solve_ivp with LSODA to integrate an ODE in the presence of an event; the event function and the solve_ivp call look like
def interrupt_integration(t, y, *tuple_of_args):
return y[0] - initial_value / 1e5
interrupt_integration.terminal = True
interrupt_integration.direction = -1
sol = solve_ivp(func, integration_range, [initial_value], method="LSODA", t_eval=t_values,
events=interrupt_integration, args=tuple_of_args,
first_step=1e-9, max_step=np.inf, rtol=5e-4, atol=5e-7,
jac=jac, lband=0, uband=0, min_step=1e-11)
I am experiencing an issue following the occurrence of the event. Specifically, the value of y calculated by LSODA differs from the one returned by the call to the interpolant generated by LsodaDenseOutput. I obtain the following
0.002851754215052383 [1.21218232e-05] 1.2e-05 1.218231563465635e-07
0.0029674726381464737 [7.54816189e-06] 1.2e-05 -4.451838114260822e-06
0.002851754215052383 [1.19125649e-05] 1.2e-05 -8.743505742940739e-08
0.0029674726381464737 [7.54816189e-06] 1.2e-05 -4.451838114260822e-06
The values printed correspond to t, y, initial_value / 1e5 and y[0] - initial_value / 1e5. On the first line, one can see that the returned value from the event is positive, hence the event is inactive. On the second line, however, the returned value is negative and the event becomes active. As a result, solve_event_equation within ivp.py is called and the third and fourth lines are produced. The fourth line is identical to the second line, which is the expected behaviour but, in the third line, the value of y differs from that in the first line, meaning that the value calculated by the interpolant from LsodaDenseOutput is incorrect.
I have had a look at _dense_output_impl within lsoda.py, but this is beyond my knowledge. Does anyone have an idea of why the interpolant yields an erroneous value at the lower end of the interpolation range?
Scipy/Numpy/Python version information:
Python 3.9.6, Numpy 1.21.1, Scipy 1.7.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (14 by maintainers)
@Patol75, I’m less busy now and can start taking a look at this next week. I’m a little astonished at how accurately I gauged when I would have time to do it. It will probably take me a couple weeks to properly review because I’m a little rusty on this stuff.
Yes, thanks for the reminder. I still want to take a look at this but have been extremely busy. I can’t promise anything but will do my best to get to it within a couple months. Please ping me again in two months if I haven’t started looking into it by then.