Discussion:
[NLopt-discuss] Problem with LD_SLSQP on a simple test-problem: f(x) = -x on [-1.0,1.0]
Alexander Riess
2011-01-05 14:44:42 UTC
Permalink
Hi,

i tried to solve a (simple) test-problem

min ( -1.0*x ) on [-1.0,1.0]

using LD_SLSQP on WinXP 64bit with Python 2.6.5 and the latest Nlopt package.

I used the following python input:

# === INPUT === START ===

# -*- coding: latin-1 -*-
import nlopt
from numpy import *

# Global iteration index
I = 0

# min -1.0*x on [-1,1] (Solution: xopt = 1 | fopt = -1.0 )
def f( x, grad ):
global I
I += 1
out = -1.0 * x[0]
grad[0] = -1.0
print str(I).ljust(15),str(x[0]).ljust(15),str(out).ljust(15),str(grad
[0]).ljust(15)
return out

opt = nlopt.opt(nlopt.LD_SLSQP, 1)
opt.set_lower_bounds( [-1.0 ] )
opt.set_upper_bounds( [ 1.0 ] )
opt.set_min_objective(f)
opt.set_xtol_rel(1e-6)
x0 = array([0.0])

print "Algorithm ", opt.get_algorithm_name(), "steps:\n"
print str("Iteration").ljust(15),str("x").ljust(15),str("f(x)").ljust(15),str
("f'(x)").ljust(15)
xOpt = opt.optimize(x0)
print "\nxopt = ", xOpt[0]
print "fopt = ", opt.last_optimum_value()

# === INPUT === END ===

This script results in

# === OUTPUT === START ===

Algorithm Sequential Quadratic Programming (SQP) (local, derivative) steps:

Iteration x f(x) f'(x)
1 0.0 -0 -1.0
2 1.0 -1.0 -1.0
Traceback (most recent call last):
File "minExample.py", line 26, in <module>
xOpt = opt.optimize(x0)
File "C:\Python265\lib\site-packages\nlopt.py", line 231, in optimize
def optimize(*args): return _nlopt.opt_optimize(*args)
RoundoffLimited: NLopt roundoff-limited

# === OUTPUT === END ===

What is the meaning of error-message "NLopt roundoff-limited"?
Why does it occur although x=1.0 is the final solution.

If i use, for example, algorithm LD_MMA with same input, everything works fine:

Algorithm Method of Moving Asymptotes (MMA) (local, derivative) steps:

Iteration x f(x) f'(x)
1 0.0 -0 -1.0
2 0.38196601125 -0.38196601125 -1.0
3 1.0 -1.0 -1.0
4 1.0 -1.0 -1.0

xopt = 1.0
fopt = -1.0

Yours sincerely

Alexander Riess
Steven G. Johnson
2011-01-13 15:22:43 UTC
Permalink
Thanks, this is a bug; in that case the original SLSQP had an
additional ftol convergence check, but not an xtol convergence check
(since I added the xtol stuff in NLopt). This will be fixed in the
next release, but for now a workaround is to use a nonzero ftol with
SLSQP.

(In general, as mentioned in the manual, a ROUNDOFF_LIMITED return
value still typically corresponds to a useful optimization result; at
worst it is less precise than you requested.)

A patch that adds the missing xtol check is attached below.

Steven

--- old-nlopt_0/slsqp/slsqp.c 2011-01-13 10:20:54.000000000 -0500
+++ new-nlopt_0/slsqp/slsqp.c 2011-01-13 10:20:55.000000000 -0500
@@ -1775,6 +1775,7 @@
double alpha;
int iexact;
int incons, ireset, itermx;
+ double *x0;
} slsqpb_state;

#define SS(var) state->var = var
@@ -2416,6 +2417,7 @@
slsqpb_(m, meq, la, n, &x[1], &xl[1], &xu[1], f, &c__[1], &g[1],
&a[
a_offset], acc, iter, mode, &w[ir], &w[il], &w[ix], &w[im],
&w[is]
, &w[iu], &w[iv], &w[iw], &jw[1], state);
+ state->x0 = &w[ix];
return;
} /* slsqp_ */

@@ -2436,7 +2438,7 @@
double *x, double *minf,
nlopt_stopping *stop)
{
- slsqpb_state state = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ slsqpb_state state = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,NULL};
unsigned mtot = nlopt_count_constraints(m, fc);
unsigned ptot = nlopt_count_constraints(p, h);
double *work, *cgrad, *c, *grad, *w,
@@ -2565,17 +2567,22 @@
break;
case 8: /* positive directional derivative for linesearch */
/* relaxed convergence check for a feasible_cur point,
- as in the SLSQP code */
+ as in the SLSQP code (except xtol as well as ftol) */
ret = NLOPT_ROUNDOFF_LIMITED; /* usually why deriv>0 */
if (feasible_cur) {
double save_ftol_rel = stop->ftol_rel;
+ double save_xtol_rel = stop->xtol_rel;
double save_ftol_abs = stop->ftol_abs;
stop->ftol_rel *= 10;
stop->ftol_abs *= 10;
+ stop->xtol_rel *= 10;
if (nlopt_stop_ftol(stop, fcur, state.f0))
ret = NLOPT_FTOL_REACHED;
+ else if (nlopt_stop_x(stop, xcur, state.x0))
+ ret = NLOPT_XTOL_REACHED;
stop->ftol_rel = save_ftol_rel;
stop->ftol_abs = save_ftol_abs;
+ stop->xtol_rel = save_xtol_rel;
}
goto done;
case 5: /* singular matrix E in LSQ subproblem */
Alexander Riess
2011-01-28 13:28:43 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...