SimPy

From Vero - Wikipedia
Jump to navigation Jump to search

Template:Short description Template:About

Template:Infobox software Template:Portal SimPy stands for “Simulation in Python”, is a process-based discrete-event simulation framework based on standard Python.<ref>Template:Cite journal</ref> 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.<ref>Template:Cite book</ref>

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.<ref>Template:Cite journal</ref>

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.,<ref>Template:Cite web</ref> while SimPy 4.0 requires Python 3.6+. SimPy distribution contains tutorials,<ref>Template:Cite journal</ref> documentation, and examples.

Example

The following is a SimPy simulation<ref>Template:Cite web</ref> showing a clock process that prints the current simulation time at each step: <syntaxhighlight lang="pycon"> >>> 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 </syntaxhighlight>

References

Template:Reflist