A simple SimPy hospital model running on parallel cpu cores. The intention is to show a framework for hospital modelling using SimPy with Model, Hospital, and Patient classes, and with scenarios and trials managed by a Replicator class; it is not intended to be a full hospital model itself.
Use 1_simplest_model_1.ipynb to revise a simple SimPy model (non-object-oriented), and 2_simplest_model_2_with_resources.ipynb to revise how limited resources may be added to a SimPy model.
Use 3_single_model_run.ipynb as your starting point to understand the object-oriented model using a single run of a single sceanrio.
Use 4_parallel_function.ipynb to understand parallel processing across CPU cores.
Use 5_simple_replicate_scenarios_model.ipynb to see how multiple scenarios may be defined and running with replication across multiple CU cores.
Please also see Additional models folder for further model examples (e.g. including plotting results).
Note: BinderHub is currently limited to one CPU, so there is no advantage of parallel processing on BinderHub.
To set up use of any Python code, using a Jupyter Notebook as the front end, on BinderHub, place the requirements for the code in a .yml file in a binder subdirectory. Upload code to GitHub. Binder can then run the code from binder.org, which will also give a link for putting a badge in the GitHub READNE.md file.
To get the correct libraries and versions it is recommended that the provided conda environment is used. To create and activate the environment:
-
Windows -> Open Anaconda prompt. Mac/linux -> Open a terminal
-
Navigate to the /binder directory
-
Run the following command:
conda env create -f environment.yml
This will fetch and install the libraries in a conda environment 'simple_sim'
- To activate the enviroment run the following command:
conda activate simple_sim
-
Learn how to set up a custom Python environment (to ensure consistency of package versions) using Anaconda or Python/Pip environments.
-
Revise simple SimPy models, and learn how to structure a simple SimPy simulation using Object Oriented Programming (OOP)
-
Learn how to create a Jupyter Notebook user interface to a model, allowing the user to create multiple sceanrios
-
Learn how to run parallel Python function calls across multiple CPU cores
-
Learn how to run SimPy models with multiple scenarios and replicates (across CPU cores) with a Jupyter Notebook interface
-
Learn how to make you model available on the web using GitHub and mybinder.org
These are standalone models without parallel processing or scenario handing. These are to illustrate simpy models.
-
1_simplest_model_1.ipynb: A standalone model of patients arriving at ED and being seen in order. There are no resources in this model. -
2_simplest_model_2_with_resources.ipynb: A standalone model of patients arriving at ED and being seen in order. This model adds the doctor as a resource.
Scenarios allow us to pass model parameters to the model, and so may be used to automate running the model with different paramater values.
-
This model holds model parameters in a
Scenarioclass that is available by loading theparametersmodule from thesim_classespackage. -
The simulation model is loaded as a class
Modelfrom themodelmodule in thesim_classespackage. The model itself loads aPatientclass which is used to create patient objects which hold the priority of the patient, and track the patient through the hospital. TheHospitalclass manages patients through the hospital.
- This is an example of using
joblibto run replicates of a function across multiple CPU cores. It does not use SimPy.
- This notebook uses
joblibto set up and run multiple replicates of a model. It calls thereplicationmodule from thesim_classespackage. This module runs the model in parallel multiple times for each scenario, and and collates results.