Consistent way to suppress solver output


#1

Is there a consistent way to suppress the solver output in JuMP v0.19 or MOI? It isn’t clear to me if there is.


#2

Not really; it’s all handled through each individual solver’s options API. As a hack, I suppose you could use

redirect_stdout(devnull) do
    # code here
end

but that doesn’t remove the overhead of the solver printing status info (which may or may not be a problem).


#3

devnull is of type IO not IOStream:

ERROR: MethodError: no method matching redirect_stderr(::Base.DevNull)
Closest candidates are:
  redirect_stderr() at stream.jl:1001
  redirect_stderr(::Union{IOStream, Base.LibuvStream}) at stream.jl:995
  redirect_stderr(::Function, ::Any) at stream.jl:1051

What’s the best way to convert from IO to IOStream?


#4

The solution I ended up with was:
redirect_stdout((()->optimize!(model)),open("/dev/null", "w"))


#5

Yep. Sorry, should have tested my code. Related issue: https://github.com/JuliaLang/julia/issues/22879.