scipy: Bug in Solve_ivp with BDF and Radau solvers and numpy arrays

It seems Scipy integration module solve_ivp when used with BDF and Radau solvers appends rounded numbers to the array. This will then cause an error of inconsistent dimensional further on in my code. I wrote a simple example of a system with (2,1)-dimensional state (i.e. a second order system), which prints the state y as it runs in the function f(t,y), at one point, it appends the rounded number and gave me

[[ 13.67999979  13.67999999]
 [-15.99       -15.98999976]]

The second column is unnecessary and these added numbers will cause error in my original code.

Reproducing code example:

from numpy import array, matmul
from scipy.integrate import solve_ivp
from numpy import size
def sys(t,x,A,xeq,matmul,size):
    if size(x)==4:
        print(x)
    xdot=matmul(A,x-xeq)
    return xdot

T=10
A=array([[-1,2],[-2,-6]])
x0=array([13.67999999,-15.989999999])
xeq=array([[0.99999999],[2.999999999]])
fun=lambda t, x: sys(t,x,A,xeq,matmul,size)
sol=solve_ivp(fun,[0,T],x0,method='BDF',vectorized=True)

The output is:

[[ 13.67999979  13.67999999]
 [-15.99       -15.98999976]]

Scipy/Numpy/Python version information:

1.1.0 1.14.4 sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I believe this bug is bigger than appending rounded numbers to the array. I’m working with a very large system of ODEs (1000+ equations), and have found that when I use the vectorized=True option for solve_ivp the solver will attempt to pass a (n,n) matrix into the right-hand-side function, where n is the number of variables (n=1180 for the ODE system I’m working with).

I also agree that the documentation for the “vectorized” option is entirely unclear.

Why should there be a difference in the way BDF and Radau implemented with that of RK45 and RK23. Users should be able to easily change the method to observe speed, convergence, and accuracy of each method. Nonetheless, if there is difference, it should be explicitly stated. I will try to design a simple system of ODEs for which switching from RK45 to BDF yields an error of inconsistent dimension.