STOCHLABSTOCHASTIC SYSTEMS WORKBENCH

REFERENCE / SOURCE & NATIVE TOOLCHAIN

The same engine, in your shell.

The native executable and browser share the C++20 simulation and exchange implementations. Use the CLI for reproducible experiments, larger batches, JSON output, and measured benchmarks.

Get the source

StochLab is open source under the MIT license. The GitHub repository includes the engine, native CLI, browser workbench, tests, and build scripts.

git clone https://github.com/bzzling/stochlab.git
cd stochlab

Start with the README, or inspect the mathematical definitions and algorithms, exchange specification, and validation and measured benchmarks.

Build the native executable

Requirements: a C++20 compiler, CMake 3.20+, and Make. The JSON dependency is vendored, so native builds require no dependency downloads.

make native
./build/stochlab --help

Run an experiment

./build/stochlab simulate brownian --paths 100000 --T 1 --seed 42
./build/stochlab experiment first-passage --barrier 1 --paths 1000000
./build/stochlab simulate ou --theta 2 --mu 0 --sigma 1 --T 10
./build/stochlab simulate hawkes --mu .2 --alpha .7 --beta 1.1 --T 30
./build/stochlab simulate ctmc --Q '[[-2,2],[1,-1]]' --T 100
./build/stochlab exchange --events 100000 --flow hawkes --maker on
./build/stochlab simulate poisson --lambda 5 --T 10 --json

Models: random-walk, brownian, ou, poisson, compound-poisson, ctmc, and hawkes. Experiments: first-passage, reflection, qv, and stationarity.

Validate and measure

make test
make validate
make bench
./build/stochlab bench --json

Benchmarks warm up once, then report the median of three runs. Brownian grid generation measures every increment. First-passage Monte Carlo uses exact terminal/maximum sampling, so its workload is different from generating full paths. Event process benchmarks include simulation and bounded result construction; JSON text serialization is excluded.

Build the web workbench

Use Node.js 22.12+ or 24.2+ and Emscripten 4.0.16. The full installation instructions below install the pinned SDK inside the checkout.

git clone --depth 1 https://github.com/emscripten-core/emsdk.git work/emsdk
cd work/emsdk
./emsdk install 4.0.16
./emsdk activate 4.0.16
cd ../..
source work/emsdk/emsdk_env.sh

npm ci
npm run build:wasm
npm run dev

# Full production build and integration checks
npm run build
npm test
npm run test:browser

Astro prerenders the shell, navigation, and this documentation. React hydrates only the experiment or exchange island. A dedicated Web Worker loads the Emscripten module and calls the C ABI; there is no JavaScript copy of the stochastic algorithms.

Deployment

The production workbench lives at stochlab.brandonling.ca. Cloudflare Workers serves Astro's static pages and the compiled WASM assets. Simulations run locally in your browser; no simulation requests go to a server. The repository's Wrangler configuration declares the custom domain.

# After a successful production build
npx wrangler login
npx wrangler deploy --dry-run
npm run deploy

When deploying your own fork, choose your own Worker name and domain in wrangler.jsonc and update site in astro.config.mjs before building. Authentication stays in your local deployment tooling, outside the source and browser bundle.

Browser commands

:process brownian
:set barrier 1.2
:set paths 100000
:seed 42
:run

:exchange start
:exchange pause
:flow hawkes
:maker enable
:speed 4x

Press Space to run or pause, R to reseed or reset, and : to focus the command line. Arrow keys recall command history. Every command has a visible control counterpart. Configuration changes to the exchange reset its book and RNG.