Let’s Go! An Introduction to Discrete Event Simulation and SimPy
A standalone workshop for the NHS-OA community from the team behind the ARC South West Health Service Modelling Associates (HSMA) Programme.
Start with the overview, check the itinerary, or go straight to the slides and exercises in Part 1 and Part 2. Visit Additional resources and next steps to keep learning after the workshop.
Why discrete event simulation?
Discrete Event Simulation (DES) is a simulation modelling technique that helps us tackle queuing problems in health and social care. These might include identifying delays in patient pathways and testing the impact of reconfiguring processes and resources to reduce those delays.
DES projects in the HSMA Programme have led to significant impact nationally, including:
- Mental health care in Devon: the construction of an £11.8 million new mental health ward to allow patients in crisis to be seen closer to home. Read the project poster.
- Urgent care in London: transformative improvements to urgent care delivery. Read the project poster.
- Stroke care in Kent: potential annual savings of £1 million or more and improved patient outcomes. Read the project poster.
What you will learn
- The principles of DES and the kinds of problems this modelling approach can tackle.
- The importance of variability and stochasticity in simulation modelling.
- How to design reproducible stochastic models.
- How to build these models in Python using SimPy, including Python generator functions and structuring code using object oriented programming.
- How to add animated visualisations to SimPy models using the vidigi package.
Some prior coding experience is recommended, but no Python experience is assumed. You will be introduced to the components of a SimPy model and the Python code used to build them, then have a chance to adapt the code to write your own models.
No local Python installation is required. We will use Google Colab to write and run code. You will need a free Google account.
About this workshop
This workshop pilots new content and exercises written for the upcoming seventh round of the HSMA Programme, due to launch in 2027. Find out more about the HSMA Programme.
An introduction to discrete event simulation (DES) concepts and SimPy, followed by three exercises.
Open the DES and SimPy slides · Download the slides (PDF)
Video
The workshop content begins at the timestamp 10:42.
Explore the DES Playground to try out simulation concepts.
Open the DES Playground in a new tab for the best experience - click here: playground.hsma.co.uk
Design a DES model for a fish and chip shop. Read the brief below, then compare your design with the proposed solutions when you are ready.

