Skip to content

pythonhealthdatascience/intro-open-sim

Repository files navigation

lite-badge License: MIT Python 3.11+ ORCID: Alison Harper ORCID: Tom Monks ORCID: Amy Heather

An introduction to Discrete-Event Simulation (DES) using Free and Open Source Software

Work in progress. This is a STARS project being prepared for the Operational Research Society 12th Simulation Workshop in 2025 (SW25). It has been adapted from our template repository for sharing simpy models with JupyterLite.

🧑‍💻 1. Tutorial

We being with two notebooks that introduce some basic concepts for creating DES in python:

  • 01_sampling.ipynb: Sampling from statistical distributions using numpy
  • 02_basic_simpy.ipynb: Creating simple simpy DES models that make use of numpy sampling

Your understanding of these is then tested in:

  • 03a_exercise1.ipynb: Exercise to testing understanding of the basics of simpy and numpy
  • 03b_exercise1_solutions.ipynb: Example solutions for the exercise

We then move on to some more advanced concepts, and create a full process model:

  • 04_111_model.ipynb: Full simpy process model, creating a model for a 111 call centre
  • 05_basic_results.ipynb: Collecting results from a single run by storing process metrics during a run and performing calculations at the end

🔧 2. Set-up

To run the notebooks in this tutorial, you can either run via your browser or locally...

2.1 Running notebooks within your browser

This tutorial has been set up to run on your browser without the need to install any components. This is achieved using Web Assembly technology i.e. JupterLite and xeus-python. A model notebook is downloaded to your local machine and all dependencies are pre-installed via conda-forge. The model then lives in the browsers cache. You can make changes to the model or create new files and these are persisted (until the browser cache is cleared).

To access this tutorial in your browser: https://pythonhealthdatascience.github.io/intro-open-sim/.

2.2 Running notebooks locally on your machine

2.2.1 Downloading the code

Either clone the repository using git or click on the green "code" button and select "Download Zip".

git clone https://github.com/pythonhealthdatascience/intro-open-sim.git

2.2.2 Installing dependencies and running JupyterLab

All dependencies can be found in binder/environment.yml and are pulled from conda-forge. To run the code locally, we recommend installing miniforge;

miniforge is FOSS alternative to Anaconda and miniconda that uses conda-forge as the default channel for packages. It installs both conda and mamba (a drop in replacement for conda) package managers. We recommend mamba for faster resolving of dependencies and installation of packages.

navigating your terminal (or cmd prompt) to the directory containing the repo and issuing the following command:

mamba env create -f binder/environment.yml

Activate the mamba environment using the following command:

mamba activate simpy_tutorial

You can then run the notebooks in content/ locally on your machine using JupyterLab. Issue the following command and JupyterLab will open in your browser. Notebooks are in the content/ directory.

jupyter-lab

📝 3. Citation

TBC.

🤝 4. Acknowledgements

We would like to thank the JupterLite and xeus-python developers for making this work possible. This discrete-event simulation focussed tutorial was based on the learning materials and template provided by Jupyterlite xeus-python demo and tutorial given at PyData 2023 by Jeremy Tuloup.

💰 5. Funding

STARS is supported by the Medical Research Council [grant number MR/Z503915/1].