/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
stan-web-ide / README.md
90 lines · 3.7 KBCodeBlameHistory
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 1# stan web IDE
3Run [Stan](https://mc-stan.org) sampling in your browser, inside a VS
4Code-style IDE built on [minwebide](https://github.com/magland/minwebide).
5Projects live in your browser's IndexedDB. Models compile on a remote
6[stan-wasm-server](https://github.com/flatironinstitute/stan-playground/tree/main/backend);
7sampling itself runs locally in a web worker with
8[tinystan](https://github.com/WardBrian/tinystan), chains in parallel
9threads.
11**Live site:** https://concept-collection.github.io/stan-web-ide/
13## How it works
15A project holds `.stan` programs, `.json` data files, and `.sample` files. A
16`.sample` file is a YAML description of one sampling run:
18```yaml
19stan: linear.stan # the Stan program
20data: data.json # the data
21output_dir: out/fit # results are written here (replaced on each run)
22num_chains: 4 # optional; defaults 4 / 1000 / 1000 / 2.0 / random
23num_warmup: 1000
24num_samples: 1000
25init_radius: 2.0
26seed: 42 # omit for a random seed
27```
29Paths are relative to the `.sample` file (leading `/` = project root).
30Opening a `.sample` file shows a **form view** — file pickers, sampling
31parameters, a Run button, and per-chain progress bars. The form edits the
32underlying YAML (tab menu → *Reopen as Text Editor* for the raw file); the
33tab bar's ▶/⏹ runs and stops the same way. Runs use current editor contents,
34saved or not.
36A run compiles the program (server-side, cached by source hash), streams
37Stan's console output to the **Output** panel, and writes into
38`output_dir`:
40- `chain_1.csv` … one CSV per chain, header = parameter names, one row per draw
41- `summary.csv` — mean, MCSE, sd, 5%/50%/95%, ESS, ESS/s, split-Rhat per
42 parameter (via [mcmc-stats](https://github.com/flatironinstitute/mcmc-stats.js))
43- `sampling_opts.json` — the exact configuration used (including the
44 resolved seed)
45- `console.txt` — the sampler's console output
47The `.stan` editor has syntax highlighting plus diagnostics, hover docs,
48completion, and auto-format from
49[stan-language-server](https://github.com/tomatitito/stan-language-server)
50(stanc3 compiled to JS, running in a worker).
52## The compilation server
54Compiling Stan to WebAssembly needs a server; everything else is local. The
55status bar shows the configured server (click it to change; persisted in the
56browser). The default is `http://localhost:8083` — run one with:
58```sh
59docker run -p 8083:8080 -it ghcr.io/flatironinstitute/stan-wasm-server:latest
60```
62**CORS**: the server's allowlist must include the page's origin. The stock
63image allows `http://127.0.0.1:3000` and `http://127.0.0.1:4173`, which
64match this app's dev and preview ports — open the `127.0.0.1` URL, not
65`localhost`. To serve other origins (like the live site above), host a
66server whose allowlist includes them.
68Threaded sampling requires cross-origin isolation (`SharedArrayBuffer`):
69dev/preview send COOP/COEP headers; the GitHub Pages deployment uses
70`coi-serviceworker.js`, injected at build time only.
72## Development
74minwebide is consumed as a sibling checkout (`file:../minwebide`):
76```sh
77git clone https://github.com/magland/minwebide ../minwebide
78(cd ../minwebide && npm install) # fetches the pinned VS Code source
79npm install
80npm run dev # http://127.0.0.1:3000
81```
83- `npm run build` — static bundle in `dist/`
84- `npm run typecheck` — typechecks app code (vendor diagnostics suppressed)
85- `npm run smoke` — headless end-to-end test against the built bundle; with
86 a compile server on `localhost:8083` it also compiles and samples for real
87- `node scripts/dev-check.mjs` — quick checks against a running dev server
89CI checks out `magland/minwebide` next to this repo, installs both, builds,
90and publishes `dist/` to GitHub Pages.
moveopenescclose