|
1 | | -[](https://pythonhealthdatascience.github.io/stars-simpy-jupterlite/notebooks/?path=01_urgent_care_model.ipynb) |
| 1 | +[](https://pythonhealthdatascience.github.io/intro-open-sim/lab/index.html) |
2 | 2 | [](https://opensource.org/licenses/MIT) |
3 | | -[](https://doi.org/10.5281/zenodo.10987817) |
4 | | -[](https://www.python.org/downloads/release/python-3100/) |
5 | | -[](https://orcid.org/0000-0001-5274-5037) |
6 | | -[](https://orcid.org/0000-0003-2631-4481) |
| 3 | +[](https://www.python.org/downloads/release/python-3100/) |
| 4 | +[](https://orcid.org/0000-0001-5274-5037) |
| 5 | +[](https://orcid.org/0000-0003-2631-4481) |
| 6 | +[](https://orcid.org/0000-0002-6596-3479) |
7 | 7 |
|
8 | | -# An introduction to Discrete-Event Simulation using Free and Open Source Software. |
| 8 | +# An introduction to Discrete-Event Simulation (DES) using Free and Open Source Software |
9 | 9 |
|
10 | | -> Work in progress. This is a STARS project being prepared for [SW25](https://www.theorsociety.com/ORS/ORS/Events/2025/Simulation-Workshop/SW25.aspx) |
| 10 | +> Work in progress. This is a STARS project being prepared for the [Operational Research Society 12th Simulation Workshop in 2025 (SW25)](https://www.theorsociety.com/ORS/ORS/Events/2025/Simulation-Workshop/SW25.aspx). It has been adapted from our [template repository](https://github.com/pythonhealthdatascience/stars-simpy-jupterlite) for sharing `simpy` models with JupyterLite. |
11 | 11 |
|
12 | | -## 1. Overview |
| 12 | +## 🧑💻 1. Tutorial |
13 | 13 |
|
14 | | -The materials and methods in this repository support work towards developing the S.T.A.R.S healthcare framework version 1.5 (**S**haring **T**ools and **A**rtifacts for **R**eproducible **S**imulations in healthcare). The code and written materials here are a work in progress to demonstrate the application of S.T.A.R.S' version to sharing a `simpy` discrete-event simuilation model and associated research artifacts. |
| 14 | +We being with two notebooks that introduce some basic concepts for creating DES in python: |
15 | 15 |
|
16 | | -The model will run on a users browser without the need to install any components. This is achieved using Web Assembly technology i.e. [JupterLite](https://github.com/jupyterlite/jupyterlite) and [xeus-python](https://github.com/jupyter-xeus/xeus-python). A model notebook is downloaded to the users local machine and all dependencies are pre-installed via conda-forge. The model then lives in the browsers cache. The user can make changes to the model or create new files and these are persisted (until the browser cache is cleared). |
| 16 | +* `01_sampling.ipynb`: Sampling from statistical distributions using `numpy` |
| 17 | +* `02_basic_simpy.ipynb`: Creating simple `simpy` DES models that make use of `numpy` sampling |
17 | 18 |
|
18 | | -> Try it in your browser now: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite |
| 19 | +Your understanding of these is then tested in: |
19 | 20 |
|
20 | | -### 1.1. Use case |
| 21 | +* `03a_exercise1.ipynb`: Exercise to testing understanding of the basics of `simpy` and `numpy` |
| 22 | +* `03b_exercise1_solutions.ipynb`: Example solutions for the exercise |
21 | 23 |
|
22 | | -* A researcher wishes to share a runnable version of a simulation model with their publication (e.g. written in `simpy`). The code allows others to replicate the simulation results, tables and charts in a paper and allows others to reuse the model. |
23 | | -* The researcher wants the model to be immediately usable. Users should not need to install python, `simpy` or any dependencies. |
24 | | -* The researcher either wants to reduce load on online open science compute infrastructure (e.g. mybinder.org) or does not want to rely on it. |
25 | | -* Users may want to use a version of their own data due to governance, ethics or other reasons **cannot upload the data to a remote instance of the model.** |
26 | | -* Loading the model is as simple as clicking a URL. |
| 24 | +We then move on to some more advanced concepts, and create a full process model: |
27 | 25 |
|
28 | | -### 1.2. Credits ✨ |
| 26 | +* `04_111_model.ipynb`: Full `simpy` process model, creating a model for a 111 call centre |
| 27 | +* `05_basic_results.ipynb`: Collecting results from a single run by storing process metrics during a run and performing calculations at the end |
29 | 28 |
|
30 | | -> We would like to thank the [JupterLite](https://github.com/jupyterlite/jupyterlite) and [xeus-python](https://github.com/jupyter-xeus/xeus-python) developers for making this work possible. This discrete-event simulation focussed repository was based on the learning materials and template provided by [Jupyterlite xeus-python demo](https://github.com/jupyterlite/xeus-python-demo) and [tutorial given at PyData 2023](https://www.youtube.com/watch?v=WXRslU9D3bo) by Jeremy Tuloup. |
| 29 | +## 🔧 2. Set-up |
31 | 30 |
|
32 | | -### 1.3. Citation |
| 31 | +To run the notebooks in this tutorial, you can either run via your browser or locally... |
33 | 32 |
|
34 | | -If you use the template in your work we would greatly appreciate a citation when you publish your work. |
| 33 | +### 2.1 Running notebooks within your browser |
35 | 34 |
|
36 | | -> Monks, T., & Harper, A. (2024). Simpy JupyterLite Template (v0.1.0). Zenodo. https://doi.org/10.5281/zenodo.10987817 |
| 35 | +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](https://github.com/jupyterlite/jupyterlite) and [xeus-python](https://github.com/jupyter-xeus/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). |
37 | 36 |
|
38 | | -``` |
39 | | -@software{monks_harper_jupyterlite_template, |
40 | | - author = {Monks, Thomas and |
41 | | - Harper, Alison}, |
42 | | - title = {Simpy JupyterLite Template}, |
43 | | - month = apr, |
44 | | - year = 2024, |
45 | | - publisher = {Zenodo}, |
46 | | - version = {v0.1.0}, |
47 | | - doi = {10.5281/zenodo.10987817}, |
48 | | - url = {https://doi.org/10.5281/zenodo.10987817} |
49 | | -} |
50 | | -``` |
51 | | - |
52 | | - |
53 | | -## 2. The example model included |
54 | | - |
55 | | -The `simpy` model is adapted from [Monks and Harper (2023)](https://github.com/pythonhealthdatascience/stars-simpy-example-docs) |
56 | | - |
57 | | -> Monks, T., & Harper, A. (2023). Towards Sharing Tools and Artifacts for Reusable Simulation: example enhanced documentation for a simpy model. (v1.1.0). Zenodo. https://doi.org/10.5281/zenodo.10054063 |
58 | | -
|
59 | | -Full documentation of this model is available in our [JupyterBook](https://pythonhealthdatascience.github.io/stars-simpy-example-docs) |
60 | | - |
61 | | -In summary, we adapt a textbook example from Nelson (2013): a terminating discrete-event simulation model of a U.S based treatment centren summary the model. The example is based on exercise 13 from Nelson (2013) page 170. |
62 | | - |
63 | | -> *Nelson. B.L. (2013). [Foundations and methods of stochastic simulation](https://www.amazon.co.uk/Foundations-Methods-Stochastic-Simulation-International/dp/1461461596/ref=sr_1_1?dchild=1&keywords=foundations+and+methods+of+stochastic+simulation&qid=1617050801&sr=8-1). Springer.* |
64 | | -
|
65 | | -## 3. Try the example DES in your browser |
66 | | - |
67 | | -* Jupyterlab: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite |
68 | | -* Classic notebook: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite/notebooks/?path=01_urgent_care_model.ipynb |
| 37 | +> ✨ **To access this tutorial in your browser:** <https://pythonhealthdatascience.github.io/intro-open-sim/>. |
69 | 38 |
|
70 | | -## 4. Using the template to create a new repo. |
| 39 | +### 2.2 Running notebooks locally on your machine |
71 | 40 |
|
72 | | -> There are three steps: i.) create a new repo form the template; ii.) modify you repo settings so that GitHub pages are built from Actions. iii.) Commit changes and trigger the GitHub Action and deployment. We recommend reading all instructions first. |
| 41 | +You can also run the notebooks in `content/` locally on your machine. You'll need to install the provided conda environment `environment.yml`. |
73 | 42 |
|
74 | | -Let's assume you wanted to create a new discrete-event simulation model of cancer services. |
75 | | - |
76 | | -1. The first step is to copy the template. Click on the green "use this template" button in the top right and select "create a new repository" |
77 | | -2. You will be prompted to enter a name of the repository - e.g. `cancer_model` - and a short description |
78 | | -3. Click on "Create Repository" |
79 | | - |
80 | | - |
81 | | - |
82 | | -The JuypterLite interactive website is built from GitHub actions. **In the newly created repo for your model** do the following |
83 | | - |
84 | | -4. Navigate to "Settings->Pages" |
85 | | -5. Under "Build and Deployment" set the "Source" to "GitHub actions". |
86 | | - |
87 | | - |
88 | | - |
89 | | -By default the build is trigged on any commit to the `main` branch. Push a small commit and it will trigger the build. This will take a few minutes. Your site will be published under https://{USERNAME}.github.io/{DEMO_REPO_NAME} |
| 43 | +``` |
| 44 | +conda env create --name xeus-python-kernel --file environment.yml |
| 45 | +conda activate xeus-python-kernel |
| 46 | +``` |
90 | 47 |
|
91 | | -## 5. How to install extra packages supporting your DES model. 📦 |
| 48 | +## 📝 3. Citation |
92 | 49 |
|
93 | | -The repo contains two environment files. To install more dependencies for your DES model and analysis you need to edit the ``environment.yml`` file. |
| 50 | +TBC. |
94 | 51 |
|
95 | | -The template ``environment.yml`` is as follows: |
| 52 | +## 🤝 4. Acknowledgements |
96 | 53 |
|
| 54 | +<!--TODO: Is this just relevant to the template repository, or likewise to this one?--> |
97 | 55 |
|
98 | | -```yml |
99 | | -name: xeus-python-kernel |
100 | | -channels: |
101 | | - - https://repo.mamba.pm/emscripten-forge |
102 | | - - conda-forge |
103 | | -dependencies: |
104 | | - - xeus-python |
105 | | - - ipycanvas |
106 | | - - simpy=4.1.1 |
107 | | - - numpy |
108 | | - - pandas |
109 | | - - matplotlib |
110 | | -``` |
| 56 | +We would like to thank the [JupterLite](https://github.com/jupyterlite/jupyterlite) and [xeus-python](https://github.com/jupyter-xeus/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](https://github.com/jupyterlite/xeus-python-demo) and [tutorial given at PyData 2023](https://www.youtube.com/watch?v=WXRslU9D3bo) by Jeremy Tuloup. |
111 | 57 |
|
112 | | -**Key points:** |
113 | | -
|
114 | | -* There are two channels in use. |
115 | | - * `encription-forge` contains specific versions of the packages for web assembly These include `numpy` `pandas`, and `matplotlib`. Other popular packages include `scipy`, `scikit-learn` and `pytest`. |
116 | | - * `conda-forge` for other installs you can use conda-forge. Only ``no-arch`` packages from ``conda-forge`` can be installed (simpy qualifies) |
117 | | -* Note that `numpy`, `pandas` and `matplotlib` have specific versions available on `enscription-forge`. For this reason we recommend not including the package version number. |
118 | | -* `simpy` is installed from `conda-forge` we were therefore able to freeze the version to 4.1.1 to aid reproducibility. |
119 | | -* At the time of writing the xeus-python kernal will use python 3.11.3 |
120 | | - |
121 | | -As an example modification assume that you wanted to add two new packages: `plotly` and `scipy`. The first `plotly` is available ``no-arch`` from conda-forge so it is safe to include and if you wanted to you could try to include a version number. There is a specific version of `scipy` is available on `encription-forge` |
122 | | - |
123 | | -Our modified environment looks like: |
124 | | - |
125 | | -```yml |
126 | | -name: xeus-python-kernel |
127 | | -channels: |
128 | | - - https://repo.mamba.pm/emscripten-forge |
129 | | - - conda-forge |
130 | | -dependencies: |
131 | | - - xeus-python |
132 | | - - ipycanvas |
133 | | - - simpy=4.1.1 |
134 | | - - numpy |
135 | | - - pandas |
136 | | - - matplotlib |
137 | | - - plotly |
138 | | - - scipy |
139 | | -``` |
| 58 | +## 💰 5. Funding |
140 | 59 |
|
141 | | -If you wanted to use an alternative simulation package to `simpy` this would need to be available on `conda-forge` and be ``no-arch``. An example package is `salabim`. A modification of the enviroment is: |
142 | | - |
143 | | - |
144 | | -```yml |
145 | | -name: xeus-python-kernel |
146 | | -channels: |
147 | | - - https://repo.mamba.pm/emscripten-forge |
148 | | - - conda-forge |
149 | | -dependencies: |
150 | | - - xeus-python |
151 | | - - ipycanvas |
152 | | - - salabim |
153 | | - - numpy |
154 | | - - pandas |
155 | | - - matplotlib |
156 | | - - plotly |
157 | | - - scipy |
158 | | -``` |
| 60 | +STARS is supported by the Medical Research Council [grant number [MR/Z503915/1](https://gtr.ukri.org/projects?ref=MR%2FZ503915%2F1)]. |
0 commit comments