nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

SLSQP fails with RoundoffLimited: NLopt roundoff-limited on Python

Open leom97 opened this issue 1 year ago • 1 comments

SLSQP keeps on failing on a fairly standard optimization problem:

import nlopt
import numpy as np

N = 5
C = np.eye(N)

def f(x, grad):
  if grad.size > 0:
    g = np.reshape(np.dot(C, x), (N,))
    grad[:] = g

  return 0.5 * np.dot(x, np.dot(C, x))

def h(x, grad):
  if grad.size > 0:
    grad[:] = 2*x
  return np.dot(x,x) - 1

opt = nlopt.opt(nlopt.LD_SLSQP, N)
opt.set_min_objective(f)
opt.add_equality_constraint(h)
opt.set_lower_bounds([0] * N)

w0 = np.ones(N)/N
w = opt.optimize(w0.copy())

I get RoundoffLimited: NLopt roundoff-limited, am I doing something wrong?

leom97 avatar Mar 09 '24 00:03 leom97

It's not really failing. You didn't set a tolerance, so it runs until it hits the limits of floating-point precision. The answer should still be useful.

stevengj avatar Mar 09 '24 18:03 stevengj