Chalk’s Chips is the number 1 fish and chip establishment in Cornwall, thanks to the passion, ingenuity and foresight of its owner - Dan Chalk. Nevertheless, Dan is keen to see if things can be improved even further to make things more efficient, and generate even more cash to spend on pasties. To this end, he’d like to use Discrete Event Simulation to model his chip shop to see how everything’s running, and has asked you to draft a design for what that model might look like.
Chalk’s Chips offers both a sit-in restaurant service and a takeaway service.
Restaurant
- The restaurant doesn’t take bookings, and instead operates a walk-in service, with a waiting area where prospective diners can wait for a table, although when it’s particularly busy, customers may either leave if they’re waiting too long, or not enter if they see the waiting area is too busy.
- Once a table is free, customers choose their food and drink from chalkboard menus on the table (nice touch), and shortly after a server will take their order.
- The server passes the order over to the kitchen, and when the cooks are free, the meals are cooked up, and left on the serving counter for a server to take to the table.
- Once diners have finished eating, a server presents them with a bill which they pay for at the table, before leaving.
Takeaway
- The takeaway service operates in a separate part of the building with its own entrance and counter, overlooking the Chalk’s Chips kitchen.
- Customers order at the counter with a member of counter staff, and then wait for the food to be cooked in the kitchen.
- Once the order’s ready it’s placed into the hot counter, and when a member of counter staff is ready, they call out the customer’s name, ask them if they want salt and vinegar to be applied, and bag up the order before handing it to the customer, who then leaves.
- When the takeaway service is particularly busy, some customers may choose not to wait before they’ve ordered their food, or choose not to come in in the first place if they see it’s too busy in there.
Telephone
Chalk’s Chips also has a telephone situated in the lobby, which is located between the takeaway and restaurant areas. Phone calls are answered by either restaurant servers or counter staff, depending on whoever’s free at the time, though if there’s no answer for a while, it’s not unusual for the caller to hang up.
Activity
You need to draw up a diagram (if you’re stuck for what to use, you might try https://www.drawio.com/) for what a DES model of Chalk’s Chips could look like. In particular, you should clearly indicate : - The generators and sinks, what they represent, and which entities the generators are bringing into being - The activities to be modelled, what resources are needed (if any) for each activity, and what the associated queue represents in terms of the resources it’s waiting for (if applicable)
If you manage to do all that in the time, consider if there are any attributes that the entities might have that might be useful to model.
When we come back we’ll ask a few groups to present their designs. There are no right or wrong answers here - we do have a “Potential Solution” but model design is an art form, and there may be different ways you come up with to model the system (IMPORTANT - you would also normally design a model based on the “what if?” questions it needs to answer, which you don’t know here)
Explore the workshop example and four proposed solutions created by the groups on the day. These show different approaches to modelling the same system; there is no single correct design. Select a tab to view a solution, and use the full-size image link to inspect the detail.
Open the workshop example at full size

Open the Blockers solution at full size

Open the Bombers solution at full size

Open the Builders solution at full size
Open the Floaters solution at full size

Explore and edit a SimPy model using the workshop notebook.
Open the notebook in Google Colab · Download the notebook (.ipynb)
If you cannot access Google Colab, download the notebook and open it in an IDE such as VS Code or Positron.
Visualisation with vidigi and resources to continue your DES journey.
Open the vidigi slides on the web · Download the introduction to animation in DES slides (Animaniacs PDF)
For the best experience, use the ‘on the web’ link above or the preview below. Use your left and right arrow keys to navigate through the slides, or click the three horizontal lines in the bottom left corner to open up the table of contents.
Video
Use the vidigi Playground for the visualisation exercises.
Open the vidigi Playground in a new tab for the best experience - click here: hsma-programme.github.io/nhs_oa_vidigi_streamlit
Continue your DES journey with the resources and opportunities from slides 82–93 of the workshop presentation.
Keep learning
| Resource | What you will find |
|---|---|
| HSMA 6 DES recordings | Full recordings and exercises from the DES module. Explore the other HSMA modules too. |
| The Little Book of DES | A free book covering the HSMA 6 DES material and more advanced concepts. |
| DES RAP Book | Amy Heather’s guide to reproducible DES modelling in Python and R. |
| Healthcare Services Analytics & Decision Support Atlas | DES resources and models from the NHS and related organisations. |
| vidigi documentation | A getting started guide and examples for adding animation to your own models. |
The HSMA 6 recordings and Little Book of DES use an earlier model structure than the one taught in this workshop, but remain useful for developing your understanding.
Put your learning into practice
- Read, run and reuse an existing model. The Strategy Unit’s ReModel Club brings people together to run, assess and adapt open healthcare simulation models. Find out how to join.
- Share what you build. If you create a model after this workshop, we would love to hear about it. Email penchord@exeter.ac.uk or tag the team in the NHS-OA Slack.
- Keep in touch. Email penchord@exeter.ac.uk to ask to join the HSMA mailing list, or follow HSMA on LinkedIn.
Take the next step with HSMA 7
HSMA 7 will include an expanded DES module with over 30 hours of content. Alongside DES, HSMA 7 will cover geographic modelling and machine learning, as well as developing skills in web application development, interactive reporting, data visualisation and automation.
The programme combines learning with a project for your organisation:
- Learn: six months of training, one day a week.
- Apply: nine months working on a real project, with an expectation of one day a week and guidance and support.
- Implement: support for implementation and gathering evidence of impact from month 15 onwards.
Revisit the additional resource slides
Download slides 82–93 (PDF) · Open the full presentation in Google Slides
The excerpt from the part 1 slides below includes the resource links, HSMA programme information and participant feedback shown in the workshop. If the preview is unavailable on your device, use the PDF download link above.