Part V: Discovery Through Simulation & Optimization
Chapter 43: Scientific Simulation

Scientific Simulation

"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

Sections

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

Gillespie, D. T. (1977). "Exact Stochastic Simulation of Coupled Chemical Reactions." The Journal of Physical Chemistry, 81(25), 2340-2361.

The original paper introducing the Stochastic Simulation Algorithm (SSA), which remains the gold standard for exact simulation of well-stirred biochemical systems.

Beaumont, M. A., Zhang, W., & Balding, D. J. (2002). "Approximate Bayesian Computation in Population Genetics." Genetics, 162(4), 2025-2035.

Introduced the regression-adjustment variant of ABC that made likelihood-free inference practical for complex population genetics models.

Klinger, E., Rickert, D., & Hasenauer, J. (2018). "pyABC: Distributed, Likelihood-Free Inference." Bioinformatics, 34(20), 3591-3593.

The pyABC library paper, describing a scalable Python framework for ABC-SMC with support for distributed computing and adaptive population strategies.

Software and Tools

Kazil, J., Masad, D., & Crooks, A. (2020). "Utilizing Python for Agent-Based Modeling: The Mesa Framework." JOSS, 5(55), 1486.

Mesa: a modular, extensible Python framework for agent-based modeling with built-in visualization and data collection.

Eastman, P., et al. (2017). "OpenMM 7: Rapid Development of High Performance Algorithms for Molecular Dynamics." PLOS Computational Biology, 13(7), e1005659.

OpenMM: GPU-accelerated molecular dynamics with a Python API that makes custom force fields and integrators accessible to non-specialists.

Team SimPy (2023). SimPy: Discrete-Event Simulation for Python.

SimPy: a process-based discrete-event simulation framework built on Python generators, ideal for modeling queuing systems, resource allocation, and workflows.

Books and Reviews

Sisson, S. A., Fan, Y., & Beaumont, M. A. (2018). "Overview of Approximate Bayesian Computation." Annual Review of Statistics and Its Application.

A comprehensive review of ABC methods, from rejection sampling through SMC and regression adjustments, with practical guidance on summary statistic selection.

Bonabeau, E. (2002). "Agent-Based Modeling: Methods and Techniques for Simulating Human Systems." PNAS, 99(suppl 3), 7280-7287.

An accessible introduction to why agent-based modeling captures emergent phenomena that equation-based models miss.