nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

NLopt roundoff-limited error from simple example

Open imbacalvin opened this issue 3 years ago • 1 comments

I saw https://www.reddit.com/r/cpp_questions/comments/k6743d/nlopt_round_off_error/ and translated it to Python.

import nlopt

def obj_fn(x,grad):
    print("%.16f,%.16f"%(x[0],x[1]))
    print("%.16f"%(-x[0]+x[1]))
    return -x[0]+x[1]

opt = nlopt.opt(nlopt.LN_COBYLA,2)
opt.set_lower_bounds([-3.0,-3.0])
opt.set_upper_bounds([3.0,3.0])
opt.set_min_objective(obj_fn)
opt.set_ftol_abs(1)
opt.optimize([-1.5,-1.5])
print(opt.last_optimize_result())

The python version also always throws an nlopt roundoff-limited error. Do you think there is a bug causing this? More generally, what should we do to avoid hitting nlopt roundoff-limited errors? Thanks!

imbacalvin avatar Aug 18 '22 16:08 imbacalvin

indeed it seems the ftol criterion (nlopt_stop_ftol function) is not called when it should be, xtol criterion works though: opt.set_ftol_abs(1e-6)

jschueller avatar Nov 10 '24 09:11 jschueller