/ concept-collection / stan-remote-sampling
Sign in
concept-collection / stan-remote-sampling
stan-remote-sampling / README.md
48 lines · 1.8 KBPreviewCodeBlameHistoryRaw
1# stan-remote-sampling
3Compile and sample Stan models from the browser, with all computation remote:
5- **Compile**: the Stan program is sent to
6 [stan-wasm-wasi](https://stan-wasm-wasi.fly.dev) (a
7 [stan-playground](https://github.com/flatironinstitute/stan-playground)
8 compilation server variant), which returns the model compiled as a **pure
9 WASI command module** — a sandboxed `.wasm` that runs one MCMC chain per
10 invocation.
11- **Sample**: each chain is submitted as one job to a
12 [wasm-exec](https://github.com/magland/wasm-exec) service (default
13 `https://wasm-exec.fly.dev`), which relays it to attached workers. Progress
14 streams back live (SSE stderr events → per-chain progress bars); draws
15 come back as CSV (SSE stdout events) and are merged across chains.
17Live app: https://concept-collection.github.io/stan-remote-sampling/
19You need a wasm-exec **client key** (`ck_...`) to sample; it is stored in
20localStorage.
22## Notes
24- Chains share a seed and get distinct chain ids (CmdStan convention), so a
25 multi-chain run is statistically equivalent to CmdStan's.
26- First compile after server idle pays a ~30 s machine cold start; compiled
27 models are cached by program hash, so recompiles are instant.
28- wasm-exec jobs run with no filesystem and no network, a 256 MiB memory cap,
29 and a wall-clock timeout. Draw output is bounded by wasm-exec's 10 MiB
30 per-stream cap.
32## Development
34```bash
35npm install
36npm run dev # http://localhost:3000
37```
39Deployment to GitHub Pages is automatic on push to `main`
40(`.github/workflows/deploy.yml`).
42## History
44Built in stages: (1) in-browser sampling with one web worker per chain via
45tinystan (since removed — see git history), (2) a prototype proving Stan
46models compile to pure-WASI modules (now the
47[stan-wasm-wasi](https://github.com/magland/stan-wasm-wasi) repo), (3) this
48remote-only app.
moveopenescclose