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

SLSQP in NLopt.jl 1.0.2 throws error: bug: more than iter SQP iterations #215

Open
thorek1 opened this issue Mar 20, 2024 · 4 comments
Open

Comments

@thorek1
Copy link

thorek1 commented Mar 20, 2024

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

@stevengj
Copy link
Member

@thorek1
Copy link
Author

thorek1 commented Mar 20, 2024

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: bug: more than iter SQP iterations

@odow
Copy link
Member

odow commented Apr 18, 2024

Do you have a reproducible example?

@mzaffalon
Copy link
Contributor

I get the same error. Here is a MWE:

using NLopt

ξ = [-1.0, -0.8019385609518437, -0.4450484640237961, 0.0, 0.4450484640237961, 0.8019385609518437, 1.0]
weight = [1.309924793995232e7, 1.311697371095455e7, 1.31290303653434e7, 1.3134417169089135e7, 7.300760397632944e6, 296.9188842891679, 1.0]
invy = [7.634026049312568e-8, 7.623709721739069e-8, 7.61670871475545e-8, 7.613584882574196e-8, 1.369720338068101e-7, 0.003367923203652162, 1.0]
p = [0.0, 0.021220788737679505, 0.4893496181966227, -0.27747890271555137]


opt = Opt(:LD_SLSQP, 4)
opt.lower_bounds = [-Inf, 0, 0, -Inf]
opt.ftol_rel = 1e-3

function myfunc(p::Vector, grad::Vector)
    p[2] < 0 && (p[2] = 0)
    p[3] < 0 && (p[3] = 0)
    Δ = sqrt.(p[2] .+ p[3]*(ξ.-p[4]).^2)
    f = p[1] .+ Δ
    objf = (invy .- f) .* weight
    if length(grad) > 0 # do not use isempty(grad)
        grad[1] =       -2sum(objf                      .* weight)
        grad[2] =        -sum(objf                 ./ Δ .* weight)
        grad[3] =        -sum(objf .* (ξ.-p[4]).^2 ./ Δ .* weight)
        grad[4] = 2p[3] * sum(objf .* (ξ.-p[4])    ./ Δ .* weight)
    end
    sum(abs2, objf)
end

opt.min_objective = myfunc
(minf, minx, ret) = optimize(opt, p)

NLopt v1.0.2 and Julia 1.10.3.

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