Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/OptimizationNLopt/src/OptimizationNLopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ function __map_optimizer_args!(cache::OptimizationCache, opt::NLopt.Opt;
local_maxtime::Union{Number, Nothing} = nothing,
local_options::Union{NamedTuple, Nothing} = nothing,
kwargs...)

# Check if AUGLAG algorithm requires local_method
if opt.algorithm ∈ (NLopt.LN_AUGLAG, NLopt.LD_AUGLAG, NLopt.AUGLAG) && local_method === nothing
error("NLopt.$(opt.algorithm) requires a local optimization method. " *
"Please specify a local_method, e.g., solve(prob, NLopt.$(opt.algorithm)(); " *
"local_method = NLopt.LN_NELDERMEAD())")
end

if local_method !== nothing
if isa(local_method, NLopt.Opt)
if ndims(local_method) != length(cache.u0)
Expand Down
4 changes: 4 additions & 0 deletions lib/OptimizationNLopt/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ using Test, Random
# @test sol.retcode == ReturnCode.Success
@test 10 * sol.objective < l1

# Test that AUGLAG without local_method throws an error
@test_throws ErrorException solve(prob, NLopt.LN_AUGLAG())
@test_throws ErrorException solve(prob, NLopt.LD_AUGLAG())

function con2_c(res, x, p)
res .= [x[1]^2 + x[2]^2 - 1.0, x[2] * sin(x[1]) - x[1] - 2.0]
end
Expand Down
Loading