PyCall.jl
PyCall.jl copied to clipboard
Using Casadi from Julia
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?
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?
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