Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ debugging nlopt #474

Open
TomasMerva opened this issue Oct 6, 2022 · 3 comments
Open

C++ debugging nlopt #474

TomasMerva opened this issue Oct 6, 2022 · 3 comments

Comments

@TomasMerva
Copy link

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?

@GenieTim
Copy link

GenieTim commented Nov 7, 2022

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.

@GenieTim
Copy link

GenieTim commented Nov 8, 2022

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();
}

@TomasMerva
Copy link
Author

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, ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants