Saturday, April 20, 2024

SimPy, To Simulate With Python

- Advertisement -

Shared resources come in handy while modelling limited-capacity congestion points like servers, checkout counters and tunnels. While the first process gets the resource first, it can be configured to release the resource when the job is done, or the release could be automated. The resource is then handed over to the process waiting in line.

Talking about resources, you can choose the resource according to the specific task at hand. Dealing with simulation of a water tank would need a container, or if the system is about a fruits shop with a variety of elements, a store comes to the aid. If you are modelling a machine shop with machines having variable attributes, go for FillerStore. The above is the case of going around the homogenous slots of a resource to get what you need.

Environment is as important as the process

When the very functioning of one’s system depends Box299on its interaction with its surroundings, the environment takes precedence. A common base environment is generally used as the norm, performing simulations as fast as possible, while a real-time application demands a separate environment for itself. This could be when the system involves hardware or human interaction. SimPy takes this factor into account and provides separate environments for the two.

- Advertisement -

Further, the way SimPy works, environment is simply not the factor that encompasses the whole, but it is this simulation environment that manages simulation time, scheduling and processing of events, and takes care of execution. You can flow through this processing in different ways: step through in steps, run for a given time, run till simulation stops on its own or flag the trigger of an event.

A peek-and-step feature lets you step through the simulation event-by-event. To integrate the simulation via the graphical user interface, you can repeatedly call a for-loop as below, with repeatedly increasing values, thereby letting you update the process bar according to the progress of the simulation:

 foriinrange(100):
env.run(until=i)
progressbar.update(i)

How to check what is happening

It is the basic code that you write in SimPy that decides the entire process at hand. It is then obvious to want to observe how the system is functioning, or maybe to cross-check expected behaviour. With monitoring in SimPy, you can monitor the various processes at hand, how each parameter is handled, the way resources are allocated and used, and trace every event of the simulation.

Monitoring can alert you when a certain event happens or if a certain event does not happen. This could be done at regular intervals or you can even set the monitoring routine to begin if and when something goes wayward, and choose to store the results as a file, a list or directly in the database.

Simply using SimPy

Though it is theoretically possible to perform continuous simulations on SimPy, as a library built for discrete simulation, it does not offer any special features for the same. On the other hand, SimPy is overkill for fixed-step-size processes that do not interact with each other or share resources. It is up to you to exploit the built-in features for the right applications and ease the load.

Download latest version of the software: click here


Priya Ravindran is M.Sc (electronics) from VIT University, Vellore, Tamil Nadu. She loves to explore new avenues and is passionate about writing

 

SHARE YOUR THOUGHTS & COMMENTS

Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Calculators