Built environment and got Table 6 config 1 results. Total time used: 8h 51m (22%)
10.02-10.16: Archive scope on Zenodo
Archiving repository on Zenodo, now that have made consensus decision on scope following:
Discussion with Tom yesterday.
Emails with Alison this morning, who also had a look over paper and our planned scope, and confirmed that she felt it looked complete.
Before doing so, created entry in CHANGELOG.md and updated CITATION.cff to include myself, Tom and Alison, and to amend the version and title.
10.23-10.30 : Look over code
All code in PHC.py.
Salabim.
Model created using classes.
Function main() defines parameters (e.g. number of doctors) and runs model.
No random seed.
Saves results to .xlsx with lots of stats (can spot lots from Table 6). Also outputs the input parameters used.
Can’t spot code for defined scenarios or figures, so anticipating will need to create for self.
(Timings below): Set up environment
Timings for this section (provided as list rather than in header as often paused for time spent solving environment):
10.31-10.47
11.00-11.01
11.03-11.04
11.12-11.35
No environment file provided. Can’t spot Python or Salabim version in the paper, nor in README from prior commit. Therefore:
Dependencies from PHC.py
Didn’t include random as should be in base
Model code commit to GitHub on 14th March 2021. Paper first published online with simulation 18th July 2021, and latest arXiv version from 21st June 2021.
Hence, looked for package versions with dates on or prior to the earlier 14th March 2021.
Spent along time solving environment and looking for incompatable packages (which excluded from timing above). Had lots of conflicts:
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Output in format: Requested package -> Available versions
Package libuuid conflicts for:
xlwt=1.3.0 -> python[version='>=3.11,<3.12.0a0'] -> libuuid[version='>=1.0.3,<2.0a0|>=1.41.5,<2.0a0']
statistics=1.0.3.5 -> python[version='>=3.10,<3.11.0a0'] -> libuuid[version='>=1.0.3,<2.0a0|>=1.41.5,<2.0a0']
xlsxwriter=1.3.7 -> python -> libuuid[version='>=1.0.3,<2.0a0|>=1.41.5,<2.0a0']
Package certifi conflicts for:
pip=21.0.1 -> setuptools -> certifi[version='>=2016.09|>=2016.9.26']
matplotlib=3.3.4 -> matplotlib-base[version='>=3.3.4,<3.3.5.0a0'] -> certifi[version='>=2020.06.20']
Package _libgcc_mutex conflicts for:
numpy=1.20.1 -> libgcc-ng[version='>=7.3.0'] -> _libgcc_mutex[version='*|0.1',build=main]
python=3.9 -> libgcc-ng[version='>=11.2.0'] -> _libgcc_mutex[version='*|0.1',build=main]
Package pip conflicts for:
numpy=1.20.1 -> python[version='>=3.9,<3.10.0a0'] -> pip
xlwt=1.3.0 -> python[version='>=3.11,<3.12.0a0'] -> pip
matplotlib=3.3.4 -> python[version='>=3.7,<3.8.0a0'] -> pip
xlsxwriter=1.3.7 -> python -> pip
pip=21.0.1
python=3.9 -> pip
Package wheel conflicts for:
python=3.9 -> pip -> wheel
pip=21.0.1 -> wheel
Package ca-certificates conflicts for:
xlwt=1.3.0 -> python[version='>=2.7,<2.8.0a0'] -> ca-certificates
python=3.9 -> openssl[version='>=3.0.13,<4.0a0'] -> ca-certificates
statistics=1.0.3.5 -> python[version='<3'] -> ca-certificates
xlsxwriter=1.3.7 -> python -> ca-certificates
Package setuptools conflicts for:
python=3.9 -> pip -> setuptools
matplotlib=3.3.4 -> matplotlib-base[version='>=3.3.4,<3.3.5.0a0'] -> setuptools
pip=21.0.1 -> setuptools
Package numpy conflicts for:
matplotlib=3.3.4 -> matplotlib-base[version='>=3.3.4,<3.3.5.0a0'] -> numpy[version='>=1.16.6,<2.0a0']
numpy=1.20.1The following specifications were found to be incompatible with your system:
- feature:/linux-64::__glibc==2.35=0
- feature:|@/linux-64::__glibc==2.35=0
- numpy=1.20.1 -> libgcc-ng[version='>=7.3.0'] -> __glibc[version='>=2.17']
- python=3.9 -> libgcc-ng[version='>=11.2.0'] -> __glibc[version='>=2.17']
Your installed version is: 2.35
Instead of going package by package, tried out a simpler approach of changing to only specify the Python version and none of the individual packages. Still found lots of conflicts:
LibMambaUnsatisfiableError: Encountered problems while solving:
- package statistics-1.0.3.5-py27_1 requires python >=2.7,<2.8.0a0, but none of the providers can be installed
Could not solve for environment specs
The following packages are incompatible
├─ python 3.9** is requested and can be installed;
└─ statistics is not installable because there are no viable options
├─ statistics 1.0.3.5 would require
│ └─ python [2.7* |>=2.7,<2.8.0a0 ], which conflicts with any installable versions previously reported;
├─ statistics 1.0.3.5 would require
│ └─ python >=3.10,<3.11.0a0 , which conflicts with any installable versions previously reported;
└─ statistics 1.0.3.5 would require
└─ python <3 , which conflicts with any installable versions previously reported.
Appears from this message (and supported versions listed on pypi) that would need to switch to python 2.7. Environment then successfully installed, and update .yml to show versions it used.
At a glance, all are lower than those I’d previously specified, except xlsxwriter, which is 3.0.1 (10 Aug 2021). As it would not be possible for them to have used this version, I set that to 1.3.7 and rebuilt environment.
This built quickly and with no issue.
11.51-11.57, 12.03-12.37: Running script and returning to environment
Copied PHC.py into reproduction/ and ran file with environment active.
ImportError: No module named pathlib. Installed latest version of pathlib (which is from 2014) into environment.
Then error:
Traceback (most recent call last):
File "/home/amy/Documents/stars/stars-reproduce-shoaib-2022/reproduction/PHC.py", line 1, in <module>
import salabim as sim
File "/home/amy/mambaforge/envs/shoaib2022/lib/python2.7/site-packages/salabim/__init__.py", line 1, in <module>
from .salabim import *
File "/home/amy/mambaforge/envs/shoaib2022/lib/python2.7/site-packages/salabim/salabim.py", line 9451, in <module>
class AnimateCombined(collections.UserList):
AttributeError: 'module' object has no attribute 'UserList'
Wanted to just explore basic salabim example first, to check environment is working, so made notebook that just imports salabim. Running required installation of ipykernel in environment. Excluded installation time for this from timings above. Then ran import salabim as sim, but this returned the same error as before just upon import.
Current salabim documentation lists a few different imports that might be required. Went to old documentation on their GitHub, to the 20.0.4 branch then PDF with documentation (which is 20.0.3, but likewise if you go to 20.0.5 branch): https://github.com/salabim/salabim/blob/20%2C0%2C4/salabim.pdf. Then ran:
pip install Pillow
Which didn’t have much impact. Error message seems to relate to collections not having UserList. Collections is a built-in module in base python. Tried to just import collections (which was fine), then run collections.UserList which returns same error.
Have realised mistake - that statistics on conda/PyPi is an import to allow it to work with 2.7, but actually, statistics is a built-in python module that was introduced in Python 3.4.
As such, deleted environment and removed statistics from the requirements, and just set requirement of Python 3.9 (as tried before) and built using mamba.
Can see that several of these are more recent that would have been possible for the paper. But trying import of salabim now works. Decided to try running the script with this environment, just to see if it can work.
ModuleNotFoundError: No module named 'greenlet'
Can see this was suggested in the salabim documentation. Add greenlet to environment and remade environment with mamba env update -f environment.yml. This add greenlet==3.0.3. Then re-run PHC.py. Got:
Traceback (most recent call last):
File "/home/amy/Documents/stars/stars-reproduce-shoaib-2022/reproduction/PHC.py", line 1300, in <module>
main()
File "/home/amy/Documents/stars/stars-reproduce-shoaib-2022/reproduction/PHC.py", line 932, in main
Main(name='')
File "/home/amy/mambaforge/envs/shoaib2022/lib/python3.9/site-packages/salabim/salabim.py", line 7131, in __init__
raise ValueError(
ValueError: process may not be a generator (contain yield statements.)
Maybe this a non yieldless model. In that case:
- add sim.yieldless(False) or
- remove all yields or
- run salabim_unyield.py
13.17-15.07: Continued and got config1 table6 results (confirmed match)
Suspicious my error could be because I’m used versions that are more recent than I know possible. Hence, delete environment and this time rebuild as specified at start but without statistics, but with the new ones I know I need, with versions based on their release history. Exception was ipykernel, as that was something I’ve added to run notebooks, and not something the original study required.
This built fine! So probably would’ve worked to begin with without statistics. Then ran PHC.py, and it started running fine, outputting No of replications done 0, No of replications done 1…
Ensure is set up with correct parameters. Configuration 1 is (from Table 3 and 6):
2 doctors: doc_cap = 2
4 nurses: staff_nurse_cap = 3, NCD_nurse_cap = 1
130 OPD cases, so OPD inter-arrival time 4: OPD_iat = 4
0.5 IPD cases, so IPD inter-arrival time 2880: IPD_iat = 2880
1 childbirth, so childbirth inter-arrival time 1440: delivery_iat = 1440
1 ANC (patients), so ANC inter-arrival time 1440: ANC_iat = 1440
6 inpatient beds: bed = sim.Resource("Bed", capacity=6)
1 labour room: delivery_bed = sim.Resource("Del bed", capacity = 1)
100 replications: replication = 10
365 days: days = 365
Warm-up 180 days: warm_up = 180*24*60
Except for number of replications, all match up to configuration 1.
Produced Outputs.xlsx in main folder, which moved manually to reproduction/, and copied to logbook folder to display below. This ran ten replications, with results in each column.
Add xlrd and pandas to environment (quarto and reproduction) so can import the .xls files produced and process them.
Processed this in reproduce.ipynb so can match up results to Table 6 (as use different label names), and calculate proportion of childbirth referred.
Confirmed that values all matched up with only apx. 1% difference at most, which is great!
15.23-16.17: Second results spreadsheet
There is REPLICATION = xlsxwriter.Workbook("Config_3(2).xlsx") with results that I didn’t get. Tried uncommenting REPLICATION.close() and reran PHC.py.
Also, changed save location of the output files, so they go into reproduction/outputs/ rather than main folder, by modifying PHC.py.
In reproduction.ipynb, compared results from that to the processed Outputs.xls. To import .xlsx file using pd.read_excel, had to add openpyxl to environment.
Also does not have fraction of childbirth cases referred
Can’t spot labour bed utilisation in the larger results table
The results are not an exact match but all are likely due to rounding differences. As the outputs one was processed additionally using spreadsheet with replication results, feel its better to use the full results spreadsheet they create, as that works with the raw results (and not potentially rounded results in the spreadsheet).
Match:
doctor utilisation
pharmacist utilisation
Don’t match:
ncd nurse utilisation (rounding?)
staff nurse utilisation (rounding?)
lab utilisation (rounding?)
bed occupancy (rounding?)
mean OPD queue length (rounding as simple results using replication spreadsheet which might have rounding)
OPD queue waiting times (rounding?)
mean pharmacy queue length (rounding?)
pharacy queue waiting tim (rounding?)
lab queue waiting time (rounding?)
However, that doesn’t have the standard deviation for all the results included - and its missing labour bed utilisation and fraction of childbirth cases. Also, the full result is potentially more rounded than the reported, and as it was commented out in the .py file originally, that lends me to suspect that results could likely be based on the replication spreadsheet results.
Decision: Use replication spreadsheet results.
16.22-16.48: Setting parameter values from notebook
In order to run the different scenarios without needing to change the PHC.py itself each time, worked to modify the function main() so that the parameters provided to that function are inputs.
Then ran the model from reproduce.ipynb.
Timings
import syssys.path.append('../')from timings import calculate_times# Minutes used prior to todayused_to_date =239# Times from todaytimes = [ ('10.02', '10.16'), ('10.23', '10.30'), ('10.31', '10.47'), ('11.00', '11.01'), ('11.03', '11.04'), ('11.12', '11.35'), ('11.51', '11.57'), ('12.03', '12.37'), ('13.17', '15.07'), ('15.23', '16.17'), ('16.22', '16.48')]calculate_times(used_to_date, times)
Time spent today: 292m, or 4h 52m
Total used to date: 531m, or 8h 51m
Time remaining: 1869m, or 31h 9m
Used 22.1% of 40 hours max