pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.74k stars 2.02k forks source link

ENH: Disable all progress bars #7151

Open JakeSummers opened 9 months ago

JakeSummers commented 9 months ago

Context for the issue:

Currently the progress bars printed by pymc are printed to stdout in my backend service. They often corrupt the structured logs that my service prints.

Right now, I need to go through my code to disable all of the progress bars.

Aka I need to, update from:

pm.sample(samples, random_seed=random_seed)

To:

pm.sample(samples, random_seed=random_seed, progressbar=False)

It would make my code better, if I could do something like:

pm.progress_bar(False)

And that would disable all progress bars in pymc.

This would allow me to make my code easy to use with the backend service we integrate with but also to use in notebooks or IDEs.

Related: https://github.com/fastai/fastprogress/issues/105

welcome[bot] commented 9 months ago

Welcome Banner] :tada: Welcome to PyMC! :tada: We're really excited to have your input into the project! :sparkling_heart:
If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.

JakeSummers commented 9 months ago

Workaround from: https://github.com/fastai/fastprogress/issues/105#issuecomment-1939645396

It looks like this is possible like this:

import fastprogress.fastprogress
fastprogress.fastprogress.NO_BAR = True

If you also want to disable the output from master_bar.write, you can do this:

def do_nothing(*args):
    pass

fastprogress.fastprogress.WRITER_FN = do_nothing

I wonder if this should be added to pymc's api so that if/when the fastprogress dependency is switched for something else, that we will keep the same structure.

ricardoV94 commented 9 months ago

Not counting on switching that dependency anytime soon

cluhmann commented 3 weeks ago

Can we get some discussion going around the interface for this feature? Is a global pm.progress_bar=False what we want? We don't currently have any high-level configuration settings that work like this. Or maybe we want some sort of logging verbosity setting?

jacobtomlinson commented 3 weeks ago

Environment variables feel like a good fit for configuring global things like this, especially when it comes to output. You can also provide Python to helpers for setting these values for folks who want to be able to configure this in Python.

For example the progress bar could check if os.environ.get("PYMC_SHOW_PROGRESS", true) and you could provide pm.show_process(False) which would set the variable.