Stan Playground: Stan without installing Stan

There have been a few new features in Stan Playground since the original post that I thought would be worth highlighting. Because the website is continually deployed, we don’t exactly have “releases”, so some of these have been available for quite some time:

Improvements to user scripting

We’ve improved our integration with pyodide and webR that allows users to run Python and R code directly in Stan Playground. These should be faster/smoother overall, and you can now cancel a script that is stuck rather than needing to refresh your page:

Additionally, the data scripts now give you an indicator in the data.json window when the values there originate from one of them:

Speaking of data.json, the analysis scripts can now read it:

Make sure to check the examples often, as we usually update them when new features become available.

Run scripts in the exported zip file

When your project has Python or R code and you go to export it, we now give you the option to include a run.py and/or run.R file

This file contains the “glue” code necessary to run your data generation and analysis code locally using CmdStanPy/R.

Scatter plots tab

We now provide some interactive scatter plots on a new tab of the Output viewer. This allows you to select different combinations of variables to scatter against each other:

Lots of tiny tweaks

The headers on the tables are now “sticky” and follow as you scroll, the page should load faster, compilation should be slightly quicker, the console text (including print statements) is also now viewable in its own tab, “Pedantic Mode” warnings can be enabled in settings, and more. Thank you to everyone who has used the site for providing feedback and suggestions!

5 Likes

Awesome!

Is it planned to give option on the Stan version to run?

We’ve discussed this. The public compilation server will probably track the latest release, but it would be nice if we gave some way of swapping out e.g. the stanc version used to give you red squigglies in the editor etc. This would both let you run different versions but also something like Torsten, which is the first thing @charlesm93 asked me about when I showed him this a while back. I got a version of torsten working inside it locally, but we never decided quite how to let users select these.

2 Likes

You read my mind. Again, great work!

Hello again!

Stan Playground has continued to get regular maintenance in the form of bug fixes and version bumps (it has been running Stan 2.37 since ~24 hours after the CmdStan release of that version), but today I’m back to show off an exciting new feature: embedded Stan Playground sites wherever you want them.

Just include one script and add a <stan-playground-embed> section to your page and you’ll get a minified version of the website embedded with your own model and data ready to go

More information is available on our new documentation site: Stan Playground Documentation | stan-playground. @magland was the driving force behind this, and I know he has a few interesting uses already in the works

7 Likes

Very cool!

Really cool stuff!

I recall that there was brms support being considered. Is this still the idea to make that work and is it even in reach?

What you have there is already fantastic. Don’t get me wrong here! (and with DARK mode)

It’s still something I would like to add!

I believe we’re still gated by this BRMS issue: Allow installation without RStan · Issue #1702 · paul-buerkner/brms · GitHub

I did experiment with just using BRMS from within the data generation window, and it did work, but obviously we’d want to do something more integrated: Possiblility of generating the stan code from R · Issue #202 · flatironinstitute/stan-playground · GitHub

If you’d like to chime in on that second issue I’d love to hear more about what “BRMS support” looks like to you. Do you just want it to generate the Stan code, or would you also like it to feature in the analysis portions, etc

As a starting point I’d love to generate Stan models and get it to also create the needed Stan data from the given R data. That would already be super cool. More functionality is great as always, but this would be a good starting point for teaching.

BTW, is it in principle possible to cache the Stan compiled models in advance just like a cmdstan executable?

1 Like

The compilation server performs caching already. We clear it out every now and then, but if you compile e.g. one of the examples it will almost certainly be a cache hit and should be nearly instant, compared to 10-15s for a cache miss

oh, nice. Do you even standardise the Stan code as a pre-step to increase cache hits?

We do not, intentionally!

The reason is a bit subtle, but stems from the fact that Stan’s runtime errors can include source code locations inside of them. So even something like deleting ‘extra’ whitespace can lead to confusion.

For example, if

// pretend there are 10 lines before this
model {

foo ~ normal(0, sigma);
bar ~ normal(theta, 2)
}

gets turned into

// pretend there are 10 lines before this
model {
foo ~ normal(0, sigma);
bar ~ normal(theta, 2)
}

By whatever cache-hit-maximizing normalization you are performing, suddenly an error message line 13: second argument to normal_lpdf must be positive looks like it is claiming that somehow 2 is non-positive, when really the issue is with the sigma variable.

This has lead to real-world bug reports from users of systems that do mess with these, for example Line number tracker for error output does not count empty lines in stan code (for both syntax and runtime errors) · Issue #1027 · stan-dev/rstan · GitHub RStan yields incorrect line numbers in compiler and runtime errors · Issue #1123 · stan-dev/rstan · GitHub

Particularly for a teaching tool, we really wanted to avoid these issues. There are also times where you may want to force a cache miss, such as if the compilation server somehow returned a corrupted file, which would be annoyingly defeated by normalization logic

That said, you can manually maximize your odds by using the format button.

2 Likes

oh, I See. maybe add an option “auto-format prior compile”? Then that option will be on by default and the behaviour is to automatically reformat the Stan model prior to sending it to compilation. Then what gets compiled and what is on screen will match… maybe this is an easy one to get more people to enjoy caching …