JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.47k stars 187 forks source link

Using Casadi from Julia #915

Open A-C1 opened 3 years ago

A-C1 commented 3 years ago

I am using Casadi from Julia and have the following code:

using PyCall
cd = pyimport("casadi")
opti = cd.Opti()
x = opti.variable()

This results in ValueError('call stack is not deep enough').

However, the following workaround works:

using PyCall
cd = pyimport("casadi")
opti = cd.Opti()
x = py"$(opti).variable()"

Also the code works fine when run directly in Python. What is the reason for this?

mkitti commented 3 years ago

It looks like the problem originates with Casadi trying to interrogate the call stack and failing. It's probably expecting to find a frame where the Python call was initiated, but that doesn't exist because you made the call from Julia. Perhaps file a ticket with Casadi and link here?

metab0t commented 2 years ago

The same problem as https://github.com/JuliaPy/PyCall.jl/issues/71.

The problem is caused by code at https://github.com/casadi/casadi/blob/12fa60f676716ae09aa2abe34c1c9b9cf426e68a/swig/casadi.i#L4403