diff --git a/06_cell_population_example.ipynb b/06_cell_population_example.ipynb index 365cea2..e3eee77 100644 --- a/06_cell_population_example.ipynb +++ b/06_cell_population_example.ipynb @@ -48,15 +48,19 @@ "\n", "These functions contain the ability to receive a seed to set up the random number generator. This is useful for testing and comparing performance as it allows us to guarantee the output of the simulation.\n", "\n", - "The script contain code which runs two single realisations - one which always dies out and one which always grows (the results are guaranteed by manually choosing the seed of the random number generator). The script then runs 100 realisations of the system. Each realisation receives the number of the realisation (from 0-99) as a seed to ensure reproducibility. The runtimes of the system are printed to the console. When I ran the code, the output was:\n", + "The script contain code which runs two single realisations - one which always dies out and one which always grows (the results are guaranteed by manually choosing the seed of the random number generator). The script then runs 200 realisations of the system. Each realisation receives the number of the realisation (from 0-199) as a seed to ensure reproducibility. The runtimes of the system are printed to the console. When I ran the code, the output was:\n", "\n", - "* Single realisation that always dies: 0.29s\n", - "* Single realisation that always grows: 2.25s\n", - "* 100 realisations: 129.7s\n", + "| Simulation Type | Running Time | Plotting Time |\n", + "|----------------------------------------|---------------------------------|---------------|\n", + "| Single realisation that always dies | 6.2 $\\times 10 ^{-5}\\textrm{s}$ | 0.31s |\n", + "| Single realisation that always grows | 2.0s | 0.20 |\n", + "| 200 realisations | 189s | 0.50s |\n", "\n", - "Each of these times includes the time spent to plot the output of the simulation. For the single realisation that dies, this is the majority of the runtime.\n", + "The time to simulate a growing population is significantly longer than the time to simulate a dying population as there are more cells to simulate. Around 20% of the simulations see a growing population. For a realisation which grows, different realisations may take different amounts of time, depending on how large the population gets. The figure below shows the amount of time taken for each realisation to run, with the number of the longest-lasted realisations added as annotation to the figures:\n", "\n", - "The time to simulate a growing population is significantly longer than the time to simulate a dying population as there are more cells to simulate. Just under 20% of the simulations see a growing population. As the number of realisations is not very high, we might expect there to be some variation in the outputs and the runtimes of the simulation with multiple realisations each time it is run." + "
\n",
+ "\n",
+ "
\n",
- "\n",
+ "
\n",
"
\n",
+ "\n",
+ "\n",
+ "Primarily because of the way the `Pool` distributes work to the processes, the load is now much more evenly balanced between the processes. The code now takes around 83s to run on 4 cores."
]
},
{
diff --git a/06_cell_population_example/pool_runtimes.png b/06_cell_population_example/pool_runtimes.png
index c384247..cce237f 100644
Binary files a/06_cell_population_example/pool_runtimes.png and b/06_cell_population_example/pool_runtimes.png differ
diff --git a/06_cell_population_example/pool_version.py b/06_cell_population_example/pool_version.py
index ae4cba0..4b8310e 100644
--- a/06_cell_population_example/pool_version.py
+++ b/06_cell_population_example/pool_version.py
@@ -107,10 +107,6 @@ def run_single_realisation(n_initial, reproduction_probability, mean_lifetime, o
return run_time, plotting_time
-def run_realisation_interface(args):
- return run_realisation(*args)
-
-
def run_multiple_realisations(n_initial, reproduction_probability, mean_lifetime, output_times, n_realisations, output_filepath, n_processes=1):
'''
Run multiple realisations of the cell population model and plot the results.
@@ -128,7 +124,7 @@ def run_multiple_realisations(n_initial, reproduction_probability, mean_lifetime
arguments = [(n_initial, reproduction_probability, mean_lifetime, output_times, i) for i in range(n_realisations)]
with multiprocessing.Pool(4) as p:
- output_list = p.map(run_realisation_interface, arguments)
+ output_list = p.starmap(run_realisation, arguments)
# Make a 2D array to store the populations of each realisation at each time
output_populations = np.array([output[0] for output in output_list])
diff --git a/06_cell_population_example/queue_runtimes.png b/06_cell_population_example/queue_runtimes.png
index e1a7468..5edcb18 100644
Binary files a/06_cell_population_example/queue_runtimes.png and b/06_cell_population_example/queue_runtimes.png differ
diff --git a/06_cell_population_example/queue_version.py b/06_cell_population_example/queue_version.py
index fe9163b..ece10ab 100644
--- a/06_cell_population_example/queue_version.py
+++ b/06_cell_population_example/queue_version.py
@@ -96,7 +96,7 @@ def run_single_realisation(n_initial, reproduction_probability, mean_lifetime, o
ax.set_yscale('log')
fig.savefig(output_filepath)
- plotting_time = time.time() - run_time
+ plotting_time = time.time() - run_time - start_time
return run_time, plotting_time
diff --git a/06_cell_population_example/serial_runtimes.png b/06_cell_population_example/serial_runtimes.png
index cdb5e3f..409051f 100644
Binary files a/06_cell_population_example/serial_runtimes.png and b/06_cell_population_example/serial_runtimes.png differ
diff --git a/resources/pool_runtimes.png b/resources/pool_runtimes.png
new file mode 100644
index 0000000..cce237f
Binary files /dev/null and b/resources/pool_runtimes.png differ
diff --git a/resources/queue_runtimes.png b/resources/queue_runtimes.png
new file mode 100644
index 0000000..5edcb18
Binary files /dev/null and b/resources/queue_runtimes.png differ
diff --git a/resources/serial_runtimes.png b/resources/serial_runtimes.png
new file mode 100644
index 0000000..409051f
Binary files /dev/null and b/resources/serial_runtimes.png differ