{ "cells": [ { "cell_type": "markdown", "id": "8a7fef09", "metadata": {}, "source": [ "# Example 4: Global Sensitivity Analysis — Sobol with MPI \n", "\n", "[(GitHub link)](https://github.com/heberlr/UQ_PhysiCell/tree/main/examples/ex4_runSA_MPI.ipynb)\n", "\n", "This notebook runs the same Sobol sensitivity analysis as ex3 but uses **MPI (Message Passing Interface)** for distributed execution across multiple compute nodes or cores. The simulation script is [ex4_runSA_MPI.py](ex4_runSA_MPI.py) — a plain Python file using the same `ModelAnalysisContext` API with `parallel_method='inter-node'`. The notebook launches it via `%%bash` and then loads results from the shared database.\n", "\n", "**Multi-task (ex3) vs MPI (ex4):**\n", "| | Multi-task (ex3) | MPI (ex4) |\n", "|---|---|---|\n", "| Launch | Python API | `mpiexec -n N python script.py` |\n", "| Scope | Single machine | Multiple nodes |\n", "| Setup | No extra config | Requires MPI installation |\n", "| Best for | Laptops, workstations | HPC clusters |\n", "\n", "**Model:** [asymmetric_division](https://github.com/MathCancer/PhysiCell/tree/master/sample_projects/asymmetric_division) — stem cell division with reparameterized probabilities (prob. progenitor_2 = 1 − prob. progenitor_1).\n", "\n", "**Parameters explored:**\n", "- `cycle_duration_stem_cell` — stem cell cycle duration\n", "- `asym_div_to_prog_1_sat` — saturation probability of dividing into progenitor_1\n", "- `asym_div_to_prog_2_sat` — saturation probability of dividing into progenitor_2" ] }, { "cell_type": "markdown", "id": "6c055dd1", "metadata": {}, "source": [ "## Run simulations via MPI\n", "\n", "Each MPI rank picks up its share of the sample list and writes results to the shared database independently." ] }, { "cell_type": "code", "execution_count": 1, "id": "9686052e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initializing MPI job with 8 processes...\n", "PhysiCell already exists at: PhysiCell-master\n", "Skipping download. Use force_download=True to override.\n", "Generated 48 samples using Sobol\n", "Inserting parameter: cycle_duration_stem_cell with properties: {'lower_bound': 1152.0, 'upper_bound': 1728.0, 'ref_value': 1440.0, 'perturbation': None}\n", "Inserting parameter: asym_div_to_prog_1_sat with properties: {'lower_bound': 0.0, 'upper_bound': 1.0, 'ref_value': 0.0, 'perturbation': None}\n", "Inserting {'frac_proj1_cells': None, 'frac_proj2_cells': None, 'run_time_sec': None} QoIs into the database\n", "Simulations completed and results stored in the database: ex4_PhysiCell_SA_MPI.db.\n" ] } ], "source": [ "%%bash\n", "mpiexec -n 8 python ex4_runSA_MPI.py" ] }, { "cell_type": "markdown", "id": "2adaa961", "metadata": {}, "source": [ "## Load results and compute summary statistics" ] }, { "cell_type": "code", "execution_count": 1, "id": "2ac1ff8b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No QoI data provided, calculating QoIs from the database...\n", "All samples in Samples table have corresponding entries in Output table.\n", "Extracting QoIs from DataFrame...\n" ] }, { "data": { "text/html": [ "
| \n", " | frac_proj1_cells_0 | \n", "frac_proj2_cells_0 | \n", "run_time_sec_0 | \n", "time_0 | \n", "
|---|---|---|---|---|
| SampleID | \n", "\n", " | \n", " | \n", " | \n", " |
| 0 | \n", "0.843984 | \n", "0.125880 | \n", "10.825394 | \n", "2880.01 | \n", "
| 1 | \n", "0.896023 | \n", "0.073295 | \n", "11.204853 | \n", "2880.01 | \n", "
| 2 | \n", "0.651961 | \n", "0.317536 | \n", "11.537088 | \n", "2880.01 | \n", "
| 3 | \n", "0.661141 | \n", "0.309091 | \n", "10.035426 | \n", "2880.01 | \n", "
| 4 | \n", "0.894974 | \n", "0.074299 | \n", "9.719086 | \n", "2880.01 | \n", "
| 5 | \n", "0.614583 | \n", "0.354356 | \n", "10.210138 | \n", "2880.01 | \n", "
| 6 | \n", "0.680871 | \n", "0.288447 | \n", "10.976077 | \n", "2880.01 | \n", "
| 7 | \n", "0.663192 | \n", "0.306103 | \n", "10.264580 | \n", "2880.01 | \n", "
| 8 | \n", "0.780370 | \n", "0.190008 | \n", "9.784336 | \n", "2880.01 | \n", "
| 9 | \n", "0.771402 | \n", "0.197727 | \n", "9.758274 | \n", "2880.01 | \n", "
| 10 | \n", "0.635649 | \n", "0.333468 | \n", "9.517483 | \n", "2880.01 | \n", "
| 11 | \n", "0.780147 | \n", "0.189338 | \n", "10.039442 | \n", "2880.01 | \n", "
| 12 | \n", "0.799209 | \n", "0.170477 | \n", "10.289918 | \n", "2880.01 | \n", "
| 13 | \n", "0.836292 | \n", "0.134434 | \n", "10.506709 | \n", "2880.01 | \n", "
| 14 | \n", "0.702639 | \n", "0.267537 | \n", "10.712825 | \n", "2880.01 | \n", "
| 15 | \n", "0.752590 | \n", "0.217072 | \n", "9.702209 | \n", "2880.01 | \n", "
| 16 | \n", "0.884388 | \n", "0.085096 | \n", "10.094876 | \n", "2880.01 | \n", "
| 17 | \n", "0.711582 | \n", "0.258450 | \n", "12.379703 | \n", "2880.01 | \n", "
| 18 | \n", "0.705426 | \n", "0.264439 | \n", "10.686780 | \n", "2880.01 | \n", "
| 19 | \n", "0.684894 | \n", "0.285327 | \n", "9.994548 | \n", "2880.01 | \n", "
| 20 | \n", "0.841756 | \n", "0.127919 | \n", "10.427948 | \n", "2880.01 | \n", "
| 21 | \n", "0.854501 | \n", "0.115185 | \n", "10.720837 | \n", "2880.01 | \n", "
| 22 | \n", "0.683389 | \n", "0.286643 | \n", "9.708683 | \n", "2880.01 | \n", "
| 23 | \n", "0.858560 | \n", "0.110735 | \n", "10.227116 | \n", "2880.01 | \n", "
| 24 | \n", "0.826203 | \n", "0.143850 | \n", "10.323526 | \n", "2880.01 | \n", "
| 25 | \n", "0.802217 | \n", "0.168688 | \n", "11.474282 | \n", "2880.01 | \n", "
| 26 | \n", "0.926637 | \n", "0.042279 | \n", "10.585155 | \n", "2880.01 | \n", "
| 27 | \n", "0.938957 | \n", "0.030338 | \n", "10.153952 | \n", "2880.01 | \n", "
| 28 | \n", "0.799566 | \n", "0.170120 | \n", "9.704243 | \n", "2880.01 | \n", "
| 29 | \n", "0.930822 | \n", "0.037915 | \n", "10.516060 | \n", "2880.01 | \n", "
| 30 | \n", "0.725824 | \n", "0.243672 | \n", "10.657874 | \n", "2880.01 | \n", "
| 31 | \n", "0.718596 | \n", "0.250119 | \n", "10.342664 | \n", "2880.01 | \n", "
| 32 | \n", "0.728855 | \n", "0.241534 | \n", "10.072137 | \n", "2880.01 | \n", "
| 33 | \n", "0.705235 | \n", "0.264754 | \n", "9.897537 | \n", "2880.01 | \n", "
| 34 | \n", "0.688000 | \n", "0.281485 | \n", "10.426809 | \n", "2880.01 | \n", "
| 35 | \n", "0.718530 | \n", "0.250196 | \n", "10.252921 | \n", "2880.01 | \n", "
| 36 | \n", "0.956617 | \n", "0.012311 | \n", "10.453640 | \n", "2880.01 | \n", "
| 37 | \n", "0.963972 | \n", "0.006061 | \n", "11.375506 | \n", "2880.01 | \n", "
| 38 | \n", "0.798702 | \n", "0.170593 | \n", "10.119175 | \n", "2880.01 | \n", "
| 39 | \n", "0.776225 | \n", "0.193460 | \n", "10.426868 | \n", "2880.01 | \n", "
| 40 | \n", "0.969508 | \n", "0.000000 | \n", "10.063891 | \n", "2880.01 | \n", "
| 41 | \n", "0.817536 | \n", "0.151961 | \n", "9.865496 | \n", "2880.01 | \n", "
| 42 | \n", "0.626549 | \n", "0.342758 | \n", "10.799564 | \n", "2880.01 | \n", "
| 43 | \n", "0.732264 | \n", "0.237233 | \n", "10.376397 | \n", "2880.01 | \n", "
| 44 | \n", "0.649075 | \n", "0.320611 | \n", "10.482474 | \n", "2880.01 | \n", "
| 45 | \n", "0.649115 | \n", "0.320180 | \n", "9.848048 | \n", "2880.01 | \n", "
| 46 | \n", "0.682955 | \n", "0.286553 | \n", "10.143365 | \n", "2880.01 | \n", "
| 47 | \n", "0.665809 | \n", "0.303877 | \n", "10.556484 | \n", "2880.01 | \n", "