1 / 30

Advanced Systems Simulation Capabilities in SimPy

Advanced Systems Simulation Capabilities in SimPy. Klaus G. Müller e-mail: kgmuller@xs4all.nl. Scope of presentation. SimPy ( Sim ulation in Py thon) in a nutshell Advanced capabilities of SimPy Tracing of simulation events – SimulationTrace module Data collection – class Monitor

reed
Download Presentation

Advanced Systems Simulation Capabilities in SimPy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Systems Simulation Capabilities in SimPy Klaus G. Müller e-mail: kgmuller@xs4all.nl

  2. Scope of presentation • SimPy (Simulation in Python) in a nutshell • Advanced capabilities of SimPy • Tracing of simulation events – SimulationTrace module • Data collection – class Monitor • Plotting of results – SimPlot module • Simulation GUI – SimGUI module • Real time synchronization – SimulationRT module • Extensibility -- adding synchronization “verbs” • What users aredoing with SimPy

  3. What Is SimPy? • A Discrete Event Simulation (DES) package • Process based • Object oriented • Modeled after Simula • Written in Python • The only DES package in Python • Open Source (GPL) • Homepage (download, documentation, tutorials): SimPy.SourceForge.Net

  4. Semi-Coroutines Simulate Parallel Processes in SimPy initialize() activate(car,car.drive()) simulate(until=endtime) Generator attributes in Process instances . . . def drive(self): speed=50 yield hold,self,25 def fly(self): speed=800 yield hold,self,25 speed=200 yield hold,self,10 def drive(self): speed=50 yield hold,self,25

  5. Basic SimPy API Entities class Process base class for processes class Resource base class for shared resources Verbs activate() activate a process reactivate() reactivate suspended process cancel() make a process passive interrupt() interrupt suspended process yield hold delay process for a period yield passivate make this process passive yield request request access to resource yield release give up resource

  6. Model scenario • Messages arrive in a LAN at a rate of about 1/minute (calculated from 1000 data points collected) • They are processed by 2 expensive servers at 1 minute/message • To investigate:Could 4 cheaper, slower servers (2 min./message) do at least the same job? • Figures of merit: • Message delays • Nr of messages delayed

  7. Model and SimPy objects

  8. Run! Data file

  9. SimulationTrace module: from Black Box to Glass Box • Insight into parallel processes and their interaction difficult • same problem occurs with simulation • Module SimulationTrace traces all events to show what is happening behind the scenes • Just replace from SimPy.Simulation import *withfrom SimPy.SimulationTrace import* • Trace output can be redirected to a file • Event types to be traced can be selected

  10. Arrival data file (segment)

  11. Run! See trace

  12. Section of trace from file

  13. class Monitor for data collection and statistics • class Monitor (subclass of list) records time series of observed data values for a simulation variable • m = Monitor(name=‘’,ylab=‘y’,tlab=‘t’) • Attributes: • m.yseries() returns a list of the recorded data values. • m.tseries() returns a list of the recorded times. • m.total() returns the sum of the y values • m.count() returns the current number of observations. • m.mean() returns the simple average of the observations • m.var() returns the simple variance of the observations. • m.timeAverage() returns the time-average of the integrated y values,

  14. First model implementation Run!

  15. Plotting results: The SimPlot module • Simulation needs data reduction • By statistics (see class Monitor) • By plotting • SimPlot is SimPy’s plotting module • Tk-based • Derived from Konrad Hinsen’s plotting module • Plots (x,y) data from Monitor instances and other lists • Plot types: • Line, bar, step, histogram, scatter • Basic and advanced API

  16. Run!

  17. Module SimGUI: SimPy’s Graphical User Interface • Satisfies need for simulation user GUI • Point-and-click • Simulation start • Parameter changes • Display/saving of results (raw and analyzed) • Model description • Satisfies need for easy development of simulation GUI • Tk-based simulation GUI framework

  18. Run!

  19. SimulationRT synchronizes simulation with real time • For simulation user interaction e.g. in game applications or animation, events should appear to be spaced in real time • SimulationRT allows tying simulation time to wall clock time • Example: simulate(real_time=True,relSpeed=0.2,until= …)runs1 simulation time unit in 5 real seconds • Module works much better under Windows than under Unix or Linux • Problem stems from time.clock( )

  20. Run!

  21. Extending SimPy:Adding new yield verbs • SimPy’s architecture and Python’s OO nature allow programmers easy addition of new scheduling or synchronization verbs • Example: • Addition of an unbounded buffer entity (class Bin) for producer/consumer synchronization • yield put,self,<Bin-instance>,<quantity>(non-blocking) for insertion into buffer • yield get,self,<Bin-instance>,<quantity>(blocking) for taking out from buffer

  22. Using the new get and put verbs Run!

  23. What are users doing with SimPy? • Teaching system simulation • Simulation of epidemics • Simulation of computer hardware • Simulation nuclear processing facilities in support of designing safeguards for nuclear non-proliferation • Visual simulation/animation which compares Personal Rapid Transit (PRT) and classic rapid transit systems like light rail or metro • Simulation of air space surveillance • Simulation of telescope management in observatory • . . . . • ? ? ? ?

More Related