Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppressing output for optimize! #1883

Closed
ahmetumutdurmus opened this issue Mar 1, 2019 · 16 comments
Closed

Suppressing output for optimize! #1883

ahmetumutdurmus opened this issue Mar 1, 2019 · 16 comments

Comments

@ahmetumutdurmus
Copy link

ahmetumutdurmus commented Mar 1, 2019

Hello,

Is there a way (a keyword argument to the solver or optimize!) to suppress the output of optimize!?

When I use the Cbc Solver to solve the following toy problem I get the following output:

julia> using JuMP, Cbc

julia> model = Model(with_optimizer(Cbc.Optimizer));

julia> @variable(model, 0 <= x <= 2);

julia> @variable(model, 0 <= y <= 30);

julia> @objective(model, Max, 5*x + 3*y);

julia> @constraint(model, 1x + 5y <= 3);

julia> optimize!(model);
Welcome to the CBC MILP Solver
Version: 2.9.9
Build Date: Dec 31 2018

command line - Cbc_C_Interface -solve -quit (default strategy 1)
Presolve 0 (-1) rows, 0 (-2) columns and 0 (-2) elements
Empty problem - 0 rows, 0 columns and 0 elements
Optimal - objective value 10.6
After Postsolve, objective 10.6, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 10.6 - 0 iterations time 0.012, Presolve 0.01
Total time (CPU seconds):       0.02   (Wallclock seconds):       0.02

This is highly inconvenient when one uses the solver inside a loop.

When I use the GLPK solver instead I do not encounter the same problem.

Btw this was not an issue in Jump 0.18.

Any thoughts?

@blegat
Copy link
Member

blegat commented Mar 1, 2019

This is currently a solver-specific option, see jump-dev/MathOptInterface.jl#663 for a proposal of solver-independent option. For Cbc, you need to do with_optimizer(Cbc.Optimizer, logLevel = 0)

@diam
Copy link

diam commented Mar 14, 2019

Just a remark:

  • For Cbc, you need to do with_optimizer(Cbc.Optimizer, logLevel = 0)
  • For Clp , you need to do with_optimizer(Clp.Optimizer, LogLevel = 0)
    (not the case difference between "Log" and "log" !)
    Is this a bug from Cbc/Clp or from their Julia interface?

-- Maurice

@odow
Copy link
Member

odow commented Mar 14, 2019

These options are solver-specific. We will be implementing a JuMP option to set the log-level to 0 to avoid this.

@blegat
Copy link
Member

blegat commented Mar 15, 2019

You should be able to do MOI.set(model, MOI.Silent(), true) to silence a solver

@hhaensel
Copy link

Just two remarks:

  • The Ipopt parameter is called "print_level".
  • The options can also be changed without setting up the model again:
MOI.set(model, MOI.RawParameter("print_level"), 1)

If you are interested in catching the solver's output, see also this post

@lausilvag
Copy link

lausilvag commented Apr 23, 2020

Hi
I have the opposite problem, I need the output of GLPK.. I don't how to make it appears... I need some help, please

Z_OP = Model(with_optimizer(GLPK.Optimizer))
@variable(Z_OP, x[l,m], Bin)
@constraint(Z_OP, e_pac*x .<= e_part)                          
@objective(Z_OP, Min, sum(B.*x))
optimize!(Z_OP)
X = value.(x)
Z = JuMP.objective_value(Z_OP)

@blegat
Copy link
Member

blegat commented Apr 24, 2020

@lausilvag See jump-dev/GLPK.jl#132 for a reply to your question.

@ConnectedSystems
Copy link

ConnectedSystems commented Oct 31, 2020

Hello,

Sorry for re-raising an old issue but I'm having trouble with this as well and can't work out what I'm doing wrong.

Here are the things I've tried, all of which do not appear to suppress output:

model::Model = Model(with_optimizer(Clp.Optimizer, LogLevel=0))

model = Model(Clp.Optimizer)
set_optimizer_attribute(model, "LogLevel", 0)

model = Model(Clp.Optimizer)
set_silent(model)

model = Model(Clp.Optimizer)
MOI.set(model, MOI.Silent(), true)

I re-run (via include()) for each attempt after restarting the REPL.

I am using JuMP v0.21.4

@odow
Copy link
Member

odow commented Nov 1, 2020

