-
Notifications
You must be signed in to change notification settings - Fork 46
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
SLSQP in NLopt.jl 1.0.2 throws error: bug: more than iter SQP iterations
#215
Comments
That's weird, it's supposed to never reach that check, since we check the evaluation count elsewhere. |
I linked the wrong line. now corrected to L2585 I don't fully grasp the flow of the script (yet) but I can confirm that he throws: |
Do you have a reproducible example? |
I get the same error. Here is a MWE:
NLopt |
Experiencing the same issue, but only if I add inequality constraints, suggesting that this may be a fallthrough from |
I can confirm the failure, but this is an issue that should probably be reported to the upstream: https://github.com/stevengj/nlopt It has been reported before: stevengj/nlopt#215, but it is helpful to have the MWE. |
Here's a smaller example: julia> using NLopt
julia> function my_objective_fn(p::Vector, grad::Vector)
if length(grad) > 0
grad .= [1e8 * p[2]^2, 2e8 * p[1] * p[2]]
end
return 1e8 * (p[1] * p[2]^2)
end
my_objective_fn (generic function with 1 method)
julia> opt = Opt(:LD_SLSQP, 2)
Opt(LD_SLSQP, 2)
julia> lower_bounds!(opt, [0, -Inf])
julia> min_objective!(opt, my_objective_fn)
julia> optimize(opt, [1, -1])
ERROR: nlopt failure FAILURE: bug: more than iter SQP iterations
Stacktrace:
[1] error(::String, ::String)
@ Base ./error.jl:44
[2] chk(o::Opt, result::Result)
@ NLopt ~/.julia/packages/NLopt/w0c7n/src/NLopt.jl:227
[3] optimize!(o::Opt, x::Vector{Float64})
@ NLopt ~/.julia/packages/NLopt/w0c7n/src/NLopt.jl:630
[4] optimize(o::Opt, x::Vector{Int64})
@ NLopt ~/.julia/packages/NLopt/w0c7n/src/NLopt.jl:634
[5] top-level scope
@ REPL[524]:1 |
And here it is using ccalls: julia> using NLopt
julia> NLopt.NLOPT_VERSION
v"2.8.0"
julia> function my_scalar_callback_fn(n, p_x, p_grad, ::Ptr{Cvoid})::Cdouble
x = unsafe_wrap(Array, p_x, (n,))
if p_grad !== C_NULL
grad = unsafe_wrap(Array, p_grad, (n,))
grad .= [1e8 * x[2]^2, 2e8 * x[1] * x[2]]
end
return 1e8 * (x[1] * x[2]^2)
end
my_scalar_callback_fn (generic function with 1 method)
julia> c_my_scalar_callback_fn = @cfunction(
my_scalar_callback_fn,
Cdouble,
(Cuint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid})
)
Ptr{Nothing} @0x0000000105e16300
julia> opt = NLopt.nlopt_create(NLopt.NLOPT_LD_SLSQP, 2)
Ptr{Nothing} @0x00006000009ae800
julia> NLopt.nlopt_set_lower_bounds(opt, [0, -Inf])
NLOPT_SUCCESS::nlopt_result = 1
julia> NLopt.nlopt_set_min_objective(opt, c_my_scalar_callback_fn, C_NULL)
NLOPT_SUCCESS::nlopt_result = 1
julia> opf_f = Ref{Cdouble}(NaN)
Base.RefValue{Float64}(NaN)
julia> NLopt.nlopt_optimize(opt, [1.0, -1.0], opf_f)
NLOPT_FAILURE::nlopt_result = -1
julia> unsafe_string(NLopt.nlopt_get_errmsg(opt))
"bug: more than iter SQP iterations" |
I have a C reproducer in stevengj/nlopt#215 (comment) |
Closing in favor of stevengj/nlopt#215 |
I understand 1.0.1 => 1.0.2 brought changes to the error handling.
this is inconvenient in the case of SLSQP because it (now) throws an error when maxeval is reached and the optimisation failed. for my purposes it would be useful to have access to the return values even if the optimisation failed/errored. in other words, not throw an error and hand over return values
The text was updated successfully, but these errors were encountered: