# How can I clear solver attributes in JuMP?

**URL:** <https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [March 25, 2021, 5:27pm UTC](https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953 "2021-03-25T17:27:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)\
**Post date:** [March 25, 2021, 5:27pm UTC](https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953/1 "2021-03-25T17:27:44Z")

</div>

I need to solve a JuMP model sequentially using different solvers. Solver 1 has one set of attributes but I’m fine with the defaults for solver 2, at least for now. Unfortunately solver 2 complains about the options I set for solver 1, and I can’t figure out how to clear them.

Here’s a silly example:

```julia
julia> using JuMP, Gurobi, Ipopt

julia> function resolve()
    m = Model()
    @variable(m, x >= 0)

    set_optimizer(m, Gurobi.Optimizer)
    set_optimizer_attributes(m, "Method" => 2)
    optimize!(m)

    set_optimizer(m, Ipopt.Optimizer)
    # Here I want something like clear_optimizer_attributes(m)
    optimize!(m)
end

julia> resolve()
Academic license - for non-commercial use only - expires 2021-04-16
Gurobi Optimizer version 9.1.1 build v9.1.1rc0 (win64)
Thread count: 6 physical cores, 12 logical processors, using up to 12 threads
Optimize a model with 0 rows, 1 columns and 0 nonzeros
Model fingerprint: 0xa187a6b9
Coefficient statistics:
  Matrix range [0e+00, 0e+00]
  Objective range [0e+00, 0e+00]
  Bounds range [0e+00, 0e+00]
  RHS range [0e+00, 0e+00]
Presolve removed 0 rows and 1 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
       0 0.0000000e+00 0.000000e+00 0.000000e+00 0s

Solved in 0 iterations and 0.01 seconds
Optimal objective 0.000000000e+00

User-callback calls 20, time in user-callback 0.00 sec
Tried to set Option: Method. It is not a valid option. Please check the list of available options.
ERROR: IPOPT: Couldn't set option 'Method' to value '2'.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] addOption(prob::IpoptProblem, keyword::String, value::Int64)
   @ Ipopt ~\.julia\packages\Ipopt\P1XLY\src\Ipopt.jl:445
 [3] optimize!(model::Ipopt.Optimizer)
   @ Ipopt ~\.julia\packages\Ipopt\P1XLY\src\MOI_wrapper.jl:1436
 [4] optimize!(b::MathOptInterface.Bridges.LazyBridgeOptimizer{Ipopt.Optimizer})
   @ MathOptInterface.Bridges ~\.julia\packages\MathOptInterface\5WwpK\src\Bridges\bridge_optimizer.jl:293
 [5] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}})
   @ MathOptInterface.Utilities ~\.julia\packages\MathOptInterface\5WwpK\src\Utilities\cachingoptimizer.jl:237
 [6] optimize!(model::Model, optimizer_factory::Nothing; bridge_constraints::Bool, ignore_optimize_hook::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ JuMP ~\.julia\packages\JuMP\e0Uc2\src\optimizer_interface.jl:130
 [7] optimize!
   @ ~\.julia\packages\JuMP\e0Uc2\src\optimizer_interface.jl:106 [inlined]
 [8] resolve()
   @ Main .\REPL[2]:10
 [9] top-level scope
   @ REPL[3]:1

```

Is there a good way to `clear_optimizer_attributes(m)`?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 25, 2021, 5:55pm UTC](https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953/2 "2021-03-25T17:55:25Z")

</div>

This is a known bug. The best work-around we have is something like

```nohighlight
set_optimizer(m, optimizer_with_attributes(Gurobi.Optimizer, "Method" => 2))

# ... 

set_optimizer(m, Ipopt.Optimizer)

```

---

<div class="post-metadata">

**Author:** ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)\
**Post date:** [March 25, 2021, 6:36pm UTC](https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953/3 "2021-03-25T18:36:18Z")

</div>

Thanks, it works now! I never suspected that was a bug. Both solvers were working and I could modify their attributes just fine. I tried finding the relevant issue just now but failed, mind pointing me to it?

Oh, and for anyone who ends up here after searching, use `optimizer_with_attributes()` with an `s` at the end.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 25, 2021, 7:05pm UTC](https://discourse.julialang.org/t/how-can-i-clear-solver-attributes-in-jump/57953/4 "2021-03-25T19:05:34Z")

</div>

Here’s the open issue: [reset\_optimizer attempts to pass RawParameters between models · Issue #1220 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/issues/1220)

(Edit: and I updated the post. Thanks for catching the typo)
