Skip to content

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

@jucor

Description

@jucor

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 rstudio/reticulate#1632 and rstudio/rstudio#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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions