Skip to content

Commit d6d7b32

Browse files
authored
Initial commit
0 parents  commit d6d7b32

File tree

14 files changed

+2897
-0
lines changed

14 files changed

+2897
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# updated 02/10/24 to be inline with main JupyterLite demo
2+
name: Build and Deploy
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- '*'
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install mamba
25+
uses: mamba-org/setup-micromamba@v1
26+
with:
27+
micromamba-version: '1.5.8-0'
28+
environment-file: build-environment.yml
29+
cache-environment: true
30+
31+
- name: Build the JupyterLite site
32+
shell: bash -l {0}
33+
run: |
34+
cp README.md content
35+
jupyter lite build --contents content --output-dir dist
36+
37+
- name: Upload artifact
38+
uses: actions/upload-pages-artifact@v3
39+
with:
40+
path: ./dist
41+
42+
deploy:
43+
needs: build
44+
if: github.ref == 'refs/heads/main'
45+
permissions:
46+
pages: write
47+
id-token: write
48+
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
*.bundle.*
2+
lib/
3+
node_modules/
4+
.yarn-packages/
5+
*.egg-info/
6+
.ipynb_checkpoints
7+
*.tsbuildinfo
8+
9+
# Created by https://www.gitignore.io/api/python
10+
# Edit at https://www.gitignore.io/?templates=python
11+
12+
### Python ###
13+
# Byte-compiled / optimized / DLL files
14+
__pycache__/
15+
*.py[cod]
16+
*$py.class
17+
18+
# C extensions
19+
*.so
20+
21+
# Distribution / packaging
22+
.Python
23+
build/
24+
develop-eggs/
25+
dist/
26+
downloads/
27+
eggs/
28+
.eggs/
29+
lib/
30+
lib64/
31+
parts/
32+
sdist/
33+
var/
34+
wheels/
35+
pip-wheel-metadata/
36+
share/python-wheels/
37+
.installed.cfg
38+
*.egg
39+
MANIFEST
40+
41+
# PyInstaller
42+
# Usually these files are written by a python script from a template
43+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
44+
*.manifest
45+
*.spec
46+
47+
# Installer logs
48+
pip-log.txt
49+
pip-delete-this-directory.txt
50+
51+
# Unit test / coverage reports
52+
htmlcov/
53+
.tox/
54+
.nox/
55+
.coverage
56+
.coverage.*
57+
.cache
58+
nosetests.xml
59+
coverage.xml
60+
*.cover
61+
.hypothesis/
62+
.pytest_cache/
63+
64+
# Translations
65+
*.mo
66+
*.pot
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# pyenv
78+
.python-version
79+
80+
# celery beat schedule file
81+
celerybeat-schedule
82+
83+
# SageMath parsed files
84+
*.sage.py
85+
86+
# Spyder project settings
87+
.spyderproject
88+
.spyproject
89+
90+
# Rope project settings
91+
.ropeproject
92+
93+
# Mr Developer
94+
.mr.developer.cfg
95+
.project
96+
.pydevproject
97+
98+
# mkdocs documentation
99+
/site
100+
101+
# mypy
102+
.mypy_cache/
103+
.dmypy.json
104+
dmypy.json
105+
106+
# Pyre type checker
107+
.pyre/
108+
109+
# OS X stuff
110+
*.DS_Store
111+
112+
# End of https://www.gitignore.io/api/python
113+
114+
# jupyterlite
115+
*.doit.db
116+
_output

.nojekyll

Whitespace-only changes.

CITATION.cff

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This CITATION.cff file was generated with cffinit.
2+
# Visit https://bit.ly/cffinit to generate yours today!
3+
4+
cff-version: 1.2.0
5+
title: Simpy JupyterLite Template
6+
message: >-
7+
If you use this software, please cite it using the
8+
metadata from this file.
9+
type: software
10+
authors:
11+
- given-names: Thomas
12+
family-names: Monks
13+
affiliation: University of Exeter
14+
orcid: 'https://orcid.org/0000-0003-2631-4481'
15+
- given-names: Alison
16+
family-names: Harper
17+
affiliation: University of Exeter
18+
orcid: 'https://orcid.org/0000-0001-5274-5037'
19+
repository-code: >-
20+
https://github.com/pythonhealthdatascience/stars-simpy-jupterlite
21+
keywords:
22+
- simpy
23+
- jupyterlite
24+
- python
25+
- discrete-event simulation
26+
- open science
27+
- reproducibility
28+
- deployment
29+
- model reuse
30+
license: MIT

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Tom Monks
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
[![lite-badge](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://pythonhealthdatascience.github.io/stars-simpy-jupterlite/notebooks/?path=01_urgent_care_model.ipynb)
2+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10987817.svg)](https://doi.org/10.5281/zenodo.10987817)
4+
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/release/python-3100/)
5+
[![License: MIT](https://img.shields.io/badge/ORCID-0000--0001--5274--5037-brightgreen)](https://orcid.org/0000-0001-5274-5037)
6+
[![License: MIT](https://img.shields.io/badge/ORCID-0000--0003--2631--4481-brightgreen)](https://orcid.org/0000-0003-2631-4481)
7+
8+
# Towards Sharing Tools and Artifacts for **Reproducible** Simulation **(v1.5)**: a JuypterLite template for `simpy` models
9+
10+
## 1. Overview
11+
12+
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.
13+
14+
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).
15+
16+
> Try it in your browser now: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite
17+
18+
### 1.1. Use case
19+
20+
* 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.
21+
* The researcher wants the model to be immediately usable. Users should not need to install python, `simpy` or any dependencies.
22+
* 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.
23+
* 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.**
24+
* Loading the model is as simple as clicking a URL.
25+
26+
### 1.2. Credits ✨
27+
28+
> 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+
30+
### 1.3. Citation
31+
32+
If you use the template in your work we would greatly appreciate a citation when you publish your work.
33+
34+
> Monks, T., & Harper, A. (2024). Simpy JupyterLite Template (v0.1.0). Zenodo. https://doi.org/10.5281/zenodo.10987817
35+
36+
```
37+
@software{monks_harper_jupyterlite_template,
38+
author = {Monks, Thomas and
39+
Harper, Alison},
40+
title = {Simpy JupyterLite Template},
41+
month = apr,
42+
year = 2024,
43+
publisher = {Zenodo},
44+
version = {v0.1.0},
45+
doi = {10.5281/zenodo.10987817},
46+
url = {https://doi.org/10.5281/zenodo.10987817}
47+
}
48+
```
49+
50+
51+
## 2. The example model included
52+
53+
The `simpy` model is adapted from [Monks and Harper (2023)](https://github.com/pythonhealthdatascience/stars-simpy-example-docs)
54+
55+
> 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
56+
57+
Full documentation of this model is available in our [JupyterBook](https://pythonhealthdatascience.github.io/stars-simpy-example-docs)
58+
59+
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.
60+
61+
> *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.*
62+
63+
## 3. Try the example DES in your browser
64+
65+
* Jupyterlab: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite
66+
* Classic notebook: https://pythonhealthdatascience.github.io/stars-simpy-jupterlite/notebooks/?path=01_urgent_care_model.ipynb
67+
68+
## 4. Using the template to create a new repo.
69+
70+
> 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.
71+
72+
Let's assume you wanted to create a new discrete-event simulation model of cancer services.
73+
74+
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"
75+
2. You will be prompted to enter a name of the repository - e.g. `cancer_model` - and a short description
76+
3. Click on "Create Repository"
77+
78+
![Deploy your own](img/use_template_1.gif)
79+
80+
The JuypterLite interactive website is built from GitHub actions. **In the newly created repo for your model** do the following
81+
82+
4. Navigate to "Settings->Pages"
83+
5. Under "Build and Deployment" set the "Source" to "GitHub actions".
84+
85+
![Deploy your own](img/actions.gif)
86+
87+
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}
88+
89+
## 5. How to install extra packages supporting your DES model. 📦
90+
91+
The repo contains two environment files. To install more dependencies for your DES model and analysis you need to edit the ``environment.yml`` file.
92+
93+
The template ``environment.yml`` is as follows:
94+
95+
96+
```yml
97+
name: xeus-python-kernel
98+
channels:
99+
- https://repo.mamba.pm/emscripten-forge
100+
- conda-forge
101+
dependencies:
102+
- xeus-python
103+
- ipycanvas
104+
- simpy=4.1.1
105+
- numpy
106+
- pandas
107+
- matplotlib
108+
```
109+
110+
**Key points:**
111+
112+
* There are two channels in use.
113+
* `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`.
114+
* `conda-forge` for other installs you can use conda-forge. Only ``no-arch`` packages from ``conda-forge`` can be installed (simpy qualifies)
115+
* Note that `numpy`, `pandas` and `matplotlib` have specific versions available on `enscription-forge`. For this reason we recommend not including the package version number.
116+
* `simpy` is installed from `conda-forge` we were therefore able to freeze the version to 4.1.1 to aid reproducibility.
117+
* At the time of writing the xeus-python kernal will use python 3.11.3
118+
119+
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`
120+
121+
Our modified environment looks like:
122+
123+
```yml
124+
name: xeus-python-kernel
125+
channels:
126+
- https://repo.mamba.pm/emscripten-forge
127+
- conda-forge
128+
dependencies:
129+
- xeus-python
130+
- ipycanvas
131+
- simpy=4.1.1
132+
- numpy
133+
- pandas
134+
- matplotlib
135+
- plotly
136+
- scipy
137+
```
138+
139+
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:
140+
141+
142+
```yml
143+
name: xeus-python-kernel
144+
channels:
145+
- https://repo.mamba.pm/emscripten-forge
146+
- conda-forge
147+
dependencies:
148+
- xeus-python
149+
- ipycanvas
150+
- salabim
151+
- numpy
152+
- pandas
153+
- matplotlib
154+
- plotly
155+
- scipy
156+
```

build-environment.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: build-env
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python
6+
- pip
7+
- jupyter_server
8+
- jupyterlite-core >=0.4.1,<0.5.0
9+
- jupyterlite-xeus>=2.0.0,<3

0 commit comments

Comments
 (0)