nlopt
nlopt copied to clipboard
C++ debugging nlopt
Hi, I am sorry for maybe a vague question but is there a way to find out (debug/verbose/...) why nlopt fails? I am using C++ API and the only exception is that the nlopt returns nlopt failure after a few iterations and from that, I cannot find any clue. The numeric code of the result is a weird number (99968768). Therefore I would like to ask what can someone do in order to debug nlopt?
I am having the same issue (with LD_MMA, e.g., but different large numbers as result values). I am currently investigating the source code as to where such a result code could even come from, but to no luck so far.
What you can do is to use opt.set_param("verbosity", 1.0), but that barely helps.
I could tell you that this lack of debuggability is also the case when using the C interface, but that won't help you either, unfortunately.
Some further insights after stepping through my program:
- the result value is just the uninitialised value, coming from
opt.optimize()not returning anything but throwing the nlopt failure exception. That's why we have large, unrelated return values (assuming you too use the code as seen below) - in my case, the issue was that the "inner" function, the one I am optimising, threw an error – that gets caught by nlopt without further notice and results in the unhelpful "nlopt failure"
nlopt::result res = nlopt::result::SUCCESS; // use an initialisation here in order not to get the large number
std::exception_ptr nloptException = nullptr;
try {
res = opt.optimize(u0, minf); // if this throws, the error code is still in its initialised state
} catch (...) {
nloptException = std::current_exception();
}
I have found out, that that error code does not mean anything (as you said its just "random" value ). When I get this big value, I know that something is wrong in terms of implementation (wrong number of boundaries, C++ syntax error, wrong usage of nlopt functions, ...).