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

NLopt doesn't catch ForcedStop for some optimizers #158

Closed
ivborissov opened this issue Jan 26, 2021 · 1 comment
Closed

NLopt doesn't catch ForcedStop for some optimizers #158

ivborissov opened this issue Jan 26, 2021 · 1 comment

Comments

@ivborissov
Copy link

Hello @stevengj

It seems, ForcedStop termination doesn't work for a number of gradien-based algorithms (or these algorithms handle ForcedStop condition differently). The MWE is the following:

using NLopt

function myfunc(x::Vector, grad::Vector)

  if x[1] > 5.
    throw(NLopt.ForcedStop())
  elseif length(grad) > 0
    grad[1] = 1.
  end
  return x[1]
end

for alg in [:LN_NELDERMEAD, :LN_SBPLX, :LN_COBYLA, :LN_PRAXIS, :LN_BOBYQA, :LD_MMA, :LD_SLSQP, :LD_CCSAQ, :LD_LBFGS, :LD_TNEWTON, :LD_VAR2, :LD_VAR1]
  opt = Opt(alg, 1)
  opt.upper_bounds = [1e3]
  opt.xtol_rel = 1e-3
  opt.max_objective = myfunc
  (minf,minx,ret) = optimize(opt, [1.])

  println("$alg returned $ret status")
end

LN_NELDERMEAD returned FORCED_STOP status
LN_SBPLX returned FORCED_STOP status
LN_COBYLA returned FORCED_STOP status
LN_PRAXIS returned FORCED_STOP status
LN_BOBYQA returned FORCED_STOP status
LD_MMA returned FORCED_STOP status
LD_SLSQP returned FORCED_STOP status
LD_CCSAQ returned FORCED_STOP status
LD_LBFGS returned FAILURE status
LD_TNEWTON returned FAILURE status
LD_VAR2 returned FAILURE status
LD_VAR1 returned FAILURE status
@odow
Copy link
Member

odow commented Mar 3, 2022

They all return FORCED_STOP, it was just that some solvers were failing before x[1] was greater than 5.

julia> using NLopt

julia> function myfunc(x::Vector, grad::Vector)
           throw(NLopt.ForcedStop())
           return x[1]
       end
myfunc (generic function with 1 method)

julia> for alg in [:LN_NELDERMEAD, :LN_SBPLX, :LN_COBYLA, :LN_PRAXIS, :LN_BOBYQA, :LD_MMA, :LD_SLSQP, :LD_CCSAQ, :LD_LBFGS, :LD_TNEWTON, :LD_VAR2, :LD_VAR1]
         opt = Opt(alg, 1)
         opt.upper_bounds = [1e3]
         opt.xtol_rel = 1e-3
         opt.max_objective = myfunc
         (minf,minx,ret) = optimize(opt, [1.])

         println("$alg returned $ret status")
       end
LN_NELDERMEAD returned FORCED_STOP status
LN_SBPLX returned FORCED_STOP status
LN_COBYLA returned FORCED_STOP status
LN_PRAXIS returned FORCED_STOP status
LN_BOBYQA returned FORCED_STOP status
LD_MMA returned FORCED_STOP status
LD_SLSQP returned FORCED_STOP status
LD_CCSAQ returned FORCED_STOP status
LD_LBFGS returned FORCED_STOP status
LD_TNEWTON returned FORCED_STOP status
LD_VAR2 returned FORCED_STOP status
LD_VAR1 returned FORCED_STOP status

@odow odow closed this as completed Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants