|
| |
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.
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.
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.
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.
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:

|
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:
|