I'm having a similar issue also when just retrieving the derivatives, which I'd like to obtain for some further calculations, from the opti class.
In this case it seems to me that there's a bug or maybe I don't understand the logic behind and there's a smarter way to perform this operation.
U = opti.variable(nu, N)
...
H = casadi.hessian(opti.f, X) # this works, type is
casadi.casadi.MXz_vars = []
for i in range(N):
z_vars.append(U[:,i])
z_vars.append(X[:,i+1])
Z = casadi.vertcat(z_vars)
H = casadi.hessian(opti.f, Z) # DOESN'T work, throws:
RuntimeError Traceback (most recent call last)
<ipython-input-24-6b85bbe7f899> in <module>
----> 1 c.hessian(opti.f, Z)
/usr/local/python/casadi/casadi.py in hessian(*args)
12649 hessian(SX ex, SX arg) -> SX
12650 """
> 12651 return _casadi.hessian(*args)
12652
12653 def quadratic_coeff(*args) -> "casadi::Matrix< casadi::SXElem > &, casadi::Matrix< casadi::SXElem > &, casadi::Matrix< casadi::SXElem > &":
RuntimeError: Error in MX::hessian at .../casadi/core/mx.cpp:1679:
Error in MX::gradient at .../casadi/core/generic_matrix.hpp:1203:
Error in MX::jtimes at .../casadi/core/generic_matrix.hpp:1191:
Error in MX::reverse at .../casadi/core/mx.cpp:1741:
Error in Function::Function for 'reverse_temp' [MXFunction] at .../casadi/core/function.cpp:235:
.../casadi/core/function_internal.cpp:144: Error calling MXFunction::init for 'reverse_temp':
.../casadi/core/x_function.hpp:286: For reverse_temp: Xfunction input arguments must be purely symbolic.
Argument 0(i0) is not symbolic.
Now the type is the same, I'm not sure why reordering the vector with the derivatives should not work, I don't get the purely symbolic error, can someone help me out with this?