Skip to content

Commit

Permalink
improve the deprecation warning for with_optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Feb 17, 2020
1 parent aa08802 commit 6a91d0c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/JuMP.jl
Expand Up @@ -94,14 +94,15 @@ end
function with_optimizer(constructor; kwargs...)
if isempty(kwargs)
deprecation_message = """
`with_optimizer` is deprecated, replace `with_optimizer(Ipopt.Optimizer)` by `Ipopt.Optimizer`.
`with_optimizer` is deprecated. Adapt the following example to update your code:
`with_optimizer(Ipopt.Optimizer)` becomes `Ipopt.Optimizer`.
"""
Base.depwarn(deprecation_message, :with_optimizer)
return constructor
else
deprecation_message = """
`with_optimizer` is deprecated, replace `with_optimizer(Ipopt.Optimizer, max_cpu_time=60.0)`
by `optimizer_with_attributes(Ipopt.Optimizer, "max_cpu_time" => 60.0)`.
`with_optimizer` is deprecated. Adapt the following example to update your code:
`with_optimizer(Ipopt.Optimizer, max_cpu_time=60.0)` becomes `optimizer_with_attributes(Ipopt.Optimizer, "max_cpu_time" => 60.0)`.
"""
Base.depwarn(deprecation_message, :with_optimizer_kw)
params = [MOI.RawParameter(string(kw.first)) => kw.second for kw in kwargs]
Expand All @@ -111,7 +112,8 @@ end
function with_optimizer(constructor, args...; kwargs...)
if isempty(kwargs)
deprecation_message = """
`with_optimizer` is deprecated, replace `with_optimizer(Gurobi.Optimizer, env)` by `() -> Gurobi.Optimizer(env)`.
`with_optimizer` is deprecated. Adapt the following example to update your code:
`with_optimizer(Gurobi.Optimizer, env)` becomes `() -> Gurobi.Optimizer(env)`.
"""
Base.depwarn(deprecation_message, :with_optimizer_args)
if !applicable(constructor, args...)
Expand All @@ -122,8 +124,8 @@ function with_optimizer(constructor, args...; kwargs...)
return with_optimizer(() -> constructor(args...); kwargs...)
else
deprecation_message = """
`with_optimizer` is deprecated, replace `with_optimizer(Gurobi.Optimizer, env, Presolve=0)`
by `optimizer_with_attributes(() -> Gurobi.Optimizer(env), "Presolve" => 0)`.
`with_optimizer` is deprecated. Adapt the following example to update your code:
`with_optimizer(Gurobi.Optimizer, env, Presolve=0)` becomes `optimizer_with_attributes(() -> Gurobi.Optimizer(env), "Presolve" => 0)`.
"""
Base.depwarn(deprecation_message, :with_optimizer_args_kw)
if !applicable(constructor, args...)
Expand Down

0 comments on commit 6a91d0c

Please sign in to comment.