/ concept-collection / stan-remote-sampling
Sign in
concept-collection / stan-remote-sampling
stan-remote-sampling
Go to fileHistoryFork
.githubStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
srcStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
.gitignoreStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
index.htmlStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
package-lock.jsonStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
package.jsonStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
README.mdStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
tsconfig.jsonStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec
vite.config.tsStan remote sampling: compile via stan-wasm-wasi, sample via wasm-exec

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 (a 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 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#

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 repo), (3) this remote-only app.

moveopenescclose