Skip to content

Commit

Permalink
Silence test outputs (#457)
Browse files Browse the repository at this point in the history
* Set silent before other parameters

In MOI.empty(), set outputflag=0 before any other parameter
changes are made.

* Add output_flag option to Env constructor

Set output_flag=0 for all environments used in the tests
  • Loading branch information
simonbowly authored Feb 18, 2022
1 parent 1648d6e commit 4188473
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ mutable struct Env
finalize_called::Bool
attached_models::Int

function Env()
function Env(; output_flag::Int = 1)
a = Ref{Ptr{Cvoid}}()
ret = GRBloadenv(a, C_NULL)
ret = GRBemptyenv(a)
env = new(a[], false, 0)
_check_ret(env, ret)
ret = GRBsetintparam(env.ptr_env, GRB_INT_PAR_OUTPUTFLAG, output_flag)
_check_ret(env, ret)
ret = GRBstartenv(env.ptr_env)
finalizer(env) do e
e.finalize_called = true
if e.attached_models == 0
Expand Down Expand Up @@ -380,12 +384,12 @@ function MOI.empty!(model::Optimizer)
model.env.attached_models += 1
_check_ret(model, ret)
# Reset the parameters in this new environment
for (name, value) in model.params
MOI.set(model, MOI.RawOptimizerAttribute(name), value)
end
if model.silent
MOI.set(model, MOI.Silent(), true)
end
for (name, value) in model.params
MOI.set(model, MOI.RawOptimizerAttribute(name), value)
end
model.needs_update = false
model.objective_type = _SCALAR_AFFINE
model.is_objective_set = false
Expand Down
3 changes: 2 additions & 1 deletion test/MOI/MOI_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ end

const MOI = Gurobi.MOI

const GRB_ENV = isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env()
const GRB_ENV =
isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env(output_flag = 0)

function callback_simple_model()
model = Gurobi.Optimizer(GRB_ENV)
Expand Down
3 changes: 2 additions & 1 deletion test/MOI/MOI_multiobjective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ end

const MOI = Gurobi.MOI

const GRB_ENV = isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env()
const GRB_ENV =
isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env(output_flag = 0)

function test_multiobjective()
model = Gurobi.Optimizer(GRB_ENV)
Expand Down
5 changes: 3 additions & 2 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function runtests()
return
end

const GRB_ENV = isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env()
const GRB_ENV =
isdefined(Main, :GRB_ENV) ? Main.GRB_ENV : Gurobi.Env(output_flag = 0)

function test_runtests()
model =
Expand Down Expand Up @@ -207,7 +208,7 @@ function test_MULTI_ENV_automatic_env_empty()
end

function test_MULTI_ENV_manual_finalize()
env = Gurobi.Env()
env = Gurobi.Env(output_flag = 0)
model = Gurobi.Optimizer(env)
finalize(env)
@test env.finalize_called
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Test
# re-use an existing environment in the module, or name the test function
# `test_MULTI_ENV_xxx` to trap the specific Gurobi error indicating that an
# environment could not be created.
const GRB_ENV = Gurobi.Env()
const GRB_ENV = Gurobi.Env(output_flag = 0)

@testset "MathOptInterface Tests" begin
for file in readdir("MOI")
Expand Down

0 comments on commit 4188473

Please sign in to comment.