Skip to content

Commit 78a56cb

Browse files
committed
feat(warmup): nb finalised for warmup coding
1 parent 0b40b7f commit 78a56cb

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

content/13_warm_up.ipynb

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@
55
"id": "0be7dabf-cb34-4faf-abb1-e2c8e735beda",
66
"metadata": {},
77
"source": [
8-
"# Implementing a warm-up period\n",
8+
"# Coding a warm-up period in SimPy\n",
99
"\n",
10-
"We will implement warm-up as a single event that resets all of our results collection variables. \n",
10+
"## Why do you need a warm-up period?\n",
1111
"\n",
12-
"This is a simpler approach than including lots of if statements in `simpy` processes."
12+
"Typically when you are modelling a non-terminating system, you will need to deal with **initialisation bias**. That is the real system always has work-in-progress (e.g. patients in queues and in service), but the model starts from empty. One way to do this is to split the model's run length into warm-up and data collection periods. We discard all results in the warm-up period.\n",
13+
"\n",
14+
"> In this tutorial we will focus on coding a warm-up period rather than analysis to determine its length\n",
15+
"\n",
16+
"## But how do you code it?\n",
17+
"\n",
18+
"💪 We will implement warm-up as a **single event** that resets all of our results collection variables. \n",
19+
"\n",
20+
"> This is a simpler approach than including lots of if statements in `simpy` processes.\n",
21+
"\n",
22+
"## Illustrative example model\n",
23+
"\n",
24+
"We will use a very simple model for this example. This is a acute stroke pathway with a single arrival processes, a single type of resource, and a single treatment process. This is a non-terminating system. There are always patients in the system - it does not start up from empty\n",
25+
"\n",
26+
"\n",
27+
"![model image](img/acute_stroke_pathway.png \"stroke pathway\")"
1328
]
1429
},
1530
{
@@ -34,7 +49,7 @@
3449
},
3550
{
3651
"cell_type": "code",
37-
"execution_count": 25,
52+
"execution_count": 2,
3853
"id": "ea3d507f-9e6d-4ff0-8b90-f9c63c8a8bdf",
3954
"metadata": {},
4055
"outputs": [],
@@ -212,7 +227,11 @@
212227
"id": "7ff9beae-89cc-419c-b584-c05b81086865",
213228
"metadata": {},
214229
"source": [
215-
"## 🥵 Warm-up period"
230+
"## 🥵 Warm-up period\n",
231+
"\n",
232+
"The acute stroke pathway model starts from empty. As it is a non-terminating system our estimate of waiting time is biased due to the empty period at the start of the simulation. We can remove this initialisation bias using a warm-up period. \n",
233+
"\n",
234+
"We will implement a warm-up through an **event** that happens once in a single run of the model. The model will be run for the **warm-up period + results collection period**. At the end of the warm-up period an event will happen where all variables in the current experiment are reset (e.g. empty lists and set quantitative values to 0)."
216235
]
217236
},
218237
{
@@ -248,7 +267,7 @@
248267
"id": "94f0f9c5-22cb-493a-9f1f-4e2a8325beaa",
249268
"metadata": {},
250269
"source": [
251-
"## 4. Pathway process logic\n",
270+
"## 4. Stroke pathway process logic\n",
252271
"\n",
253272
"The key things to recognise are \n",
254273
"\n",
@@ -309,7 +328,7 @@
309328
},
310329
{
311330
"cell_type": "code",
312-
"execution_count": 33,
331+
"execution_count": 8,
313332
"id": "b3e686ce-5371-4471-a052-b9d43309bc85",
314333
"metadata": {},
315334
"outputs": [],
@@ -352,7 +371,7 @@
352371
},
353372
{
354373
"cell_type": "code",
355-
"execution_count": 34,
374+
"execution_count": 9,
356375
"id": "0d0ea6cf-7d95-4d2c-9690-fcdbdae35d84",
357376
"metadata": {},
358377
"outputs": [],
@@ -424,7 +443,7 @@
424443
},
425444
{
426445
"cell_type": "code",
427-
"execution_count": 35,
446+
"execution_count": 22,
428447
"id": "caf52390-5455-4fa1-bb22-60b5b91ad8d0",
429448
"metadata": {},
430449
"outputs": [
@@ -436,7 +455,13 @@
436455
"3.29: Stroke arrival.\n",
437456
"3.29: Patient 1 admitted to acute ward.(waited 0.00 days)\n",
438457
"4.06: Stroke arrival.\n",
439-
"4.06: Patient 2 admitted to acute ward.(waited 0.00 days)\n"
458+
"4.06: Patient 2 admitted to acute ward.(waited 0.00 days)\n",
459+
"5.31: Stroke arrival.\n",
460+
"5.31: Patient 3 admitted to acute ward.(waited 0.00 days)\n",
461+
"5.53: Stroke arrival.\n",
462+
"5.53: Patient 4 admitted to acute ward.(waited 0.00 days)\n",
463+
"5.76: Stroke arrival.\n",
464+
"5.76: Patient 5 admitted to acute ward.(waited 0.00 days)\n"
440465
]
441466
},
442467
{
@@ -445,31 +470,31 @@
445470
"{'mean_acute_wait': 0.0}"
446471
]
447472
},
448-
"execution_count": 35,
473+
"execution_count": 22,
449474
"metadata": {},
450475
"output_type": "execute_result"
451476
}
452477
],
453478
"source": [
454479
"TRACE = True\n",
455480
"experiment = Experiment()\n",
456-
"results = single_run(experiment, rep=0, wu_period=0.0, rc_period=5.0)\n",
481+
"results = single_run(experiment, rep=0, wu_period=0.0, rc_period=6.0)\n",
457482
"results"
458483
]
459484
},
460485
{
461486
"cell_type": "code",
462-
"execution_count": 36,
487+
"execution_count": 23,
463488
"id": "ddedb4f1-207d-4295-9ae4-c49b2c7cdcaf",
464489
"metadata": {},
465490
"outputs": [
466491
{
467492
"data": {
468493
"text/plain": [
469-
"{'n_arrivals': 2, 'waiting_acute': [0.0, 0.0]}"
494+
"{'n_arrivals': 5, 'waiting_acute': [0.0, 0.0, 0.0, 0.0, 0.0]}"
470495
]
471496
},
472-
"execution_count": 36,
497+
"execution_count": 23,
473498
"metadata": {},
474499
"output_type": "execute_result"
475500
}
@@ -484,12 +509,12 @@
484509
"id": "660ea2e1-d9c2-4355-876c-43dfd9dab0fe",
485510
"metadata": {},
486511
"source": [
487-
"## Quick check 1: Include a warm-up"
512+
"## Quick check 2: Include a warm-up"
488513
]
489514
},
490515
{
491516
"cell_type": "code",
492-
"execution_count": 37,
517+
"execution_count": 24,
493518
"id": "72b5284a-1fcb-4126-b663-c0ef0002e4bf",
494519
"metadata": {},
495520
"outputs": [
@@ -516,7 +541,7 @@
516541
"{'mean_acute_wait': 0.0}"
517542
]
518543
},
519-
"execution_count": 37,
544+
"execution_count": 24,
520545
"metadata": {},
521546
"output_type": "execute_result"
522547
}
@@ -530,7 +555,7 @@
530555
},
531556
{
532557
"cell_type": "code",
533-
"execution_count": 38,
558+
"execution_count": 25,
534559
"id": "7f5e282b-0f41-41df-bdca-f128e7d418c1",
535560
"metadata": {},
536561
"outputs": [
@@ -540,7 +565,7 @@
540565
"{'n_arrivals': 3, 'waiting_acute': [0.0, 0.0, 0.0]}"
541566
]
542567
},
543-
"execution_count": 38,
568+
"execution_count": 25,
544569
"metadata": {},
545570
"output_type": "execute_result"
546571
}

content/img/acute_stroke_pathway.png

66.5 KB
Loading

0 commit comments

Comments
 (0)