"I simulated a thousand universes before lunch. In 743 of them, the hypothesis held. In the rest, lunch was cancelled."
A Gillespie Algorithm That Lost Track of Time
Overview
Scientific simulation turns a mathematical model into a computational experiment. Where physical experiments probe nature directly, simulations probe our understanding of nature: you encode your hypotheses as rules, press play, and watch whether the emergent behavior matches what you observe in the real world. When it does, you gain confidence in the mechanism. When it does not, you learn exactly which assumption breaks, because every rule is explicit and every parameter is tunable.
This chapter covers the core simulation paradigms that drive modern scientific discovery. We begin with computational experiments as a discipline (Section 43.1): agent-based models for complex systems, discrete-event simulation for processes with queuing and resource constraints, and the design principles that make simulations reproducible and analyzable. Section 43.2 dives into the stochastic and molecular scales, covering the Gillespie algorithm for exact stochastic simulation of chemical kinetics, molecular dynamics with OpenMM, and trajectory analysis with MDAnalysis. Section 43.3 addresses the central challenge of simulation-based science: calibration. When your simulator has no tractable likelihood function, Approximate Bayesian Computation (ABC) and its sequential variant ABC-SMC let you infer parameters by comparing simulated and observed summary statistics. Finally, Section 43.4 assembles these techniques into a complete recipe: a stochastic biochemical simulator calibrated with ABC-SMC that supports counterfactual interventions for mechanistic discovery.
Prerequisites
This chapter builds on Chapter 5 (Discovery Through Data, Models, and Simulation), where we introduced simulation as one of three discovery paradigms, and Chapter 42 (Differentiable Programming), which covered gradient-based approaches to scientific computing. Familiarity with Chapter 32 (Bayesian Discovery and Uncertainty) will help with the ABC material but is not strictly required; we develop the necessary Bayesian intuition from scratch. You should be comfortable with Python, NumPy, and basic probability (distributions, sampling, Bayes' theorem).
What You Will Learn
- Build agent-based models with Mesa and discrete-event simulations with SimPy for complex systems research.
- Implement the Gillespie algorithm for exact stochastic simulation of chemical reaction networks.
- Set up molecular dynamics simulations with OpenMM and analyze trajectories with MDAnalysis.
- Generate synthetic data from simulators to train, validate, and augment machine learning models.
- Apply Approximate Bayesian Computation (ABC) and ABC-SMC to calibrate simulators with intractable likelihoods.
- Construct a complete calibrated simulator pipeline that supports counterfactual interventions for mechanistic discovery.
- Integrate calibrated simulators into the Discovery Workbench for automated hypothesis testing.
Sections
43.1 Computational Experiments
Agent-based models with Mesa, discrete-event simulation with SimPy, and the principles that make computational experiments reproducible and analyzable.
43.2 Stochastic Simulation and Molecular Dynamics
The Gillespie algorithm for chemical kinetics, molecular dynamics with OpenMM, trajectory analysis with MDAnalysis, and generating synthetic data from simulators.
43.3 Simulator Calibration
Approximate Bayesian Computation for likelihood-free inference, ABC-SMC for efficient posterior approximation, and summary statistic selection for calibration quality.
43.4 Building a Calibrated Simulator
A hands-on recipe: stochastic biochemical simulator calibrated with ABC-SMC, counterfactual interventions, and integration with the Discovery Workbench.
What's Next
Scientific simulators encode explicit mechanistic knowledge: every rule, every rate constant, every interaction is specified by the modeler. But what if you could learn the simulator itself from data? Chapter 44: World Models for Discovery explores neural simulators that learn dynamics from observations, bridging the gap between the interpretable but manually constructed simulators of this chapter and the data-driven representations of Chapter 33. The calibration techniques you learned here (especially ABC-SMC) will return in Chapter 44 as baselines against which learned world models are evaluated.
Bibliography
Foundational Papers
The original paper introducing the Stochastic Simulation Algorithm (SSA), which remains the gold standard for exact simulation of well-stirred biochemical systems.
Introduced the regression-adjustment variant of ABC that made likelihood-free inference practical for complex population genetics models.
The ABC-SMC framework for sequential posterior refinement, enabling efficient calibration of complex dynamical models.
The pyABC library paper, describing a scalable Python framework for ABC-SMC with support for distributed computing and adaptive population strategies.
Software and Tools
Mesa: a modular, extensible Python framework for agent-based modeling with built-in visualization and data collection.
OpenMM: GPU-accelerated molecular dynamics with a Python API that makes custom force fields and integrators accessible to non-specialists.
MDAnalysis: a Python library for reading, transforming, and analyzing molecular dynamics trajectories across dozens of formats.
SimPy: a process-based discrete-event simulation framework built on Python generators, ideal for modeling queuing systems, resource allocation, and workflows.
Books and Reviews
A comprehensive review of ABC methods, from rejection sampling through SMC and regression adjustments, with practical guidance on summary statistic selection.
An accessible introduction to why agent-based modeling captures emergent phenomena that equation-based models miss.