SimPy Overview

Up Next

 

bulletWhat is SimPy?
bulletWhat is SimPy used for?
bulletIntroductory presentations on SimPy
bulletA simple SimPy program
bulletThe SimPy GUI
bulletPlot output from SimPy
bulletArticles on SimPy

What is SimPy?

SimPy (= Simulation in Python) is an object-oriented, process-based discrete-event simulation language based on standard Python and released under the GNU GPL. It provides the modeller with components of a simulation model including processes, for active components like customers, messages, and vehicles, and resources, for passive components that form limited capacity congestion points like servers, checkout counters, and tunnels. It also provides Monitor variables to aid in gathering statistics. Random variates are provided by the standard Python random module.

Many users claim that SimPy is one of the cleanest, easiest to use discrete event simulation packages!

SimPy comes with data collection capabilities, GUI and plotting packages. It can be easily interfaced to other packages, such as plotting, statistics, GUI, spreadsheets, and data bases.

Back to Top

What is SimPy used for?

SimPy has very wide applicability. It is already being used for

Modelling/simulation of epidemics
Traffic simulation
Air space surveillance planning
Industrial engineering
Computer hardware performance studies
Performance modelling
Industrial process optimization
Workflow studies
Teaching of simulation methodology

. . . plus a lot of applications we don't know about.

 Back to Top

Introductory presentations on SimPy

This slide show (a presentation by one of the original SimPy developers at EuroPython 2003) gives an overview of how SimPy works and shows a number of sample programs.

And here is a presentation on advanced capabilities of SimPy (given at EuroPython 2004).

Robert Ramsdell of the Great Lakes Dredge & Dock Company gave a great presentation on SimPy at the 10 March 2005 meeting of the Chicago Python Users Group. He used examples from his company's business to illustrate some of SimPy's constructs and capabilities.

Back to Top

A simple SimPy program

What does a SimPy program look like?

Here is a program modelling fireworks with two rockets, 'stars' and 'screamer'.  

from __future__ import generators                       # only needed in Python 2.2
from SimPy.Simulation import *                          # (0)

class Firework(Process):                                # (1)
   
def __init__(self,name):
       
Process.__init__(self)
       
self.name=name

   
def fire(self):                                      # (2)
       
print now(), self.name, "rocket launched"
       
for i in range(10):
           
yield hold,self,1.0                          # (3)
           
print now(), self.name, "rocket flying"
       
yield hold,self,2.0                              # (3)
       
print now(), self.name,'goes Boom!!'

initialize()                                            # (4)
screamer = Firework(name="Screamer")                    # (5)
activate(screamer,screamer.fire(),at=0.0)               # (6)
stars = Firework(name="Stars")                          # (7)
activate(stars,stars.fire(),at=5.0)                     # (8)
simulate(until=100)                                     # (9)

"""Output:
0 Screamer rocket launched
1.0 Screamer rocket flying
2.0 Screamer rocket flying
3.0 Screamer rocket flying
4.0 Screamer rocket flying
5.0 Stars rocket launched
5.0 Screamer rocket flying
6.0 Stars rocket flying
6.0 Screamer rocket flying
7.0 Stars rocket flying
7.0 Screamer rocket flying
8.0 Stars rocket flying
8.0 Screamer rocket flying
9.0 Stars rocket flying
9.0 Screamer rocket flying
10.0 Stars rocket flying
10.0 Screamer rocket flying
11.0 Stars rocket flying
12.0 Screamer goes Boom!!
12.0 Stars rocket flying
13.0 Stars rocket flying
14.0 Stars rocket flying
15.0 Stars rocket flying
17.0 Stars goes Boom!!
"""

What is going on?

(0): The SimPy Simulation package is imported.
(1): A class Fireworks is defined as a sub-class of Process to allow Fireworks instances to be dynamic, i.e., contain quasi-parallel processes with events.
(2): A generator method (Process Execution Method) fire is defined, the dynamic part of Fireworks.
(3): 'yield hold,self,<wait time>' statements make a process wait (suspend its execution) for <wait time> simulated time units.
(4): Here, the simulation framework is initialized.
(5): The screamer instance of Fireworks is defined and given a name.
(6): The screamer.fire process is activated at simulated time 0.0.
(7): The stars instance of Fireworks is defined and given a name.
(8): The stars.fire process is activated at simulated time 5.0.
(9): The simulation execution is started, with an upper bound on the simulated time of 100.

The output shows the result of the quasi-parallel execution of the two fire processes.

Back to Top

The SimPy GUI

SimPy has a programmable GUI (graphical user interface) for running simulations, inputting parameters, viewing and saving output, getting help, and a lot more.

The following minimal program hints at what this GUI looks like. 

from SimPy.SimGUI import *
root=Tk()
gu=SimGUI(root,consoleHeight=20)
gu.mainloop()

Screen output resulting from running above program:

images/Minimal.png

 

Back to Top

Plot output from SimPy

SimPy provides a plotting package for visualizing simulation output. It produces screen output and also allows saving of plots in Postscript format.

Here are a few plots showing the type of output that can be generated:

 

 

Back to Top

Articles and other SimPy publications

bulletSimPy Tutorial page by Prof. Norman Matloff, University of California, Davis
 
bulletAn introductory presentation on SimPy by Dr. Klaus Müller (one of the SimPy inventors and developers); presented at EuroPython 2003 in Charleroi, Belgium.
        
bulletAdvanced systems simulation capabilities in SimPy (PDF format) by Dr. Klaus Müller; presented at EuroPython 2004 in Gothenburg, Sweden. (Same presentation in Microsoft PowerPoint format -- click here.) 
 
bullet "Charming Python: SimPy simplifies complex models" by Dr. David Mertz
 
bullet"SimPy: Simulating Systems in Python" by Dr. Klaus Müller and Prof. Tony Vignaux (the other SimPy inventor and simulation modelling guru) 
Back to Top

 

 

horizontal rule

©Copyright 2004, 2005, 2006, 2007, 2008 SimPy Developer Team.
For problems or questions regarding this web contact SimPy webmaster.
Last updated: 19/03/08.