# Suppress license output from solver in JuMP.Model

**URL:** <https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 15, 2019, 5:19pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828 "2019-02-15T17:19:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![torgo](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@torgo](https://discourse.julialang.org/u/torgo)\
**Post date:** [February 15, 2019, 5:19pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/1 "2019-02-15T17:19:48Z")

</div>

```julia
using JuMP, Gurobi
m = Model(solver=GurobiSolver(OutputFlag=0))

```

I have a program where the second line gets called frequently.  
Every time it does, this gets printed to stdout:

```julia
Academic license - for non-commercial use only

```

How can I suppress this notice?

In an old version of the JuMP FAQ it is suggested to use

```julia
    TT = stdout
    redirect_stdout()
    m = Model(solver=GurobiSolver(OutputFlag = 0))
    redirect_stdout(TT)

```

But I didn’t find this to work – perhaps it is outdated?

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 15, 2019, 8:32pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/2 "2019-02-15T20:32:45Z")

</div>

You can try [Suppressor.jl](https://github.com/JuliaIO/Suppressor.jl). But a better option might be to talk to the package authors and ask them to remove or add an option to remove the message. See [this issue](https://github.com/Nemocas/AbstractAlgebra.jl/issues/158) for a similar situation, and interesting discussion around it.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [February 16, 2019, 12:27am UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/3 "2019-02-16T00:27:46Z")

</div>

This message is coming from Gurobi itself though, not the Julia wrapper. I don’t think Gurobi-the-company is going to be receptive to a request to remove the message, and there might be license issues with having the Julia wrapper suppress the message by default.

---

<div class="post-metadata">

**Author:** ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Post date:** [February 16, 2019, 3:42am UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/4 "2019-02-16T03:42:24Z")

</div>

As others have mentioned, the message comes from Gurobi when getting the Gurobi environment. The solution is to get the environment just once, and then re-use that environment:

```julia
julia> gurobi_env = Gurobi.Env()
Academic license - for non-commercial use only
Gurobi.Env(Ptr{Nothing} @0x000000002cd049f0)

julia> m = Model(with_optimizer(Gurobi.Optimizer, gurobi_env))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Gurobi

julia> m = Model(with_optimizer(Gurobi.Optimizer, gurobi_env))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Gurobi

```

Notice that each model creation doesn’t trigger a printed warning about the academic license.

---

<div class="post-metadata">

**Author:** ![torgo](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@torgo](https://discourse.julialang.org/u/torgo)\
**Post date:** [February 18, 2019, 8:55pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/5 "2019-02-18T20:55:19Z")

</div>

Doesn’t this solution require one to pass along `gurobi_env` to any called functions that are going to solve an optimization problem? That seems pretty undesirable.

Isn’t there a way to just capture and dispose of the message? The solutions with `redirect_stdout` that were suggested for previous versions of JuMP are what I want – they just don’t seem to work anymore.

---

<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:** [February 18, 2019, 9:13pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/6 "2019-02-18T21:13:00Z")

</div>

> Doesn’t this solution require one to pass along `gurobi_env` to any called functions that are going to solve an optimization problem? That seems pretty undesirable.

Make a global constant.

```julia
const GUROBI_ENV = Gurobi.Env()

function solve_model()
    model = Model(with_optimizer(Gurobi.Optimizer, GUROBI_ENV))
end

```

> Isn’t there a way to just capture and dispose of the message?

No. As already stated, this is coming from Gurobi itself. The wrapper won’t provide a mechanism to suppress this.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 18, 2019, 9:52pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/7 "2019-02-18T21:52:02Z")

</div>

> [@torgo](#):
>
> Isn’t there a way to just capture and dispose of the message?

Yes. As already stated, you should be able to do this with [Suppressor.jl](https://github.com/JuliaIO/Suppressor.jl). (But a single global environment sounds like a more proper solution.)

---

<div class="post-metadata">

**Author:** ![torgo](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@torgo](https://discourse.julialang.org/u/torgo)\
**Post date:** [February 19, 2019, 5:23pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/8 "2019-02-19T17:23:05Z")

</div>

The global constant solution works well for my purposes. Thanks.

---

<div class="post-metadata">

**Author:** ![torgo](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@torgo](https://discourse.julialang.org/u/torgo)\
**Post date:** [March 4, 2019, 5:46pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/9 "2019-03-04T17:46:32Z")

</div>

I was able to get this to work well in JuMP 18.5 using the following syntax:

```julia
genv = Gurobi.Env()
m = Model(solver=GurobiSolver(OutputFlag = 0, genv))

```

However, in JuMP 19 it seems like the way to reuse the environment has changed?  
I tried this syntax given by @evanfields:

```julia
gurobi_env = Gurobi.Env()
m = Model(with_optimizer(Gurobi.Optimizer, gurobi_env))

```

and I get this output:

```julia
julia> gurobi_env = Gurobi.Env()
Academic license - for non-commercial use only
Gurobi.Env(Ptr{Nothing} @0x000000000342c2d0)

julia> m = Model(with_optimizer(Gurobi.Optimizer, gurobi_env))
ERROR: Gurobi.Optimizer does not have any method with arguments (Gurobi.Env(Ptr{Nothing} @0x000000000342c2d0),).The first argument of `with_optimizer` should be callable with the other argument of `with_optimizer`.
Stacktrace:
 [1] error(::String, ::String, ::String) at ./error.jl:42
 [2] #with_optimizer#1(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Type, ::Gurobi.Env) at /home/at/.julia/packages/JuMP/jnmGG/src/JuMP.jl:108
 [3] with_optimizer(::Type, ::Gurobi.Env) at /home/at/.julia/packages/JuMP/jnmGG/src/JuMP.jl:107
 [4] top-level scope at none:0

```

Can someone explain to me what the correct syntax for this is now?

EDIT: The problem was I needed to update Gurobi.jl from 0.5.9 to 0.6.0. After doing that the syntax given by @evanfields works.

---

<div class="post-metadata">

**Author:** ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)\
**Post date:** [February 27, 2020, 3:09pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/10 "2020-02-27T15:09:33Z")

</div>

In case anyone else comes across this:

```julia
with_optimizer(Gurobi.Optimizer, GUROBI_ENV)

```

is now

```julia
optimizer_with_attributes(() -> Gurobi.Optimizer(GUROBI_ENV))

```

---

<div class="post-metadata">

**Author:** ![Peter\_Volkmar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_volkmar/32/19391_2.png) [@Peter\_Volkmar](https://discourse.julialang.org/u/Peter_Volkmar)\
**Post date:** [November 17, 2020, 6:24am UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/11 "2020-11-17T06:24:09Z")

</div>

This doesn’t work with the new JuMP v0.21.5. I’m getting the following error. Any ideas?

```julia
The provided `optimizer_constructor` is invalid. It must be callable with zero arguments. For example, "Ipopt.Optimizer" or "() -> ECOS.Optimizer()". It should not be an instantiated optimizer like "Ipopt.Optimizer()" or "ECOS.Optimizer()". (Note the difference in parentheses!)

```

---

<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:** [November 17, 2020, 8:54pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/12 "2020-11-17T20:54:14Z")

</div>

```nohighlight
using JuMP, Gurobi
const GRB_ENV = Gurobi.Env()
model = Model(() -> Gurobi.Optimizer(GRB_ENV))

```

---

<div class="post-metadata">

**Author:** ![pearlzli](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pearlzli](https://discourse.julialang.org/u/pearlzli)\
**Post date:** [January 10, 2021, 10:31pm UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/13 "2021-01-10T22:31:30Z")

</div>

After many months in which this solution worked for me, I’m now having a weird (maybe Revise-related?) issue reusing an environment inside a package. I opened an [issue](https://github.com/jump-dev/Gurobi.jl/issues/388) at Gurobi.jl where I describe my problem in more detail. Would really appreciate any thoughts!

---

<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:** [January 11, 2021, 1:24am UTC](https://discourse.julialang.org/t/suppress-license-output-from-solver-in-jump-model/20828/14 "2021-01-11T01:24:41Z")

</div>

I’ve replied to the issue.
