Skip to content

Commit 07d369e

Browse files
Merge pull request #1026 from ChrisRackauckas-Claude/fix-nlopt-auglag-error
Add error message when NLopt AUGLAG algorithms are used without local_method
2 parents b5b4dc6 + 37f8492 commit 07d369e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/OptimizationNLopt/src/OptimizationNLopt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ function __map_optimizer_args!(cache::OptimizationCache, opt::NLopt.Opt;
6868
local_maxtime::Union{Number, Nothing} = nothing,
6969
local_options::Union{NamedTuple, Nothing} = nothing,
7070
kwargs...)
71+
72+
# Check if AUGLAG algorithm requires local_method
73+
if opt.algorithm (NLopt.LN_AUGLAG, NLopt.LD_AUGLAG, NLopt.AUGLAG) && local_method === nothing
74+
error("NLopt.$(opt.algorithm) requires a local optimization method. " *
75+
"Please specify a local_method, e.g., solve(prob, NLopt.$(opt.algorithm)(); " *
76+
"local_method = NLopt.LN_NELDERMEAD())")
77+
end
78+
7179
if local_method !== nothing
7280
if isa(local_method, NLopt.Opt)
7381
if ndims(local_method) != length(cache.u0)

lib/OptimizationNLopt/test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ using Test, Random
149149
# @test sol.retcode == ReturnCode.Success
150150
@test 10 * sol.objective < l1
151151

152+
# Test that AUGLAG without local_method throws an error
153+
@test_throws ErrorException solve(prob, NLopt.LN_AUGLAG())
154+
@test_throws ErrorException solve(prob, NLopt.LD_AUGLAG())
155+
152156
function con2_c(res, x, p)
153157
res .= [x[1]^2 + x[2]^2 - 1.0, x[2] * sin(x[1]) - x[1] - 2.0]
154158
end

0 commit comments

Comments
 (0)