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