/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
stan-web-ide / src / stan / protocol.ts
43 lines · 1.4 KBBlameHistoryRaw
1// Message protocol between the app and the per-chain sampler workers.
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 {
8 /** Contents of the data JSON file. */
9 data: string;
10 /** Same seed for every chain; the chain id differentiates the streams
11 * (CmdStan convention). */
12 seed: number;
13 /** 1-based. */
14 chainId: number;
15 numWarmup: number;
16 numSamples: number;
17 initRadius: number;
18 /** Iterations between progress lines. */
19 refresh: number;
22export interface Progress {
23 chain: number;
24 iteration: number;
25 totalIterations: number;
26 percent: number;
27 warmup: boolean;
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};
38export type WorkerResponse =
39 | { type: 'progress'; report: Progress }
40 | { type: 'console'; text: string; level: 'log' | 'error' }
41 /** draws[param][draw] for this worker's single chain. */
42 | { type: 'done'; paramNames: string[]; draws: number[][] }
43 | { type: 'error'; message: string };
moveopenescclose