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

LD_SLSQP does not terminate on NaN #31

Open
joehuchette opened this issue Jan 28, 2015 · 11 comments
Open

LD_SLSQP does not terminate on NaN #31

joehuchette opened this issue Jan 28, 2015 · 11 comments

Comments

@joehuchette
Copy link
Member

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

@stevengj
Copy link
Member

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

@joehuchette
Copy link
Member Author

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)

@stevengj
Copy link
Member

What does "MWE" mean?

@joehuchette
Copy link
Member Author

Minimal working example, sorry.

@mlubin
Copy link
Member

mlubin commented Jan 28, 2015

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

@mlubin
Copy link
Member

mlubin commented Jan 31, 2015

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

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

Which part is iterating?

@mlubin
Copy link
Member

mlubin commented Feb 2, 2015

NLopt

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

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

@odow
Copy link
Member

odow commented Mar 3, 2022

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
Copy link
Member

odow commented Jan 25, 2023

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 odow changed the title Hangs in g_ineq when called from JuMP LD_SLSQP does not terminate on NaN Jan 25, 2023
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

4 participants