PyCall.jl icon indicating copy to clipboard operation
PyCall.jl copied to clipboard

Using Casadi from Julia

Open A-C1 opened this issue 4 years ago • 2 comments

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?

A-C1 avatar Jul 16 '21 10:07 A-C1

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?

mkitti avatar Aug 06 '21 09:08 mkitti

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

metab0t avatar Oct 27 '21 11:10 metab0t