Skip to content
Merged

Dev #12

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
739cdf5
style(analysis): remove unnecessary legend from spread plots
amyheather Jan 23, 2025
2112ee5
style(choosing parameters): convert num rep plots to subplots, and sa…
amyheather Jan 23, 2025
4010d26
style(notebooks): render non-interactive px figures for GitHub, and s…
amyheather Jan 24, 2025
2363f8f
style(spelling): correct license to licence (where not referring to a…
amyheather Jan 24, 2025
4230a5e
refactor(class): renamed Trial to Runner, run_trial() to run_reps(), …
amyheather Jan 28, 2025
1757636
refactor(choosing parameters): round cores run times to .5 sec to avo…
amyheather Jan 28, 2025
204b052
ci(tests): alter so runs action on push to main, pull request or manu…
amyheather Jan 28, 2025
f5eb145
style(readme): alter title + description in README and CITATION.cff
amyheather Jan 28, 2025
ccccebb
build(env): add pylint
amyheather Jan 28, 2025
05c24b6
style(lint): linting .py files and add .pylintrc
amyheather Jan 28, 2025
bc76dda
ci(lint): add github action to lint .py files
amyheather Jan 28, 2025
dd9b28a
ci(lint): alter to any push, so can initialise/test on dev
amyheather Jan 28, 2025
71a22df
ci(lint): switch back to just push to main
amyheather Jan 28, 2025
598adbf
refactor(scenarios): moved run_scenarios() to model.py
amyheather Jan 28, 2025
14199b1
feat(model): add MonitoredResource, alternative warm-up results colle…
amyheather Jan 28, 2025
75cd9ca
chore(notebooks): re-run analysis and choosing-parameters - results c…
amyheather Jan 28, 2025
029b05b
build(env): add pytest-xdist
amyheather Jan 28, 2025
1144800
docs(draw.io): update model structure diagram, adding MonitoredResource
amyheather Jan 28, 2025
24683ad
fix(model): Fixed bug in MonitoredResource where activities scheduled…
amyheather Jan 28, 2025
b8ee8f8
test(unittest): add some tests for MonitoredResource
amyheather Jan 28, 2025
f7d5a41
bug(choosing parameters): running this notebook since changes, there …
amyheather Jan 28, 2025
618b1c3
docs(README/.md): update README and RAP checklists
amyheather Jan 28, 2025
7aafc1c
style(plots): set template 'plotly_white'
amyheather Jan 29, 2025
15b396e
feat(time weighted): add .ipynb in docs/ to explain how time-weighted…
amyheather Jan 29, 2025
1f37514
Merge branch 'main' into dev
amyheather Jan 29, 2025
0cea609
style(analysis): removed legend (got re-add accidentally when dealing…
amyheather Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file will lint the specified files/directories.

name: lint

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:

- name: Check out repository
uses: actions/checkout@v4

- name: Install python and dependencies
uses: actions/setup-python@v4
with:
python-version: '3.13'
cache: 'pip'
- run: pip install -r requirements.txt

- name: Lint model code
run: |
flake8 ./simulation
pylint ./simulation

- name: Lint tests
run: |
flake8 ./tests
pylint ./tests
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# This file runs the tests in `tests/` with every push to GitHub
# This file runs the tests in `tests/`
# They will run in parallel, and run on three operating systems:
# Ubuntu, Windows and Mac.

name: tests

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
Expand Down
4 changes: 4 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[MESSAGES CONTROL]
disable=
too-few-public-methods,
too-many-instance-attributes
7 changes: 3 additions & 4 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

cff-version: 1.2.0
title: >-
Simple Reproducible Python Discrete-Event Simulation (DES)
Template
Python DES RAP Template
message: >-
If you use this software, please cite it using the
metadata from this file.
Expand All @@ -18,8 +17,8 @@ authors:
repository-code: >-
https://github.com/pythonhealthdatascience/rap_template_python_des
abstract: >-
Template reproducible analytical pipeline (RAP) for simple
python DES model.
A template for creating discrete-event simulation (DES) models in Python
within a reproducible analytical pipeline (RAP).
license: MIT
# TODO: Manually update with each GitHub release
version: '0.1.0'
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div align="center">

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

[![python](https://img.shields.io/badge/-Python_3.13-306998?logo=python&logoColor=white)](https://www.python.org/)
[![licence](https://img.shields.io/badge/Licence-MIT-green.svg?labelColor=gray)](https://github.com/pythonhealthdatascience/rap_template_python_des/blob/main/LICENSE)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14622466.svg)](https://doi.org/10.5281/zenodo.14622466)
[![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)

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

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

* ["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`).
* 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`).
* 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`).

🚀 **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:
🚀 **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:

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

To run tests in parallel -

```
pytest -n auto
```

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.

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

**Trial Class Usage:**
**Runner Class Usage:**

Having set up `experiment = Runner()`...

* **Single Run:** Use `trial.run_single()` to execute a single model run.
* **Multiple Runs:** Use `trial.run_trial()` to perform multiple replications of the model.
* **Single Run:** Use `experiment.run_single()` to execute a single model run.
* **Multiple Runs:** Use `experiment.run_reps()` to perform multiple replications of the model.

<br>

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

<!--TODO: Add test times -->

These times were obtained on an Intel Core i7-12700H with 32GB RAM running Ubuntu 24.04.1 Linux.

<br>
Expand Down
2 changes: 1 addition & 1 deletion docs/heather_2025.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reproducibility recommendations from Heather et al. 2025

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.
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.

## Recommendations to support reproduction

Expand Down
8 changes: 4 additions & 4 deletions docs/hsma_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ param.patient_inter = 10
model = Model(param)
```

## Saving trial results
## Saving replication results

To save trial-level results in the HSMA models, an empty dataframe is initialised during the __init__ method of the `Trial` class.
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).

```
self.df_trial_results = pd.DataFrame()
Expand Down Expand Up @@ -164,7 +164,7 @@ In the template, results are instead saved as a dictionary into a list as the ru
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.

```
trial_results = {
run_results = {
'run_number': run,
'scenario': self.param.scenario_name,
'arrivals': len(patient_results),
Expand All @@ -176,7 +176,7 @@ trial_results = {

...

self.trial_results_df = pd.DataFrame(trial_results_list)
self.run_results_df = pd.DataFrame(run_results_list)
```

## Extra features
Expand Down
2 changes: 1 addition & 1 deletion docs/nhs_rap.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RAP fundamentals offering resilience against future change.
| Data produced by code in an open-source language (e.g., Python, R, SQL). | ✅ | Python |
| 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/) |
| 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). | ✅ | - |
| 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.** |
| Code has been [peer reviewed](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/workflow/code-review/). | | Peer reviewed by Tom Monks |
| 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. |

## 🥈 Silver
Expand Down
Loading
Loading