-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stanc3 online demo for pedantic mode, canonicalizer, auto format, etc #577
Comments
Cool !!! EDIT: It would be great to make this thing Stan version specific. So this thing should have a switch which allows to use different versions of the Stan transpiler for this. That is useful to make it easy for people to use older Stan versions and ensure that their Stan program runs with a certain Stan version. |
Sounds cool. I think printing the C++ would also be useful. Does GitHub let you host servers or would you be plumbing in other servers? |
This would use github pages like we do for hosting the website. Given that its only html and a javascript file its a static page that github can handle. |
There is now a prototype available: https://rok-cesnovar.github.io/stanc3js-demo/index.html It lacks any CSS styling to make it prettier but it can:
|
I think especially with #894 merged, it would be really cool to put this somewhere more official. It reminds me a lot of stuff like https://try.ocamlpro.com/ |
Yeah, we could probably place it somewhere like mc-stan.org/stanc3-try or -demo or something like that. Still need to pretty-up the interface, havent touched this in a while. |
I was impressed that it had kept up to date the whole time, but (of course!) it's just pulling the nightly stanjs from Github |
I finally got back to fixing this. The link again https://rok-cesnovar.github.io/stanc3js-demo/ Fixes:
TODO:
Other than that I think we can start discussing if we want this on the official Stan page and where. Maybe a topic for the Stan weekly meeting. |
I think you can use highlight.js, prism.js, or rouge. There are issues/prs in each of these to update Stan syntax: Can't wait for the modular canonicalizer as well! Is it possible for the optimizer to output stan code? As in, what should the Stan code have been written to generate the optimized c++ code? It would be a nice teaching tool. |
As I was typing that there is already a pr in prismjs! PrismJS/prism#3238 |
A web canonicalizer would also come in handy for users to easily update their models when they start seeing deprecation warnings (particularly the array syntax one for example). |
I think it would also be useful to let users select a version of the compiler to use if possible. Make it easy to compare codegen or use an older version (especially bc after a deprecation is 100% removed, it won’t be able to be canonicalized) |
@spinkney make sure that the |
Yeah, I am for that as well. The first version that would be selectable would be 2.29, the rest would then be added as they are released. Plus obviously the nightly. |
We should also discuss (in #1058) how the stancjs interface should look for the modular version of the canonicalizer |
@WardBrian can you make a minimial stan program with this and how it should look? I'll add to the issues. I'm not very familiar with complex numbers or the Stan syntax. |
transformed data {
complex zi = 1+3.14i;
zi = zi * 0i;
complex yi = to_complex(0, 1.1) + to_complex(0.0, 2.2) + to_complex();
real x = get_real(3i - 40e-3i);
} You can see how ugly Github highlights this. |
|
I think just highlight them as numbers (I don’t think real and int get highlighted differently) |
We would need to update atom first, then we can just open a three PR to update the sub module |
Updated the issues to highlight the complex number issues referenced in #577 (comment) |
For highlighting directly in the web version, I’m not sure how intense CodeMirror is to use but the Stan highlighter I maintain for jupyterlab is up to date |
Also opened an issue at vscode-Stan ivan-bocharov/stan-vscode#7 |
prismjs is updated! See PrismJS/prism#3236 (comment) |
@rok-cesnovar when I put anytime I get an error I have to refresh the entire page to get anything to work. Otherwise, I am shown this repeatedly, even with a valid program:
|
I have seen that |
It's very easy try data {
vector[10] y;
}
model {
y ~ std_normal();
}
model {
y ~ std_normal();
} and then remove the second model block and try running the formatter again |
That's very weird. If you keep pressing 'compile' over and over it moves the location of the error and eventually completes. |
Will investigate, hopefully its a bug in the webapp not stancjs. |
This one doesn't complete parameters {
real x;
array[10] y;
}
model {
target += normal_log(x, 0, 1);
} even after commenting out the array piece. |
It's definitely possible stancjs has some weird global that isn't being cleared properly, and it just isn't noticeable in rstan etc because they tear down and restart the process each call. |
This is an issue with the compiler, but luckily an easy one. When parsing we add the lexbuf to a stack, which is how we make |
I can confirm #1074 solved that issue now that the build has propagated and I cleared my cache of Rok's site |
Fantastic! Next time I have time to update this I just need to figure out syntax highlighting and this should be ready. |
Having this demo as a stress test of the JS compiler will also be really helpful to catch problems like that, which would have been much harder to debug from inside rstan or something like that |
The demo is now in a state where I don't think there is anything else needed to be done in stanc3.js or stan-language repos so I am closing this issue and will open discussion on Discourse in the coming days. Other than making it look nicer with HTML/CSS and testing whether it works on all recent major browsers it should now be in a stable state. |
It looks really great @rok-cesnovar ! |
Given that we build a javascript version of
stanc3
with each release, it would be very simple to make a static web page hosted on github that would enable demos of pedantic mode, canonicalizer (--print-canonical) and other options like that. The "compiling/transpiling/formatting/...." steps are done on the users end.If we make Github Pages for this repository, that could be hosted under
https://mc-stan.org/stanc3/demo
It probably does not make sense to add printing of C++.
Any thoughts?
The text was updated successfully, but these errors were encountered: