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

map maxiters to outer_iterations #544

Merged
merged 5 commits into from
Sep 27, 2023
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
18 changes: 17 additions & 1 deletion lib/OptimizationOptimJL/src/OptimizationOptimJL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Optim.SAMIN, Optim.ConstrainedOptimizer};
callback = nothing,
maxiters::Union{Number, Nothing} = nothing,
local_maxiters::Union{Number, Nothing} = nothing,
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
Expand All @@ -36,7 +37,22 @@
end

if !isnothing(maxiters)
mapped_args = (; mapped_args..., iterations = maxiters)
if opt isa Optim.Fminbox
if !isnothing(local_maxiters)
mapped_args = (;

Check warning on line 42 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L40-L42

Added lines #L40 - L42 were not covered by tests
mapped_args...,
outer_iterations = maxiters,
iterations = local_maxiters)
else
mapped_args = (; mapped_args..., outer_iterations = maxiters)

Check warning on line 47 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L47

Added line #L47 was not covered by tests
end
else
mapped_args = (; mapped_args..., iterations = maxiters)

Check warning on line 50 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L50

Added line #L50 was not covered by tests
end
end

if !isnothing(local_maxiters) && opt isa Optim.Fminbox
mapped_args = (; mapped_args..., iterations = local_maxiters)

Check warning on line 55 in lib/OptimizationOptimJL/src/OptimizationOptimJL.jl

View check run for this annotation

Codecov / codecov/patch

lib/OptimizationOptimJL/src/OptimizationOptimJL.jl#L54-L55

Added lines #L54 - L55 were not covered by tests
end

if !isnothing(maxtime)
Expand Down
9 changes: 9 additions & 0 deletions lib/OptimizationOptimJL/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ using Test
sol = solve(prob, Optim.KrylovTrustRegion())
@test 10 * sol.objective < l1

sol = solve(prob, Optim.BFGS(), maxiters = 1)
@test sol.original.iterations == 1

sol = solve(prob, Optim.BFGS(), maxiters = 1, local_maxiters = 2)
@test sol.original.iterations == 1

sol = solve(prob, Optim.BFGS(), local_maxiters = 2)
@test sol.original.iterations > 2

cons = (res, x, p) -> res .= [x[1]^2 + x[2]^2]
optprob = OptimizationFunction(rosenbrock, Optimization.AutoModelingToolkit();
cons = cons)
Expand Down
Loading