Unable to implement ipopt solver for nlp

1,556 views
Skip to first unread message

Raushan Prabhakar

unread,
Apr 29, 2020, 7:37:13 AM4/29/20
to CasADi
I am new to casadi.I am writing the code for the mpc for mobile robots as taking the reference of this(https://www.youtube.com/results?search_query=mpc+casadi). In this video, he implemented on the Matlab but I am writing code in python, but got stuck here. 
Pleae Help

Original exception was:
Traceback (most recent call last):
  File "working.py", line 107, in <module>
    solver=nlpsol('solver','ipopt',nlp_prob,options)
  File "/usr/local/lib/python3.6/dist-packages/casadi/casadi.py", line 16673, in nlpsol
    return _casadi.nlpsol(*args)
RuntimeError: .../casadi/core/function_internal.cpp:144: Error calling IpoptInterface::init for 'solver':
Error in Function::factory for 'nlp' [SXFunction] at .../casadi/core/function.cpp:1634:
Failed to create nlp_grad_f:[x, p]->[f, grad:f:x] with {}:
.../casadi/core/factory.hpp:367: Gradient generation failed:
Error in SX::gradient at .../casadi/core/generic_matrix.hpp:1203:
.../casadi/core/generic_matrix.hpp:1200: Assertion "ex.is_scalar()" failed:
'gradient' only defined for scalar outputs: Use 'jacobian' instead.



Thanks

Joris Gillis

unread,
Apr 29, 2020, 7:58:38 AM4/29/20
to CasADi
Check the shape of your objective.
Apparently it is not scalar, while it should..

Joris

Raushan Prabhakar

unread,
Apr 29, 2020, 11:33:56 PM4/29/20
to Joris Gillis, CasADi
Thanks a lot, Joris

--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to the Google Groups "CasADi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casadi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/casadi-users/707f11d5-0c67-4ffe-98d1-a433e7b0f328%40googlegroups.com.

Raushan Prabhakar

unread,
Apr 30, 2020, 8:23:42 PM4/30/20
to Joris Gillis, CasADi
I am trying to solve the nlp,but got this error. Please help me out.
 RuntimeError: .../casadi/core/function_internal.cpp:1821: 'eval_sx' not defined for IpoptInterface

Joris Gillis

unread,
May 1, 2020, 7:07:40 AM5/1/20
to CasADi
You are attempting to call an Ipopt solver instance with SX variables, either explictly or implicitly through an 'expand' action (with 'expand' method or with 'expand' option). Don't do that and the error will disappear..

Joris

Dishan Desai

unread,
Jan 16, 2021, 10:13:26 PM1/16/21
to CasADi
I am getting the same error working on a very similar code. I do not recall using any expand method for my code. I am also relatively new to casadi. The error I am getting is:


  Message=.../casadi/core/function_internal.cpp:1832: 'eval_sx' not defined for IpoptInterface
  Source=C:\My drive\thesis_Code\single_shoot_new\single_shoot_new\single_shoot_new.py
  StackTrace:
  File "C:\........\single_shoot_new.py", line 88, in <module>
    sol = solver(x0= au0,lbx = LowerBX, ubx = UpperBX, lbg = LowerG, ubg = UpperG, p = PositionA)

my solver function is:

nlp_prob = {'f':obj,'x':OPT_variables,'g':g,'p':P}

solver = nlpsol('solver','ipopt',nlp_prob)

Joris Gillis

unread,
Feb 6, 2021, 3:37:37 PM2/6/21
to CasADi
Dear Dandes,

Check the type() of au0, LowerBX, UpperBX, LowerG, UpperG, PositionA.
One of these is probably an SX. It should be numeric/DM or MX, not SX.

Best regards,
  Joris

Prashant lokur

unread,
Mar 10, 2022, 10:26:49 AM3/10/22
to CasADi
So is it possible to convert SX to MX as I have a constraint as function of state and state is defined as SX 

Kamil Etxagibel Begic

unread,
May 29, 2022, 12:11:11 PM5/29/22
to CasADi
Dear Prashan,

I have the same problem as you, but I have not been able to find a solution anywhere, so if you have managed to solve it please let me know how.

Best regards,
Kamil
El dia dijous, 10 de març de 2022 a les 16:26:49 UTC+1, prashan...@gmail.com va escriure:
Reply all
Reply to author
Forward
0 new messages