Skip to content

Commit

Permalink
Deprecate passing keyword arguments to Ipopt.Optimizer (#240)
Browse files Browse the repository at this point in the history
* Deprecate passing keyword arguments to Ipopt.Optimizer

* Add test_deprecation
  • Loading branch information
odow authored Nov 21, 2020
1 parent 88bef1b commit 1d80321
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ end

empty_nlp_data() = MOI.NLPBlockData([], EmptyNLPEvaluator(), false)

function Optimizer(; options...)
options_dict = Dict{String, Any}()
# TODO: Setting options through the constructor could be deprecated in the
# future.
for (name, value) in options
options_dict[string(name)] = value
function Optimizer(; kwargs...)
if length(kwargs) > 0
@warn("""Passing optimizer attributes as keyword arguments to
`Ipopt.Optimizer` is deprecated. Use
MOI.set(model, MOI.RawParameter("key"), value)
or
JuMP.set_optimizer_attribute(model, "key", value)
instead.""")
end
return Optimizer(
nothing,
Expand All @@ -102,7 +104,10 @@ function Optimizer(; options...)
[],
nothing,
false,
options_dict,
Dict{String, Any}(
# Remove when `kwargs...` support is dropped.
string(key) => value for (key, value) in kwargs
),
NaN,
)
end
Expand Down
5 changes: 5 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ function test_check_derivatives_for_naninf()
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INVALID_MODEL
end

function test_deprecation()
model = Ipopt.Optimizer(print_level = 0)
@test MOI.get(model, MOI.RawParameter("print_level")) == 0
end

end # module TestMOIWrapper

runtests(TestMOIWrapper)

0 comments on commit 1d80321

Please sign in to comment.