SimPy

{{Short description|Process-based discrete-event simulation framework based on standard Python}}

{{About||the Python symbolic mathematics library|SymPy|the discontinued social bookmarking service|Simpy}}

{{Infobox software

| name = SimPy

| title = SimPy, a free discrete-event simulation package based on Python

| logo = SimPy logo.svg

| logo size = 200px

| author = Klaus G. Müller, Tony Vignaux

| developer = Ontje Lünsdorf, Stefan Scherfke

| released = {{Start date and age|2002|09|17}}

| latest release version = 4.1.1

| latest release date = {{Start date and age|2023|11|12}}

| programming language = Python

| operating system = Cross-platform

| genre = Discrete event simulation

| license = MIT

| website = {{URL|simpy.readthedocs.org}}

}}

SimPy stands for “Simulation in Python”, is a process-based discrete-event simulation framework based on standard Python.{{Cite journal |last1=Iwata |first1=Curtis |last2=Mavris |first2=Dimitri |date=2013-01-01 |title=Object-Oriented Discrete Event Simulation Modeling Environment for Aerospace Vehicle Maintenance and Logistics Process |journal=Procedia Computer Science |volume=16 |pages=187–196 |doi=10.1016/j.procs.2013.01.020 |issn=1877-0509|doi-access=free }} It enables users to model active components such as customers, vehicles, or agents as simple Python generator functions. SimPy is released as open source software under the MIT License. The first version was released in December 2002.{{Cite book |last1=Xiong |first1=Xinli |last2=Ma |first2=Linru |last3=Cui |first3=Chao |chapter=Simulation Environment of Evaluation and Optimization for Moving Target Defense: A SimPy Approach |date=2020-01-13 |title=Proceedings of the 2019 9th International Conference on Communication and Network Security |chapter-url=https://doi.org/10.1145/3371676.3371692 |series=ICCNS '19 |location=New York, NY, USA |publisher=Association for Computing Machinery |pages=114–117 |doi=10.1145/3371676.3371692 |isbn=978-1-4503-7662-4}}

Overview

Its event dispatcher is based on Python's generators and can be used for asynchronous networking or to implement multi-agent systems (with both, simulated and real communication). Simulations can be performed “as fast as possible”, in real time (wall clock time) or by manually stepping through the events. Though it is theoretically possible to do continuous simulations with SimPy, it lacks features to support them. However, for simulations with a fixed step size where processes don't interact with each other or with shared resources, a simple while loop is sufficient.{{Cite journal |last1=Olaitan |first1=Oladipupo |last2=Geraghty |first2=John |last3=Young |first3=Paul |last4=Dagkakis |first4=Georgios |last5=Heavey |first5=Cathal |last6=Bayer |first6=Martin |last7=Perrin |first7=Jerome |last8=Robin |first8=Sebastien |date=2014-01-01 |title=Implementing ManPy, a Semantic-free Open-source Discrete Event Simulation Package, in a Job Shop |journal=Procedia CIRP |volume=25 |pages=253–260 |doi=10.1016/j.procir.2014.10.036 |issn=2212-8271|doi-access=free }}

Additionally, SimPy provides different types of shared resources to simulate congestion points that have limited capacity, such as servers, checkout counters, and tunnels. In version 3.1 and above, SimPy offers monitoring capabilities to assist in collecting statistics about processes and resources.

SimPy 3.0 requires Python 3.,{{Cite web |title=SimPy History & Change Log — SimPy 4.0.2.dev1+g2973dbe documentation |url=https://simpy.readthedocs.io/en/latest/about/history.html}} while SimPy 4.0 requires Python 3.6+. SimPy distribution contains tutorials,{{cite journal |last1=Zinoviev |first1=Dmitry |date=February 2018 |title=Discrete Event Simulation. It's Easy with SimPy! |journal=PragPub |issue=104 |pages=1–16}} documentation, and examples.

Example

The following is a SimPy simulation{{Cite web|url=https://stefan.sofa-rockers.org/downloads/simpy-ep14.pdf#page=5|title=Discrete-event simulation with SimPy|last=Scherfke|first=Stefan|date=July 25, 2014|website=|publisher=|page=5|format=PDF|access-date=August 10, 2016}} showing a clock process that prints the current simulation time at each step:

>>> import simpy

>>>

>>> def clock(env, name, tick):

... while True:

... print(name, env.now)

... yield env.timeout(tick)

...

>>> env = simpy.Environment()

>>> env.process(clock(env, 'fast', 0.5))

>>> env.process(clock(env, 'slow', 1))

>>> env.run(until=2)

fast 0

slow 0

fast 0.5

slow 1

fast 1.0

fast 1.5

References