Simulation Frameworks Scientific¶
When you'd use this
Tools for discrete-event, agent-based and continuous simulation in Python.
Build and run simulations — physical systems, agents, Monte Carlo — with Python frameworks and numeric backends.
What you'll learn¶
- The three simulation paradigms
- When to use each
- The frameworks for each style
- How simulation connects to the rest of this site
This page maps the simulation frameworks landscape. The runnable examples of each technique live on related pages (linked below) so this stays a focused guide to what tool for what job.
Three paradigms¶
Discrete-event, agent-based, and continuous — pick by how your system changes over time.
Simulation splits into three approaches, each suited to different systems:
DISCRETE-EVENT AGENT-BASED CONTINUOUS
jump between events many agents, solve equations
(queues, logistics) local rules → over time
emergent behavior (physics, chemistry)
→ SimPy → Mesa → NumPy/SciPy
| Paradigm | Models | Time | Example |
|---|---|---|---|
| Discrete-event | Systems that change at distinct moments | Jumps event→event | Bank queue, factory, network |
| Agent-based | Many interacting individuals | Steps or events | Traffic, epidemics, markets |
| Continuous | Quantities evolving smoothly | Small time steps | Orbits, fluid flow, circuits |
Discrete-event simulation → SimPy¶
Model systems that change at discrete events (queues, servers) with SimPy processes.
Time advances by jumping to the next scheduled event, skipping idle periods — hugely efficient for systems that are mostly waiting. You saw a complete, tested discrete-event engine in Hardware Simulation.
For real models, SimPy adds resources (limited servers/tellers), queues, and process interaction on top of Python generators. Use it for operations research: queuing systems, supply chains, service capacity planning.
Agent-based simulation → Mesa¶
Model many interacting agents and watch emergent behavior with Mesa.
Model individual agents with simple local rules; watch complex global behavior emerge. You saw a tested agent-based model (Conway's Game of Life) in Python for Simulation.
Mesa is Python's agent-based framework — it provides agent scheduling, spatial grids, data collection, and visualization. Use it for social science, ecology, epidemiology, and economics where the interesting behavior comes from many interacting entities.
Continuous simulation → NumPy/SciPy¶
Integrate differential equations over time for physical systems.
Systems governed by differential equations evolve continuously; you approximate them with small time steps. You saw tested numerical ODE integration (Euler's method) in Computational Physics.
For real work, SciPy's solve_ivp provides accurate adaptive solvers (Runge-Kutta and more), and NumPy vectorizes the math. Use for physics, engineering, chemical kinetics — anything described by rates of change.
Choosing a paradigm¶
Match the modeling style to whether change is event-driven, agent-driven, or continuous.
Ask what drives change in your system:
- Change happens at distinct events (an arrival, a completion)? → Discrete-event (SimPy).
- Behavior emerges from many individuals following rules? → Agent-based (Mesa).
- Quantities change smoothly and continuously? → Continuous (SciPy).
Some systems mix paradigms (a hybrid model), but most fit one primarily.
Frameworks aren't installed here
SimPy, Mesa, and SciPy aren't in this environment, so their APIs are described rather than run. The techniques behind each are demonstrated with run-verified pure-Python examples on the linked pages — build those to understand what the frameworks automate.
The ecosystem¶
SimPy, Mesa, and SciPy as the go-to simulation tools.
| Paradigm | Framework | Also |
|---|---|---|
| Discrete-event | SimPy | salabim |
| Agent-based | Mesa | AgentPy |
| Continuous / ODE | SciPy | NumPy, JAX |
| Visualization | Matplotlib | see Scientific Visualization |
Practice exercises¶
- Classify five systems (traffic, a chemical reaction, a call center, disease spread, a pendulum) by paradigm.
- Extend the tested Game of Life with data collection (population per step).
- Extend the tested ODE integrator to model a damped oscillator.
- Describe a system that needs a hybrid of two paradigms and why.
- Explain why discrete-event simulation is more efficient than fixed-timestep for a mostly-idle system.
💬 Discussion
Have a question about this topic? Found an error? Share your thoughts below.