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

SLSQP fails with RoundoffLimited: NLopt roundoff-limited on Python #550

Open
leom97 opened this issue Mar 9, 2024 · 1 comment
Open

Comments

@leom97
Copy link

leom97 commented Mar 9, 2024

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?

@stevengj
Copy link
Owner

stevengj commented Mar 9, 2024

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.

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