Skip to main content

💫 Towards Sharing Tools, and Artefacts, for Reusable Simulation (STARS): a minimal model example

Binder License: MIT Python DOI PyPI version fury.io

Overview

The materials and methods in this repository support work towards developing the STARShealthcare framework (Sharing Tools and Artifacts for Reusable Simulations in healthcare). The code and written materials here demonstrate the application of STARS to sharing a SimPy discrete-event simulation model and associated research artifacts.

  • All artifacts in this repository are linked to study researchers via ORCIDs;
  • Model code is made available under an MIT license;
  • Python dependencies are managed through mamba;
  • Documentation of the model is enhanced using a simple Jupyter notebook.
  • The python model itself can be viewed and executed in Jupyter notebooks via Binder;
  • The materials are deposited and made citable using Zenodo;
  • The model is sharable with other researchers and the NHS without the need to install software.
  • A full suite of automated tests are provided with the model.

Author ORCIDs

ORCID: Harper ORCID: Monks ORCID: Heather

Funding

This code is part of independent research supported by the National Institute for Health Research Applied Research Collaboration South West Peninsula. The views expressed in this publication are those of the author(s) and not necessarily those of the National Institute for Health Research or the Department of Health and Social Care.

Between May 2024 and October 2026 this work has was supported by the MRC.

Instructions to run the model

Install from PyPI

If you do not wish to view the code or would like to use the model as part of your own work you can install the model as a python package.

pip install treat-sim

Online Notebooks via Binder

The python code for the model has been setup to run online in Jupyter notebooks via binder Binder

mybinder.org is a free tier service. If it has not been used in a while Binder will need to re-containerise the code repository, and push to BinderHub. This will take several minutes. After that the online environment will be quick to load.

To download code and run locally

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/stars-treat-sim

Installing dependencies

Python

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 stars_treat_sim

Running the model

To run 50 multiple replications across a number of example experiments, use the following code:

from treat_sim.model import (get_scenarios, run_scenario_analysis,
                             scenario_summary_frame, 
                             DEFAULT_RESULTS_COLLECTION_PERIOD)

if __name__ == '__main__':

    results = run_scenario_analysis(get_scenarios(), 
                                    DEFAULT_RESULTS_COLLECTION_PERIOD,
                                    n_reps=50)

    results_summary = scenario_summary_frame(results)
    print(results_summary)

Alternative you can design and execute individual experiments by creating a Scenario object:

from treat_sim.model import Scenario, multiple_replications

if __name__ == '__main__':

    # use all default parameter values
    base_case = Scenario()

    results = multiple_replications(base_case).describe().round(2).T
    print(results)

The model can be run with different time dependent arrival profiles. By default the model runs with the arrival profile taken from Nelson (2013). The datasets module provides access to an alternative example dataset where arrivals are slightly skewed towards the end of the working day.

from treat_sim.model import Scenario, multiple_replications
from treat_sim.datasets import load_alternative_arrivals

if __name__ == '__main__':

    # set the arrival profile to later in the day
    scenario1 = Scenario(arrival_profile=load_alternative_arrivals())

    alternative_results = multiple_replications(scenario1).describe().round(2).T
    print(alternative_results)

Testing the model

See our online documentation for an overview of testing

To run tests activate the virtual environment and entre the following command:

pytest

Alternatively to recieve a test coverage estimate issue the following command

pytest --cov=treat_sim tests/

To run the tests in multiple python environments i.e. Python 3.10 to 3.13 use:

hatch test --all

Repo overview

.
├── binder
│   └── environment.yml
├── CHANGES.md
├── CITATION.cff
├── LICENSE
├── notebooks
│   └── test_package.ipynb
├── pyproject.toml
├── README.md
├── tests
│   └── test_datasets.ipynb
│   └── test_model.ipynb
└── treat_sim
    ├── data
    │   └── ed_arrivals.csv
    │   └── ed_arrivals_scenario1.csv
    ├── __init__.py
    ├── datasets.py
    └── model.py
  • binder/ - contains the environment.yml file (sim) and all dependencies managed via conda, used to set-up the notebooks on Binder.
  • CHANGES.md - changelog with record of notable changes to project between versions.
  • CITATION.cff - citation information for the package.
  • LICENSE - details of the MIT permissive license of this work.
  • notebooks/ - contains a notebook to run the model and provides basic enhanced model documentation.
  • pyproject.toml - used to build and distribute python package inc. managing a list of package dependencies.
  • README.md - what you are reading now!
  • tests/ - contains automated testing code
  • treat_sim/ - contains packaged version of the model.
    • data/ - directory containing data file used by package.
    • __init__.py - required as part of package - contains author and version.
    • datasets.py - functions to load example dataset for parameterising the model.
    • model.py - example SimPy model.

Citation

If you use the materials within this repository we would appreciate a citation.

Monks, T., Harper, A., & Heather, A. (2024). Towards Sharing Tools, and Artifacts, for Reusable Simulation: a minimal model example (v2.1.0). Zenodo. https://doi.org/10.5281//zenodo.10026326
@software{stars_treat_sim,
  author       = {Thomas Monks, Alison Harper and Amy Heather},
  title        = {{Towards Sharing Tools, and Artifacts, for Reusable 
                   Simulation: a minimal model example}},
  month        = May,
  year         = 2024,
  publisher    = {Zenodo},
  version      = {v2.2.0},
  doi          = {10.5281//zenodo.10026326.},
  url          = {https://doi.org/10.5281//zenodo.10026326}
}

Release files for treat-sim 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treat-sim 3.0.0
File Size Uploaded
treat_sim-3.0.0.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for treat-sim 3.0.0
File Interpreter ABI Platform
treat_sim-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / treat_sim-3.0.0.tar.gz

Download URL treat_sim-3.0.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1110dc67de0d52ede669f0c053996cdf66783995025a11e2eaf2b7c2581b08b5
BLAKE2b-256 checksum
How to use checksums
35e0641fe8923e1fc8ccd123a85cf5276f2e0f86d64ac0981984e34bc8cf8f6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 11, 2026.

Transparency log

Release files / treat_sim-3.0.0-py3-none-any.whl

Download URL treat_sim-3.0.0-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15c6b375f649919624d2efd125a4a4e71f105396329462a18201867c29c6037a
BLAKE2b-256 checksum
How to use checksums
8c8e895ee804d530274056952df418688d55a39812cd35ffbcd3d16096c0650f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page