NLopt.jl icon indicating copy to clipboard operation
NLopt.jl copied to clipboard

LD_SLSQP does not terminate on NaN

Open joehuchette opened this issue 10 years ago • 11 comments

using JuMP
using NLopt
m = Model(solver=NLoptSolver(algorithm=:LD_SLSQP))
@defVar(m, c[1:2] >= 0)
@addConstraint(m, sum(c) <= 2)
@setNLObjective(m, Max, (c[1] + 0.7*c[2])^0.5 - (0.7*c[2])^0.5 + (c[2] + 0.7*c[1])^0.5 - (0.7*c[1])^0.5)
solve(m)

This hangs for a while, and when I manually exit, I get

ERROR: InterruptException:
 in eval_g at /Users/huchette/.julia/v0.4/JuMP/src/nlp.jl:274
 in g_ineq at /Users/huchette/.julia/v0.4/NLopt/src/NLoptSolverInterface.jl:179
 in nlopt_vcallback_wrapper at /Users/huchette/.julia/v0.4/NLopt/src/NLopt.jl:469
 in optimize! at /Users/huchette/.julia/v0.4/NLopt/src/NLopt.jl:509
 in optimize! at /Users/huchette/.julia/v0.4/NLopt/src/NLoptSolverInterface.jl:203
 in solvenlp at /Users/huchette/.julia/v0.4/JuMP/src/nlp.jl:491
 in solve at /Users/huchette/.julia/v0.4/JuMP/src/solvers.jl:9

cc @mlubin

joehuchette avatar Jan 28 '15 20:01 joehuchette

Does the ~/.julia/NLopt/test/tutorial_jump.jl example work?

stevengj avatar Jan 28 '15 21:01 stevengj

Yep, that one works great. MWE:

using JuMP, NLopt
m = Model(solver=NLoptSolver(algorithm=:LD_MMA)) # or :LD_SLSQP
@defVar(m, c >= 0)
@setNLObjective(m, Min, sqrt(c))
solve(m)

Edit: also,

using JuMP, NLopt
m = Model(solver=NLoptSolver(algorithm=:LD_MMA))
@defVar(m, 0 <= c <= 1)
@setNLObjective(m, Max, sqrt(c))
solve(m)

joehuchette avatar Jan 28 '15 21:01 joehuchette

What does "MWE" mean?

stevengj avatar Jan 28 '15 21:01 stevengj

Minimal working example, sorry.

joehuchette avatar Jan 28 '15 21:01 joehuchette

The hang is apparently inside JuMP code, but doesn't occur when another solver like Ipopt is used. Pretty strange.

mlubin avatar Jan 28 '15 22:01 mlubin

It's not hanging, it's just iterating without converging.

mlubin avatar Jan 31 '15 03:01 mlubin

Which part is iterating?

stevengj avatar Feb 02 '15 16:02 stevengj

NLopt

mlubin avatar Feb 02 '15 16:02 mlubin

What are the termination criteria? I don't see any tolerances.

stevengj avatar Feb 02 '15 16:02 stevengj

Just confirming that this is still a problem

using JuMP
import NLopt
m = Model(NLopt.Optimizer)
set_optimizer_attribute(m, "algorithm", :LD_SLSQP)
@variable(m, c[1:2] >= 0)
@constraint(m, sum(c) <= 2)
@NLobjective(m, Max, (c[1] + 0.7*c[2])^0.5 - (0.7*c[2])^0.5 + (c[2] + 0.7*c[1])^0.5 - (0.7*c[1])^0.5)
optimize!(m)

Although you could set time limits or tolerances to exit earlier:

julia> using JuMP

julia> import NLopt

julia> m = Model(NLopt.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: NLopt

julia> set_optimizer_attribute(m, "algorithm", :LD_SLSQP)

julia> set_optimizer_attribute(m, "maxtime", 3.0)

julia> @variable(m, c[1:2] >= 0, start = 0)
2-element Vector{VariableRef}:
 c[1]
 c[2]

julia> @constraint(m, sum(c) <= 2)
c[1] + c[2] ≤ 2.0

julia> @NLobjective(m, Max, (c[1] + 0.7*c[2])^0.5 - (0.7*c[2])^0.5 + (c[2] + 0.7*c[1])^0.5 - (0.7*c[1])^0.5)

julia> @time optimize!(m)
  3.005593 seconds (14.77 M allocations: 676.120 MiB, 4.12% gc time, 0.18% compilation time)

julia> termination_status(m)
TIME_LIMIT::TerminationStatusCode = 12

odow avatar Mar 03 '22 03:03 odow

So the issue is that the derivatives aren't defined at the default starting point of 0.0.

It seems like for this algorithm NLopt just lets NaN accumulate and doesn't error. Should it? Or are there some algorithms that support NaN and can recover?

odow avatar Jan 25 '23 02:01 odow