A Monte Carlo engine for event-driven risk and cost models, in Go, with exact answers wherever the model allows them.
A model is a directed acyclic graph. Sources emit events at a rate per period; each event walks the graph from the node it enters, booking values at the nodes it passes, choosing an outcome at each, and holding for a while where the model says so. The engine simulates periods and reports the period total, its breakdown by category and source, the events and values at each node, quantiles, the exceedance curve and who the tail belongs to. Beside the simulation it computes the exact mean, variance and probability of an empty period from the graph, and for most models the exact distribution of the period total by FFT, bracketed between rigorous bounds, with no sampling at all.
- Rates: a constant or an uncertain rate drawn once per period (Poisson or mixed-Poisson counts); a source that fires on every n-th arrival of its stream; a source silent for a repair after each firing; a reliability block diagram of components with mean times between failures and repairs, simulated exactly as a Markov chain of the units; and shared factors that scale several rates at once, the common shock that makes a bad year bad for every risk together; and schedules, cycles of multipliers that give a rate its season or shift pattern.
- Nodes: values booked on entry or per unit of time held, in any of twenty-two distribution families with truncation and caps; a selection of outcomes with fixed or uncertain probabilities, as shares or tried in order; holding times, including the outage of the reliability block that fired the event; values and probabilities drawn once per period and shared by every event in it.
- Structure: several graphs in one model, templates instanced with overrides, categories added across the model; totals the model names over chosen categories, each reported as the total is, a net one subtracting some of them with the chance it is at or below zero, and categories kept outside the total, such as hours or revenue beside cost.
- Queues: a node that serves its rounds first come, first served with a number of servers of one speed, each round bringing its own work, carrying its line from period to period or emptying it at each period's end; the report gives the wait and stay with their quantiles, the line and the servers' utilisation.
- Where it starts: the steady state, or a started run, a horizon of periods repeated from an empty start or from a given state, the rounds waiting or in service at each queue with their ages and the rounds part-way through a holding time, reported period by period with each period's exact mean where the paths allow, beside the horizon's total.
docs/format.md is the reference for the YAML model file, and
examples/ holds twenty-eight complete models with a README saying what
each shows, from a one-line compound loss to a register of a hundred
risks, a plant as a block diagram, and a shift with its own period.
go run ./cmd/variate run -f examples/compound.yaml # simulate to the plan's criteria
go run ./cmd/variate run -f examples/compound.yaml --analytic # with the exact distribution
go run ./cmd/variate plan -f examples/compound.yaml # the convergence plan and work
go run ./cmd/variate stream -f examples/sequential.yaml --leaf undetected --rounds csv
go run ./cmd/variate sweep -f examples/pump_station.yaml --figure p99 --top 5
go run ./cmd/variate compare -f examples/pump_station.yaml --option other.yaml --figure p99
run reports a table, JSON or CSV, and with --at total=150 (or
--at category:labour=40, repeated as needed) also the chance a
period reaches each value and of staying under it, counted in the run
with its standard error rather than read off the histogram. With
--when total>=1/100 (a value, or 1/N for the level reached once in
N periods, or a band such as --when "total in [1/10,1/100)") it also
says what those periods are made of: each category's, source's and
node's mean in them and share of their total, each with its standard
error, and a return period's level with its error; plan says how many periods each
convergence criterion needs and what the run will cost; stream
writes the rounds, the path each event takes with the values it
books, filtered to a node or a leaf; sweep moves each input the
model gives a range, how far its frequency, value, probability, holding
time, factor, schedule or block component's MTBF or MTTR could
plausibly be off, to the two ends of that range and ranks the inputs by how far they move a figure: the
mean, a quantile, a return period's loss, P(T = 0), or a layer's,
category's or source's mean (--screen 0.1 moves every input by a
tenth instead, to see which deserve a range). Its rows are exact where
the analytic means give the figure, brackets where the exact
distribution applies, and otherwise simulated at one seed, the moved
models drawing alike wherever the move does not reach, so that each
difference's standard error is measured on paired blocks: every draw is
keyed by what it is, its period, source, round and the node, function
or holding by name, not by its place in the model. compare sets
options against the model, each a model file of its own run with the
model's settings: each option's figure, its difference from the
model's and, for a simulated row, that difference's standard error on
the same paired blocks, a small fraction of what two independent runs
would give where an option changes little. A run without a period count
continues until every criterion is met: enough hits on every outcome,
a small enough error on every mean, enough periods in the tail. The
same model, seed and block size repeat a run exactly.
make demo builds the engine to WebAssembly with TinyGo and serves a
page at http://127.0.0.1:8000/ with every example as a model with
knobs, or any model pasted as YAML. A run draws the histogram and
exceedance curve of the total or of any category, source, node or
trigger's sum, with
return periods and the exact bounds when asked for; the sources'
contributions and who the tail belongs to beyond a return period; a
source's events per period against a Poisson reference; the totals
over the run; what the uncertain inputs could do to the mean, as a
tornado chart;
and the compiled graph as a flow diagram. A run can be
pinned as a baseline and the next drawn beside it, for
cheaper-and-slower against faster-and-dearer. The page lives under
web/; cmd/variate-wasm is the engine's browser entry point. A host
that builds the engine into its own WebAssembly applies the same limits
with browser.Apply: one worker, and the transform's work and memory
budgets that keep it within a browser's time and wasm32's memory.
The variate-python repository, MIT-licensed, builds a model in
Python and runs it through the variate command, the model crossing as
a YAML file and the report returning as JSON. The engine runs as a
separate program, so a notebook, a library or a product built on the
package takes on none of the engine's obligations; embedding the engine
itself is what this repository's licence and its commercial licences
cover. variate plan --format json, variate sweep --format json and
the series in the JSON report exist for it.
make ci runs what runs on every push: formatting, vet, the linters
and the project's own analyzers, the escape and allocation checks on
the hot path, the race detector, the suite again with a 32-bit int
(the width of TinyGo's wasm target), a TinyGo build of the browser
engine, the fuzzers and the vulnerability scan. make stat is the
long statistical suite, make bench the benchmarks against a
baseline, make wasm-test the engine's tests as wasm under the wazero
runtime, and make race the race detector run. The engine's test
suites live in internal/suite, against the public API only; the root
keeps the tests that reach inside. internal/lint is a separate
module holding the project's checkers. The engine allocates nothing
while a run is going, has no recursion and bounds every loop, and the
build checks each of these with a tool wherever a tool can.
Copyright © 2026 Eitanity Systems VCC.
Variate is free software under the GNU Affero General Public License,
version 3 (see LICENSE). Any work that links it, calls it over a
network or ships it must be offered under the same terms, source
included. Commercial licences are available for those terms do not
suit.