SimPy: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
No edit summary
 
imported>Frap
Add portal
 
Line 18: Line 18:
| website = {{URL|simpy.readthedocs.org}}
| website = {{URL|simpy.readthedocs.org}}
}}
}}
{{Portal|Free and open-source software}}
'''SimPy''' stands for '''“Simulation in Python”,''' is a process-based [[discrete-event simulation]] [[Software framework|framework]] based on standard [[Python (programming language)|Python]].<ref>{{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 }}</ref> It enables users to model active components such as customers, vehicles, or agents as simple Python [[Generator (computer programming)|generator functions]]. SimPy is released as [[Open-source software|open source]] software under the [[MIT License]]. The first version was released in December 2002.<ref>{{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}}</ref>
'''SimPy''' stands for '''“Simulation in Python”,''' is a process-based [[discrete-event simulation]] [[Software framework|framework]] based on standard [[Python (programming language)|Python]].<ref>{{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 }}</ref> It enables users to model active components such as customers, vehicles, or agents as simple Python [[Generator (computer programming)|generator functions]]. SimPy is released as [[Open-source software|open source]] software under the [[MIT License]]. The first version was released in December 2002.<ref>{{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}}</ref>


Line 39: Line 40:
...
...
>>> env = simpy.Environment()
>>> env = simpy.Environment()
>>> env.process(clock(env, 'fast', 0.5))
>>> env.process(clock(env, "fast", 0.5))
<Process(clock) object at 0x...>
<Process(clock) object at 0x...>
>>> env.process(clock(env, 'slow', 1))
>>> env.process(clock(env, "slow", 1))
<Process(clock) object at 0x...>
<Process(clock) object at 0x...>
>>> env.run(until=2)
>>> env.run(until=2)

Latest revision as of 22:47, 3 July 2025

Template:Short description Script error: No such module "about".

Script error: No such module "Infobox".Template:Template other Script error: No such module "Check for unknown parameters".Script error: No such module "Check for conflicting parameters". Script error: No such module "Portal". SimPy stands for “Simulation in Python”, is a process-based discrete-event simulation framework based on standard Python.[1] 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.[2]

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.[3]

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.,[4] while SimPy 4.0 requires Python 3.6+. SimPy distribution contains tutorials,[5] documentation, and examples.

Example

The following is a SimPy simulation[6] 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))
<Process(clock) object at 0x...>
>>> env.process(clock(env, "slow", 1))
<Process(clock) object at 0x...>
>>> env.run(until=2)
fast 0
slow 0 
fast 0.5 
slow 1 
fast 1.0 
fast 1.5

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "Citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "Citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "Citation/CS1".
  6. Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".