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

Closed
joehuchette opened this issue Jan 28, 2015 · 14 comments
Closed

LD_SLSQP does not terminate on NaN #31

joehuchette opened this issue Jan 28, 2015 · 14 comments
Labels
upstream A bug or issue in the upstream library

Comments

@joehuchette
Copy link

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
Collaborator

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

@joehuchette
Copy link
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
Collaborator

What does "MWE" mean?

@joehuchette
Copy link
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
Collaborator

stevengj commented Feb 2, 2015

Which part is iterating?

@mlubin
Copy link
Member

mlubin commented Feb 2, 2015

NLopt

@stevengj
Copy link
Collaborator

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
@odow odow added the upstream A bug or issue in the upstream library label Aug 19, 2024
@odow
Copy link
Member

odow commented Aug 21, 2024

@stevengj I'd appreciate your feedback on this issue. What is the expected behavior when functions or gradients return NaN?

I bumped into this during https://github.com/JuliaOpt/NLopt.jl/pull/239/files#diff-1c91bbf6e133c9ebca6c69381a02bb628595d0216a3a095e281ddba57d495b9cR236-R237

@odow
Copy link
Member

odow commented Aug 22, 2024

It seems like this is a known issue with some algorithms. stevengj/nlopt#38

But it is intended behavior for others: stevengj/nlopt#279 (comment)

So perhaps we just close this issue and deal with the consequences. No one else has come along to comment in nearly 10 years.

@odow
Copy link
Member

odow commented Aug 22, 2024

The conclusion of the monthly developer call is that we should close this issue because it is nearly 10 years old, and because it is a "feature" of the upstream library. We shouldn't intercept NaN calls in NLopt.jl. (I'll also file this away as related to jump-dev/JuMP.jl#3664. It'd be good to be able to evaluate starting points of nonlinear programs to detect feasibility, gradients, etc.)

@odow odow closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream A bug or issue in the upstream library
Development

No branches or pull requests

4 participants