3

The function that I am using for solve_ivp is defined as:

def ydot(t,y,kappa4,kappa16):

Upon using solve_ivp as below:

sol=solve_ivp(ydot,[0,10],initial_condition(),args=(50,100))

I get the following error:

ydot() missing 2 required positional arguments: 'kappa4' and 'kappa16'

I am not able debug the code even though I have defined the function ydot the way scipy documentation for solve_ivp defines (https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html)

There's even an example in the end of the documentation that demonstrates the passing of arguments implemented in the same way as I have done.

I believe the problem is somewhere in the two above pieces of the code I have provided from an otherwise long code.

  • 1
    Hi Angad, even if 'I believe the problem is somewhere in the two above pieces of the code I have provided from an otherwise long code.' , please be kind to us and provide an MWE (minimal-reproducible-example) – Tejas Shetty Feb 24 '20 at 06:57
  • You can refer https://stackoverflow.com/help/minimal-reproducible-example – Tejas Shetty Feb 24 '20 at 06:58
  • 2
    Thanks. I am new to stack overflow. Didn't know about this. Consider the following minimal example: `def ydot(t,y,a): return -a*y` `sol=solve_ivp(ydot,[0,10],[5],args=(10))` I still get the same error for my argument **a**. – Angad Yuvraj Mar 03 '20 at 09:10
  • 1
    Does my answer fix your problem? – Tejas Shetty Mar 03 '20 at 17:03

2 Answers2

2

I was able to replicate the error with scipy 1.1.0 . Upgrading scipy to the latest version via cmd (pip install scipy==1.4.1) solved that error message for me.

Then the minimal reproducible example gave another error:

TypeError: ydot() argument after * must be an iterable, not int

Which was solved by the solution given by Tejas. The full working minimal script is hence:

from scipy.integrate import solve_ivp

def ydot(t,y,a): return -a*y

sol=solve_ivp(ydot,[0,10],[5],args=(8,))
print(sol.y)
Joris
  • 1,158
  • 1
  • 16
  • 25
  • I updated scipy package using `!conda install --yes --prefix {sys.prefix} scipy` on my jupyter notebook (currently using os 10.13.4 High Sierra) referring the article [https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/] and it updated the scipy package to 1.2.1 instead of 1.4.1 – Angad Yuvraj Mar 11 '20 at 13:22
  • perhaps scipy 1.2.1 also does the job? In any case i have no experience with macOS but probably you can also use "conda/pip install scipy==1.4.1"? – Joris Mar 11 '20 at 14:02
  • The error is unresolved with scipy 1.2.1 as also pointed by @Tejas in the post [https://stackoverflow.com/questions/48245765/pass-args-for-solve-ivp-new-scipy-ode-api?rq=1] – Angad Yuvraj Mar 17 '20 at 11:56
  • Is it resolved for you with scipy 1.4.1 ? Can you make the upgrade? – Joris Mar 18 '20 at 12:48
  • The command "conda/pip install scipy==1.4.1", is it supposed to be executed from Jupyter notebook? – Angad Yuvraj Mar 20 '20 at 15:07
  • you need to execute "pip install scipy==1.4.1" from the command line / terminal / any way you call it in macOS – Joris Mar 23 '20 at 08:32
  • 1
    @Joris Upgrding scipy solved the problem in my case. – Karlo Sep 29 '20 at 16:37
1

I had faced the same issue recently. But the great Warren Weckesser helped me out. Change

args=(10)

to

args=(10,)

and your MWE will work fine. This happens because of tuples with a single element. For reference see pg 30 of Python tutorial pdf (Release 3.5.1) on python.org

Tejas Shetty
  • 685
  • 6
  • 30