Use set_silent(model).

Note that some solvers still print output, even when their printing level option is set to the minimum. We won't be providing a work-around for this because there are general Julia ones: https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437/6?u=odow

@diam
Copy link

diam commented Nov 2, 2020 via email

@ConnectedSystems
Copy link

Hi @diam

As noted by @odow , they won't be providing a workaround as there are general Julia ones.

In my case, I'm doing these optimizations in a loop, and simply redirecting stdout (as is suggested in the link above) isn't a great workaround anyway as it makes using Clp slower than GLPK. So for now, I stick with GLPK. Not ideal but not much else I can do.

@diam
Copy link

diam commented Nov 2, 2020 via email

@odow
Copy link
Member

odow commented Nov 2, 2020

This may be a regression in Clp.jl. I will investigate.

Edit: it was a bug in Clp.jl: jump-dev/Clp.jl#102

vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
@vtjeng
Copy link
Contributor

vtjeng commented Feb 17, 2023

A note for posterity:

I came across this issue because I had had trouble silencing Cbc.jl output in my test suite. Without specifying any parameters, we get four lines of output:

julia> using JuMP, Cbc

julia> model = Model(Cbc.Optimizer);

julia> @variable(model, 0 <= x <= 2); @variable(model, 0 <= y <= 30); @constraint(model, 1x + 5y <= 3); @objective(model, Max, 5*x + 3*y);

julia> optimize!(model)
Presolve 0 (-1) rows, 0 (-2) columns and 0 (-2) elements
Optimal - objective value 10.6
After Postsolve, objective 10.6, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 10.6 - 0 iterations time 0.002, Presolve 0.00

Setting the logLevel flag had no impact.

julia> model2 = Model(optimizer_with_attributes(Cbc.Optimizer, Dict("logLevel" => 0)...));

julia> @variable(model2, 0 <= x <= 2); @variable(model2, 0 <= y <= 30); @constraint(model2, 1x + 5y <= 3); @objective(model2, Max, 5*x + 3*y);

julia> optimize!(model2)
Presolve 0 (-1) rows, 0 (-2) columns and 0 (-2) elements
Optimal - objective value 10.6
After Postsolve, objective 10.6, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 10.6 - 0 iterations time 0.002, Presolve 0.00

set_silent, suggested by @odow in #1883 (comment), has no impact

julia> set_silent(model3)

julia> @variable(model3, 0 <= x <= 2); @variable(model3, 0 <= y <= 30); @constraint(model3, 1x + 5y <= 3); @objective(model3, Max, 5*x + 3*y);

julia> optimize!(model3)
Presolve 0 (-1) rows, 0 (-2) columns and 0 (-2) elements
Optimal - objective value 10.6
After Postsolve, objective 10.6, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 10.6 - 0 iterations time 0.002, Presolve 0.00

Redirecting stdout (https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437/4) works on the command line, but did not work in tests

julia> model4 = Model(Cbc.Optimizer);

julia> @variable(model4, 0 <= x <= 2); @variable(model4, 0 <= y <= 30); @constraint(model4, 1x + 5y <= 3); @objective(model4, Max, 5*x + 3*y);

julia> redirect_stdout(devnull) do
           optimize!(model4)
       end

In the end, I needed to also flush stdio:

julia> model5 = Model(Cbc.Optimizer);

julia> @variable(model5, 0 <= x <= 2); @variable(model5, 0 <= y <= 30); @constraint(model5, 1x + 5y <= 3); @objective(model5, Max, 5*x + 3*y);

julia> function optimize_silent!(m)
           redirect_stdout(devnull) do
               optimize!(m)
               # Required, per https://discourse.julialang.org/t/consistent-way-to-suppress-solver-output/20437/9
               Base.Libc.flush_cstdio()
           end
       end
optimize_silent! (generic function with 1 method)

julia> optimize_silent!(model5)

vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
vtjeng added a commit to vtjeng/MIPVerify.jl that referenced this issue Feb 17, 2023
@odow
Copy link
Member

odow commented Feb 17, 2023 via email

@vtjeng
Copy link
Contributor

vtjeng commented Feb 17, 2023

This is jump-dev/Cbc.jl#168. Use HiGHS instead.

Thanks; used your suggestion in vtjeng/MIPVerify.jl#133.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants