Skip to content

Commit

Permalink
refactor: 💡 Change optional args of select_optimizers to kwargs (#160)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 🧨 The API of select_optimizers changed to not have positional optional
arguments. The problem is mandatory and the other arguments are
keywords.

✅ Closes: #159
  • Loading branch information
abelsiqueira authored Jun 1, 2024
1 parent bb11e8b commit b185280
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ There are 7 optimizers available:
```
"""
function select_optimizers(
nlp::AbstractNLPModel{T, S},
nlp::AbstractNLPModel{T, S};
verbose = 1,
highest_derivative_available::Integer = 2,
) where {T, S}
Expand Down Expand Up @@ -151,9 +151,9 @@ function select_optimizers(
return select
end

function select_optimizers(model::JuMP.Model, args...; kwargs...)
function select_optimizers(model::JuMP.Model; kwargs...)
nlp = MathOptNLPModel(model)
return select_optimizers(nlp, args...; kwargs...)
return select_optimizers(nlp; kwargs...)
end

"""Checker whether optimizers are Generic only"""
Expand Down
12 changes: 10 additions & 2 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ function minimize(
highest_derivative_available::Integer = 2,
kwargs...,
)
select = select_optimizers(nlp, verbose, highest_derivative_available)
select = select_optimizers(
nlp;
verbose = verbose,
highest_derivative_available = highest_derivative_available,
)
(verbose ≥ 1) && println("Solve using $(first(select).name):")
solver = first(select)
return minimize(Val(Symbol(solver.name)), nlp; verbose = verbose, kwargs...)
Expand All @@ -16,7 +20,11 @@ function minimize(
highest_derivative_available::Integer = 2,
kwargs...,
)
select = select_optimizers(nlp, verbose, highest_derivative_available)
select = select_optimizers(
nlp;
verbose = verbose,
highest_derivative_available = highest_derivative_available,
)
nls_select = select[select.specialized_nls, :]
solver = if !isempty(nls_select)
first(nls_select)
Expand Down

0 comments on commit b185280

Please sign in to comment.