Help us test a new progress bar for sampling in CmdStanR!

@josswright has implemented a progress bar for sampling in CmdStanR:

It would be great to have some Stan users test it out so we can incorporate your feedback before including it in a release. The “Summary” section at the GitHub link above has instructions for using it and you can install it from GitHub using:

remotes::install_github("stan-dev/cmdstanr#1138")

If you try it out please let us know how it goes. Thanks in advance!

4 Likes

Can you provide a minimalistic code to get the progress bar while sampling in R using cmdstanR?

Yeah, good suggestion:

# install cmdstanr from the branch with this functionality then restart R
remotes::install_github("stan-dev/cmdstanr#1138")

# in a fresh R session
library(cmdstanr) 

# register the default progress bar
# (you can also customize your own: https://progressr.futureverse.org/)
register_default_progress_handler()

# run a model and use show_progress_bar = TRUE
# (you can run whatever model you want, doesn't need to be this example model)
fit <- cmdstanr_example(show_progress_bar = TRUE)

If running your own model instead of an example model, the show_progress_bar=TRUE should be passed to the sample method.

Perfect.
One quick feedback. It would be nice to have chain specific progress bar. It could be important if the chains sample at different speeds.

2 Likes

Thanks for trying it out!

It would be great, but it seems like this is not currently possible using progressr. Over at the GitHub PR @josswright mentioned this (Add a `progressr`-based progress bar for sampling. by josswright · Pull Request #1138 · stan-dev/cmdstanr · GitHub):

One of the main blockers seems to be that RStudio’s terminal only supports the necessary ANSI sequences to allow single-line progress bars, making it not worth the time to add multi-line bars as a feature.

1 Like

Just to clarify: I dug as deeply as I could into the various R progress frameworks, and at the moment all of them seem to be fairly unified on the fact that RStudio’s console doesn’t currently support the necessary terminal features to allow multi-line progress bars, so they don’t want to waste time adding it.

There have been some discussions in progressr about nested progress bars, but they’re very much sequential bars as substeps, not parallel bars. I caught myself in time and decided to try and get a single progress bar running for CmdStanR, rather than deciding it was time to write my own parallel progress bar framework. :)

(I did even look at using Python’s tqdmalongside reticulateto get per-chain progress bars, but it felt like a step too far.)

3 Likes

Hey, I get this:

> library(progressr)
> library(cmdstanr)
> register_default_progress_handler()
Error in register_default_progress_handler() : 
  could not find function "register_default_progress_handler"

Did you forget to install the version from the pull request (see the first and third post in this topic)

remotes::install_github("stan-dev/cmdstanr#1138")

What’s the difference from Wordle-inspired progress updates for CmdStan v2.29.1 and why not build this directly in cmdstan?

Of course, the difference is that this is more usable and the other was an April fools joke. However, if the wordle one was changed to be a proper progress bar, that’s what I mean by what is the difference here.

Also try restarting R after installing. If you install from the PR branch, restart R, and then it still doesn’t work definitely let us know!

1 Like

I think it’s just because there are not as many people who want to write C++ code and learn the inner workings of CmdStan and work with the CmdStan repo, so it’s just much more likely to get a contributor willing to work on this in R (or Python). That said, I agree that it would be nice for CmdStan itself to offer a progress bar!

That did it, thanks. I like it! I’ll keep using it and let you know.

2 Likes