Skip to content

Instantly share code, notes, and snippets.

@davipatti
Last active June 28, 2021 17:45
Show Gist options
  • Save davipatti/1b63889a0ba21d7a8202f9778c456173 to your computer and use it in GitHub Desktop.
Save davipatti/1b63889a0ba21d7a8202f9778c456173 to your computer and use it in GitHub Desktop.
Quiet pymc3 info logging #pymc3 #python #logging

Running any model in pymc3 spits out a lot of info, even if everything is running fine:

import pymc3 as pm

with pm.Model():
    pm.Normal(
        "obs",
        mu=pm.Normal("mu", 0, 1),
        sigma=pm.Exponential("sigma", 1),
        observed=y
    )
    pm.sample(progressbar=False)
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, mu]
Sampling 4 chains for 1_000 tune and 2_000 draw iterations (4_000 + 8_000 draws total) took 3 seconds.
The acceptance probability does not match the target. It is 0.8863963431513027, but should be close to 0.8. Try to increase the number of tuning steps.

It gets a bit annoying seeing all these messages all the time, that tell you everything is running as expected.

This snippet supresses INFO log records, so you only see WARNING, ERROR and CRITICAL messages.

For the above example the only message you see is:

The acceptance probability does not match the target. It is 0.8863963431513027, but should be close to 0.8. Try to increase the number of tuning steps.
import logging
logging.getLogger("pymc3").addFilter(lambda x: x.levelname != "INFO")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment