21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 1// Message protocol between the app and the sampler web worker.
3/** The config passed to tinystan's model.sample() (unset options use
4 * tinystan defaults: diagonal metric, adapt_delta 0.8, max_depth 10, ...). */
5export interface StanSampleConfig {
6 /** Contents of the data JSON file. */
7 data: string;
8 num_chains: number;
9 num_warmup: number;
10 num_samples: number;
11 init_radius: number;
12 seed: number;
13 /** Iterations between progress lines. */
14 refresh: number;
15 /** One thread per chain runs chains in parallel (needs SharedArrayBuffer). */
16 num_threads: number;
17}
19export interface Progress {
20 chain: number;
21 iteration: number;
22 totalIterations: number;
23 percent: number;
24 warmup: boolean;
25}
27export type WorkerRequest =
28 | { type: 'load'; mainJsUrl: string }
29 | { type: 'sample'; config: StanSampleConfig };
31export type WorkerResponse =
32 | { type: 'loaded'; stanVersion: string }
33 | { type: 'progress'; report: Progress }
34 | { type: 'console'; text: string; level: 'log' | 'error' }
35 | { type: 'done'; draws: number[][]; paramNames: string[] }
36 | { type: 'error'; message: string };