NLopt.jl
NLopt.jl copied to clipboard
LD_SLSQP does not terminate on NaN
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
Does the ~/.julia/NLopt/test/tutorial_jump.jl
example work?
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)
What does "MWE" mean?
Minimal working example, sorry.
The hang is apparently inside JuMP code, but doesn't occur when another solver like Ipopt is used. Pretty strange.
It's not hanging, it's just iterating without converging.
Which part is iterating?
NLopt
What are the termination criteria? I don't see any tolerances.
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
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?