b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 1// Message protocol between the app and the per-chain sampler workers.
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 2
b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 3/** One chain's run configuration — maps onto the compiled model's argv:
4 * <data_json> <seed> <chain_id> <num_warmup> <num_samples> <init_radius>
5 * <refresh>. Unset sampler options use the driver's defaults (diagonal
6 * metric, adapt_delta 0.8, max_depth 10, ... — same as tinystan's). */
7export interface ChainRunConfig {
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 8 /** Contents of the data JSON file. */
9 data: string;
b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 10 /** Same seed for every chain; the chain id differentiates the streams
11 * (CmdStan convention). */
b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 13 /** 1-based. */
14 chainId: number;
15 numWarmup: number;
16 numSamples: number;
17 initRadius: number;
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 18 /** Iterations between progress lines. */
19 refresh: number;
20}
22export interface Progress {
23 chain: number;
24 iteration: number;
25 totalIterations: number;
26 percent: number;
27 warmup: boolean;
28}
b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 30export type WorkerRequest = {
31 type: 'run';
32 /** The compiled model (structured-cloned; workers share the compiled
33 * code and instantiate their own 256 MiB memory). */
34 module: WebAssembly.Module;
35 config: ChainRunConfig;
36};
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 37
38export type WorkerResponse =
39 | { type: 'progress'; report: Progress }
40 | { type: 'console'; text: string; level: 'log' | 'error' }
b1dbd02Switch sampling to pure-WASI web workers; add results dashboardJeremy Magland 41 /** draws[param][draw] for this worker's single chain. */
42 | { type: 'done'; paramNames: string[]; draws: number[][] }
21efcb6stan web IDE: run Stan sampling in the browserJeremy Magland 43 | { type: 'error'; message: string };