pymc-devs / pymc-devs/pymc

BUG: SMC progress bars do not display correctly when called from RStudio

Open
#7,409 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

Description

Describe the issue:

When calling pyMC SMC sampling from RStudio with multiple chains, the new Rich progress bars fill the Console and the Rmarkdown output with chains lines every 0.1 seconds, eventually flooding the console and slowing down RStudio to a crawl.

This is because RStudio console output does not implement cursor movement ANSI control sequences used by Rich multi-progress bars.

See https://github.com/rstudio/reticulate/issues/1632 and https://github.com/rstudio/rstudio/issues/14942

Reproduceable code example:
import pymc as pm

# Run this via a Python chunk in Rstudio with reticulate

def main():

    with pm.Model() as model:
        x = pm.Normal("x", mu=0, sigma=1)
        y = pm.Normal("y", mu=x, sigma=0.001, observed=2)

    with model:
        trace = pm.sample_smc(draws=1000, chains=12, cores=1, progressbar=False)


if __name__ == "__main__":
    main()
Error message:
No error message. See the screenshot.
image
PyMC version information:
- PyMC 5.16.1, installed via Conda - Pytensor 2.23.0 (but not important) - macOS 14.5 Catalina, and also reproduced on Windows Server 2022 - rich 13.7.1 (relevant!)
Context for the issue:

This ruins every call to PyMC SMC sampler with progress bars from RStudio, and hence the use of SMC Sampler by R-heavy biostatisticians.

Turning off the progressbar would work, but then would give no visibility as to how the algorithm is progressing.

I'm submitting a PR in a minute to fix this :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Python reproduction using pm.sample_smc in an RStudio Python chunk, and inspect how SMC progress bars are created when multiple chains run. Verify the behavior with Rich output in RStudio and compare it with normal terminal output. Done means progress remains visible without flooding the RStudio console or RMarkdown output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.