Skip to content

scipy/legacy-odeint

Rule legacy-odeint
Pack SciPy
Severity info
Fix none, edit by hand
Library versions every version

SciPy's docs say new code should use solve_ivp instead of odeint. Switch to solve_ivp, and note that it takes t before y.

ys = odeint(lambda y, t: -k * y, y0, t)
ys = solve_ivp(lambda t, y: -k * y, (t[0], t[-1]), y0, t_eval=t).y.T

The rule reports integrate.odeint, because SciPy's docs ask new code to use solve_ivp. Neither solver was faster on every problem measured, so the message makes no claim about speed. The message also tells you what changes when you switch:

  • solve_ivp raises ValueError when t_eval repeats a time, which odeint accepts.
  • The values differ in the last digits.
  • Keep the default method of solve_ivp for a large system, because method='LSODA' stores a full Jacobian and raised MemoryError at 1,000,000 equations.

xpd has no automatic fix. Because solve_ivp calls fun(t, y) where odeint calls func(y, t), and returns an object. Make the change by hand.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

SciPy's docs say new code should use solve_ivp instead of odeint. Write solve_ivp(fun, (t0, t1), y0, t_eval=t) with fun taking t before y. solve_ivp raises ValueError when t_eval repeats a time, which odeint accepts, and its values differ from odeint's in the last digits. Keep its default method for a large system, because method='LSODA' stores a full Jacobian and ran out of memory at 1,000,000 equations.

Browse the other rules of the SciPy pack.