Skip to content

Commit 80fe389

Browse files
authored
Merge pull request #12 from pythonhealthdatascience/dev
Dev
2 parents d2d7acd + 0cea609 commit 80fe389

40 files changed

+1540
-18915
lines changed

.github/workflows/lint.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file will lint the specified files/directories.
2+
3+
name: lint
4+
5+
on:
6+
push:
7+
branches: [main]
8+
pull_request:
9+
workflow_dispatch:
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Check out repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install python and dependencies
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.13'
23+
cache: 'pip'
24+
- run: pip install -r requirements.txt
25+
26+
- name: Lint model code
27+
run: |
28+
flake8 ./simulation
29+
pylint ./simulation
30+
31+
- name: Lint tests
32+
run: |
33+
flake8 ./tests
34+
pylint ./tests

.github/workflows/tests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# This file runs the tests in `tests/` with every push to GitHub
1+
# This file runs the tests in `tests/`
22
# They will run in parallel, and run on three operating systems:
33
# Ubuntu, Windows and Mac.
44

55
name: tests
66

77
on:
88
push:
9+
branches: [main]
10+
pull_request:
911
workflow_dispatch:
1012

1113
jobs:

.pylintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[MESSAGES CONTROL]
2+
disable=
3+
too-few-public-methods,
4+
too-many-instance-attributes

CITATION.cff

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
cff-version: 1.2.0
55
title: >-
6-
Simple Reproducible Python Discrete-Event Simulation (DES)
7-
Template
6+
Python DES RAP Template
87
message: >-
98
If you use this software, please cite it using the
109
metadata from this file.
@@ -18,8 +17,8 @@ authors:
1817
repository-code: >-
1918
https://github.com/pythonhealthdatascience/rap_template_python_des
2019
abstract: >-
21-
Template reproducible analytical pipeline (RAP) for simple
22-
python DES model.
20+
A template for creating discrete-event simulation (DES) models in Python
21+
within a reproducible analytical pipeline (RAP).
2322
license: MIT
2423
# TODO: Manually update with each GitHub release
2524
version: '0.1.0'

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<div align="center">
22

3-
# Simple Reproducible Python<br>Discrete-Event Simulation (DES) Template
3+
# Python DES RAP Template
44

