TuringLang / Turing.jl

Bayesian inference with probabilistic programming.
https://turinglang.org
MIT License
2.03k stars 218 forks source link

Option to suppress "Warning" and "Info" statements #1398

Open ElOceanografo opened 4 years ago

ElOceanografo commented 4 years ago

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?

devmotion commented 4 years ago

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.

cpfiffer commented 4 years ago

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

devmotion commented 4 years ago

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

cpfiffer commented 4 years ago

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

ElOceanografo commented 4 years ago

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 🙃

rikhuijzer commented 3 years ago

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.

andreasKroepelin commented 1 year ago

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.