You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/hsma_changes.md
+78-27Lines changed: 78 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,8 @@ class Patient:
73
73
self.time_with_nurse = np.nan
74
74
```
75
75
76
+
This enables metrics like `count_unseen` and `mean_q_time_unseen`, which can show backlog in the system at the end of the simulation.
77
+
76
78
## Seeds
77
79
78
80
The HSMA models use a multiplied version of the `run_number` as a seed when sampling:
@@ -111,24 +113,31 @@ class g:
111
113
g.patient_inter = 10
112
114
```
113
115
114
-
To resolve this, the template creates an instance of the parameter class, and never uses or alters it directly. For clarity, the class is called `Defaults()` and instances are typicallyed called `param`.
116
+
To resolve this, the template creates an instance of the parameter class, and never uses or alters it directly. For clarity, the class is called `Param()` and instances are typically called `param`.
115
117
116
118
```
117
-
class Defaults():
118
-
def __init__(self):
119
-
self.patient_inter = 5
120
-
self.mean_n_consult_time = 35
121
-
self.number_of_nurses = 9
122
-
self.warm_up_period = 0
123
-
self.data_collection_period = 600
124
-
self.number_of_runs = 5
125
-
self.audit_interval = 5
126
-
self.scenario_name = 0
127
-
128
-
...
129
-
130
-
param = Defaults()
131
-
param.patient_inter = 10
119
+
class Param:
120
+
"""
121
+
Default parameters for simulation.
122
+
123
+
Attributes are described in initialisation docstring.
The same metrics can be calculated in several possible ways. In this model, time-weighted averages have been included using the `MonitoredResource`. This requires methods `init_results_variables()` and `warm_up_complete()`, which have meant that implementation of warm-up can be done using `warm_up_complete()` rather than by checking whether warm up is complete every time a metric is saved.
219
+
220
+
```
221
+
def warm_up_complete(self):
222
+
if self.param.warm_up_period > 0:
223
+
yield self.env.timeout(self.param.warm_up_period)
224
+
self.init_results_variables()
225
+
```
226
+
227
+
As opposed to, for example:
228
+
229
+
```
230
+
if self.env.now > g.warm_up_period:
231
+
self.results_df.at[patient.id, "Q Time Nurse"] = (
232
+
patient.q_time_nurse
233
+
)
234
+
```
235
+
182
236
## Extra features
183
237
184
238
### Prevent addition of new attributes to the parameter class
@@ -191,15 +245,8 @@ The parameter class includes a function that:
191
245
This is to avoid an error where it looks like a parameter has been changed, but actually the wrong attribute name was used - for example, setting `param.nurses = 3` and thinking this has reduced the number of nurse resources, but actually this is based on `param.number_of_nurses` which remains set to 9.
192
246
193
247
```
194
-
class Defaults():
195
-
def __init__(self):
196
-
object.__setattr__(self, '_initialising', True)
197
-
198
-
self.patient_inter = 5
199
-
self.mean_n_consult_time = 35
200
-
...
201
-
202
-
object.__setattr__(self, '_initialising', False)
248
+
class Param():
249
+
...
203
250
204
251
def __setattr__(self, name, value):
205
252
if hasattr(self, '_initialising') and self._initialising:
@@ -242,7 +289,7 @@ for rule, param_names in validation_rules.items():
242
289
243
290
### Tests
244
291
245
-
The files `test_unittest.py` and `test_backtest.py` include various tests which check the model is functioning as expected. For example, checking that:
292
+
The files `test_unittest_model.py`, `test_unittest_logger.py` and `test_backtest.py` include various tests which check the model is functioning as expected. For example, checking that:
246
293
247
294
* It is not possible to add new attributes to the parameter class.
248
295
* Invalid inputs to `Model()` return an `ValueError`.
@@ -256,11 +303,15 @@ The `summary_stats()` function is used to find the overall results from across t
256
303
257
304
It can also be applied to other results dataframes if desired.
258
305
306
+
### Logger
307
+
308
+
The `SimLogger` class will generate logs which can be saved to a file or printed to a console. This includes information on when patients arrive and are seen. This can be helpful for understanding the simulation or when debugging.
309
+
259
310
### Other minor changes
260
311
261
312
There are a few smaller changes to the model with minimal impact on function. These include:
262
313
263
-
***Names** - for example, `Patient.id` was changed to `Patient.patient_id`, as the patient objects are used to create the patient-level results dataframe, and want "patient_id" as the column name.
314
+
***Names** - for example, `Patient.id` was changed to `Patient.patient_id`, as the patient objects are used to create the patient-level results dataframe, and want "patient_id" as the column name. Also, `Trial` was changed to `Runner` with methods changed to e.g. `run_reps()`.
264
315
***Comments and docstrings**
265
316
***Removed `patient_counter`** - as can just use the length of the `patients` list now.
266
317
***Interval audit** - records cumulative mean wait time, as well as utilisation.
0 commit comments