Avoid error message in opti and continue loop

694 views
Skip to first unread message

rskr...@gmail.com

unread,
Mar 28, 2021, 10:38:32 AM3/28/21
to CasADi
Hello everyone,

I am performing a Monte Carlo analysis of a parametric optimal control problem using Opti(). I am using parfor to solve them in parallel. But when a infeasible problem is detected by ipopt, the solver stops and error message is thrown. How do I override the error message and finish the other problem instances?


ide govers

unread,
Mar 29, 2021, 2:30:18 AM3/29/21
to CasADi
Hi,

I think you are looking for the either a try-except logic (if there is an actual error). However, if your program does finish (no error), but the solver says your problem is infeasible, you can filter the solution status using:
solver.stats()['return_status'].

I hope this is helpful,

Ide Govers


Op zondag 28 maart 2021 om 16:38:32 UTC+2 schreef rskr...@gmail.com:

sandeep kumar r

unread,
Mar 29, 2021, 2:47:48 AM3/29/21
to ide govers, CasADi
Yeah. Looking something similar to try and catch. I was using fmincon from matlab early where output flag was generated and iterations kept continuing. However with ipopt the loop stops whenever an error occurs. I wanted to find a method to override the message and keep continuing the loop.  There is a workaround for something similar when max iterations are reached i.e. solve_limited. Looking for something similar to exit the ipopt solver silently with an output flag.

--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to a topic in the Google Groups "CasADi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casadi-users/ZZZjrGKiR24/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casadi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/casadi-users/1885046d-6764-4d0c-9257-971b0d4b089cn%40googlegroups.com.

Joris Gillis

unread,
Mar 31, 2021, 6:28:20 PM3/31/21
to CasADi
Hi,

The recommended way is try-catch.
Setting option error_on_fail to false may also work for you:

opti.solver('ipopt',struct('error_on_fail', false))

rskr...@gmail.com

unread,
Apr 1, 2021, 5:05:05 AM4/1/21
to CasADi
  Hi Joris,

I tried what you had suggested but it is not working. Here is a minimal working example which I took. The given problem is infeasible and I had set error on fail to false but I don't get the desired behavior. 

import casadi.*

opti=casadi.Opti();
x=opti.variable();
y=opti.variable();

obj=x*x+y*y;
con=[x+y-10;2*x+2*y-10];

opti.minimize(obj)
opti.subject_to(con==0)

option=struct;
option.error_on_fail=false;
opti.solver('ipopt',option)
sol=opti.solve();
sol.value([x y])
Reply all
Reply to author
Forward
0 new messages