I was experimenting with NLopt and created the following minimum working example, which consistently fails with RoundoffLimited: NLopt roundoff-limited
:
import numpy as np
import nlopt
dim = 1
def obj_func(x, grad):
return float( (x[0]-0.5)**2 )
opt = nlopt.opt(nlopt.LN_COBYLA, dim)
opt.set_min_objective(obj_func)
lb = np.zeros(dim)
ub = np.ones(dim)
opt.set_lower_bounds(lb)
opt.set_upper_bounds(ub)
opt.set_ftol_rel(1e-6)
x0 = np.random.uniform(low=lb, high=ub)
xopt = opt.optimize(x0)
I have absolutely no idea what I am doing wrong here, since basically every other MWE looks similar.