Suppress ipopt output

3,487 views
Skip to first unread message

Danilo Caporale

unread,
Jul 25, 2017, 7:46:33 AM7/25/17
to CasADi
Hi all,

I'm using CasADi to setup an optimization problem in C++ that I want to call repeatedly with different parameters, in a for loop.
To speed up the loop I would like to suppress the output of ipopt (solver I'm using for the nlp), saving only a return value each time the solver is called, for instance a boolean set to true if the optimal solution has been found, false otherwise.
Is this possible? I have tried reading both the CasADI C++ API docs and ipopt manual and it seems like i need to set the "print_level" option to 0, but I was unable to do it.

As an example:

//// C++ Code
SXDict nlp = {{"x",x},{"f",f},{"g",constraints}};
Dict opts_dict = Dict();
Function solver = nlpsol("solver","ipopt",nlp,opts);

If I try to do

//// C++ Code
opts_dict["print_level"] = 0;


I get an error at runtime:
Unknown option: print_level

Did you mean one of the following?
> "print_time"          [OT_BOOL]      "print information about execution time"
> "compiler"          [OT_STRING]      "Just-in-time compiler plugin to be used."
> "con_string_md"          [OT_DICT]      "String metadata (a dictionary with lists of strings) about constraints to be passed to IPOPT"
> "ipopt"          [OT_DICT]      "Options to be passed to IPOPT"
> "output_scheme"          [OT_STRINGVECTOR]      "Custom output scheme"
Use print_options() to get a full list of options.


Is there a way to achieve this? It seems a pretty useful thing to do (and it surprised me that I couldn't find on the web a solution). Probably it's trivial and I'm not getting it.

Thank you all in advance.

Best,

Danilo Caporale

Joris Gillis

unread,
Jul 25, 2017, 7:56:39 AM7/25/17
to CasADi
print_level is an ipopt-specific option. You can set it through setting the ipopt option to an appropriate dict, or using shorthand syntax
["ipopt.print_level"] = 0;
Probably you also want to set print_time (which is not an ipopt-specific option)

Danilo Caporale

unread,
Jul 25, 2017, 8:30:03 AM7/25/17
to CasADi
Thanks Joris,

I'll leave here an example code in case anyone else has this problem in the future.

// C++ Code
SXDict nlp = {{"x", x},{"f", J},{"g", constraints}};
Dict opts_dict=Dict();
opts_dict["ipopt.print_level"] = 0;
opts_dict["ipopt.sb"] = "yes";
opts_dict["print_time"] = 0;
Function solver = nlpsol("solver", "ipopt", nlp, opts_dict);

// For the return value
std::string retstat = solver.stats().at("return_status");
if(retstat.compare("Solve_Succeeded") == 0) // Solve_succeeded hardcoded flag
{
    std::cout << "OK succeeded"<<std::endl;
    return true;
}
else
{
    std::cout << "KO succeeded"<<std::endl;
    return false;
}


Thanks!

Best,

Danilo

Wanxin Jin

unread,
Dec 6, 2019, 7:13:36 PM12/6/19
to CasADi
thank you so much, this has helped me alot!!!!
Reply all
Reply to author
Forward
0 new messages