55
[![python](https://img.shields.io/badge/-Python_3.13-306998?logo=python&logoColor=white)](https://www.python.org/)
66
[![licence](https://img.shields.io/badge/Licence-MIT-green.svg?labelColor=gray)](https://github.com/pythonhealthdatascience/rap_template_python_des/blob/main/LICENSE)
77
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14622466.svg)](https://doi.org/10.5281/zenodo.14622466)
88
[![Tests](https://github.com/pythonhealthdatascience/rap_template_python_des/actions/workflows/tests.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rap_template_python_des/actions/workflows/tests.yaml)
99

10-
A simple template for creating DES models in Python, within a **reproducible analytical pipeline (RAP)** <br>
10+
<br>A template for creating **discrete-event simulation (DES)** models in Python<br>
11+
within a **reproducible analytical pipeline (RAP)**. <br><br>
1112
Click on <kbd>Use this template</kbd> to initialise new repository.<br>
1213
A `README` template is provided at the **end of this file**.
1314

@@ -41,9 +42,9 @@ This repository provides a template for building discrete-event simulation (DES)
4142
♻️ **Reproducible:** This template is designed to function as a RAP. It adheres to reproducibility recommendations from:
4243

4344
* ["Levels of RAP" framework](https://nhsdigital.github.io/rap-community-of-practice/introduction_to_RAP/levels_of_RAP/) from the NHS RAP Community of Practice (`docs/nhs_rap.md`).
44-
* Recommendations from [Heather et al. 2025](TODO:ADDLINK) "*On the reproducibility of discrete-event simulation studies in health research: an empirical study using open models*" (`docs/heather_2025.md`).
45+
* Recommendations from [Heather et al. 2025](https://doi.org/10.48550/arXiv.2501.13137) "*On the reproducibility of discrete-event simulation studies in health research: an empirical study using open models*" (`docs/heather_2025.md`).
4546

46-
🚀 **Extendable:** This template adapts from and complements material from Sammi Rosser and Dan Chalk (2024) ["HSMA - the little book of DES"](https://github.com/hsma-programme/hsma6_des_book). The book includes additional advanced features that can be used to extend the model in this template, including:
47+
🚀 **Extendable:** This template adapts from Sammi Rosser and Dan Chalk (2024) ["HSMA - the little book of DES"](https://github.com/hsma-programme/hsma6_des_book). The book includes additional advanced features that can be used to extend the model in this template, including:
4748

4849
* Multiple activities
4950
* Branching paths
@@ -149,6 +150,12 @@ To run tests, ensure environment is active and located in main directory (i.e. p
149150
pytest
150151
```
151152

153+
To run tests in parallel -
154+
155+
```
156+
pytest -n auto
157+
```
158+
152159
The repository contains a GitHub action `tests.yaml` which will automatically run tests with new commits to GitHub. This is continuous integration, helping to catch bugs early and keep the code stable. It will run the tests on three operating systems: Ubuntu, Windows and Mac.
153160

154161
If you have changed the model behaviour, you may wish to amend, remove or write new tests.
@@ -184,10 +191,12 @@ This section describes the purposes of each class in the simulation.
184191
* `generate_patient_arrivals()` to handle patient creation, then sending them on to `attend_clinic()`.
185192
* `interval_audit()` to record utilisation and wait times at specified intervals during the simulation.
186193

187-
**Trial Class Usage:**
194+
**Runner Class Usage:**
195+
196+
Having set up `experiment = Runner()`...
188197

189-
* **Single Run:** Use `trial.run_single()` to execute a single model run.
190-
* **Multiple Runs:** Use `trial.run_trial()` to perform multiple replications of the model.
198+
* **Single Run:** Use `experiment.run_single()` to execute a single model run.
199+
* **Multiple Runs:** Use `experiment.run_reps()` to perform multiple replications of the model.
191200

192201
<br>
193202

@@ -210,6 +219,7 @@ repo/
210219
├── simulation/ # Local package containing code for the DES model
211220
├── tests/ # Unit and back testing of the DES model
212221
├── .gitignore # Untracked files
222+
├── .pylintrc # Pylint settings
213223
├── CHANGELOG.md # Describes changes between releases
214224
├── CITATION.cff # How to cite the repository
215225
├── CONTRIBUTING.md # Contribution instructions
@@ -230,6 +240,8 @@ The overall run time will vary depending on how the template model is used. A fe
230240
* `choosing_parameters.ipynb` - 22s
231241
* `generate_exp_results.ipynb` - 0s
232242

243+
<!--TODO: Add test times -->
244+
233245
These times were obtained on an Intel Core i7-12700H with 32GB RAM running Ubuntu 24.04.1 Linux.
234246

235247
<br>

docs/heather_2025.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Reproducibility recommendations from Heather et al. 2025
22

3-
As part of the project STARS (Sharing Tools and Artefacts for Reproducible Simulations), a series of computational reproducibility assessments were conducted by Heather et al. 2025 (**TODO: add DOI of pre-print**). From these, several recommendations were shared to support reproducibility of healthcare discrete-event simulation (DES) models. These are copied below. Those marked with a star (⭐) were identified as having the greatest impact in Heather et al. 2025.
3+
As part of the project STARS (Sharing Tools and Artefacts for Reproducible Simulations), a series of computational reproducibility assessments were conducted by [Heather et al. 2025](https://doi.org/10.48550/arXiv.2501.13137). From these, several recommendations were shared to support reproducibility of healthcare discrete-event simulation (DES) models. These are copied below. Those marked with a star (⭐) were identified as having the greatest impact in Heather et al. 2025.
44

55
## Recommendations to support reproduction
66

docs/hsma_changes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ param.patient_inter = 10
132132
model = Model(param)
133133
```
134134

135-
## Saving trial results
135+
## Saving replication results
136136

137-
To save trial-level results in the HSMA models, an empty dataframe is initialised during the __init__ method of the `Trial` class.
137+
To save results from each run in the HSMA models, an empty dataframe is initialised during the __init__ method of the `Trial` class (equivalent to the `Runner` class in this template).
138138

139139
```
140140
self.df_trial_results = pd.DataFrame()
@@ -164,7 +164,7 @@ In the template, results are instead saved as a dictionary into a list as the ru
164164
Also, some of the calculations have been performed directly during the `run_single()` method, instead of from a seperate method `calculate_run_results()`. This is to help simplify the code, as it makes clear how each metric was calculated in one place, rather than needing to refer elsewhere.
165165

166166
```
167-
trial_results = {
167+
run_results = {
168168
'run_number': run,
169169
'scenario': self.param.scenario_name,
170170
'arrivals': len(patient_results),
@@ -176,7 +176,7 @@ trial_results = {
176176
177177
...
178178
179-
self.trial_results_df = pd.DataFrame(trial_results_list)
179+
self.run_results_df = pd.DataFrame(run_results_list)
180180
```
181181

182182
## Extra features

docs/nhs_rap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RAP fundamentals offering resilience against future change.
1515
| Data produced by code in an open-source language (e.g., Python, R, SQL). || Python |
1616
| Code is version controlled (see [Git basics](https://nhsdigital.github.io/rap-community-of-practice/training_resources/git/introduction-to-git/) and [using Git collaboratively](https://nhsdigital.github.io/rap-community-of-practice/training_resources/git/using-git-collaboratively/) guides). || [GitHub](https://github.com/pythonhealthdatascience/rap_template_python_des/) |
1717
| Repository includes a README.md file (or equivalent) that clearly details steps a user must follow to reproduce the code (use [NHS Open Source Policy section on Readmes](https://github.com/nhsx/open-source-policy/blob/main/open-source-policy.md#b-readmes) as a guide). || - |
18-
| Code has been [peer reviewed](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/workflow/code-review/). | | **TODO: Have code peer reviewed, record on GitHub - this would typically be through working on branches and then reviewing code in a pull request before it is merged into the already approved code. Could create empty branch.** |
18+
| Code has been [peer reviewed](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/workflow/code-review/). | | Peer reviewed by Tom Monks |
1919
| Code is [published in the open](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/publishing_code/how-to-publish-your-code-in-the-open/) and linked to & from accompanying publication (if relevant). | ✅ & N/A | Shared openly. No publication. |
2020

2121
## 🥈 Silver

0 commit comments

Comments
 (0)