Turing.jl icon indicating copy to clipboard operation
Turing.jl copied to clipboard

Option to suppress "Warning" and "Info" statements

Open ElOceanografo opened this issue 3 years ago • 7 comments

Currently, sampling from a model always prints warnings for numerical errors and info statements on the initial step size, even with the option verbose=false. This can really fill up the REPL, especially when a model run generates frequent numerical errors, or when fitting models to multiple datasets in parallel. Would it be possible to optionally suppress these messages too?

ElOceanografo avatar Sep 04 '20 16:09 ElOceanografo

A cheap workaround would be to disable logging of such messages globally by setting

import Logging
Logging.disable_logging(Logging.Warn) # or e.g. Logging.Info

Alternatively, you can use a local logger for your sample call:

import Logging
logger = Logging.SimpleLogger(min_level=Logging.Error) # or e.g. Logging.Warn
chain = Logging.with_logger(logger) do
   sample(...)
end

The logging system is explained in more detail in the Julia docs.

A disadvantage of these approaches would be that progress bars are not displayed IIRC.

devmotion avatar Sep 04 '20 16:09 devmotion

This should probably be handled upstream in AdvancedHMC, since the warning doesn't respect verbose:

https://github.com/TuringLang/AdvancedHMC.jl/blob/63e32355bbc5be1639c9c12d21e908be0241db56/src/hamiltonian.jl#L47

cpfiffer avatar Sep 04 '20 18:09 cpfiffer

Yes, I agree. The approaches above are just workarounds as long as it is not fixed upstream.

devmotion avatar Sep 04 '20 19:09 devmotion

Yeah, it's a good thing to have the workaround on record.

cpfiffer avatar Sep 04 '20 19:09 cpfiffer

Thanks, that workaround will be very helpful. I'm fitting a large number of models, and while the first few "step size found" notifications are useful, they get less interesting after the 30 or 40 thousandth 🙃

ElOceanografo avatar Sep 04 '20 20:09 ElOceanografo

The local logger code from David didn't work for me. Instead, on Julia 1.6, use

stream = IOBuffer(UInt8[])
logger = Logging.SimpleLogger(stream, Logging.Error)
chain = Logging.with_logger(logger) do
   sample(...)
end

In Julia 1.7, you can drop the stream argument thanks to https://github.com/JuliaLang/julia/pull/40423.

rikhuijzer avatar May 28 '21 10:05 rikhuijzer

This appears to be a serious issue when using Turing inside a Pluto notebook, as a large number of warnings makes the page unresponsive and I can't even hit the interrupt button.

andreasKroepelin avatar Feb 16 '23 17:02 andreasKroepelin