Skip to content

Commit 5bc2df7

Browse files
authored
Merge pull request #11 from codegithubka/kimon
Kimon
2 parents bdfa91e + 65e216e commit 5bc2df7

38 files changed

Lines changed: 7535 additions & 1321 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ results/
99
# Jupyter Notebook checkpoints
1010
.ipynb_checkpoints/
1111
# Data files
12-
data/
12+
data/
13+
.pytest_cache/

benchmarks/benchmark.txt

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
======================================================================
2+
PREDATOR-PREY SIMULATION - OPTIMIZATION BENCHMARKS
3+
======================================================================
4+
Time: 2026-01-22 15:11:24
5+
Numba: Available
6+
Scipy: Available
7+
======================================================================
8+
9+
======================================================================
10+
PP KERNEL BENCHMARK
11+
======================================================================
12+
13+
Grid size: 50x50
14+
--------------------------------------------------
15+
Numba (random) 8.08 ± 2.38 ms
16+
Numba (directed) 18.19 ± 4.53 ms
17+
→ Directed hunting overhead: +125.2%
18+
Python baseline 474.44 ± 39.77 ms ( 58.7x vs Numba)
19+
20+
Grid size: 100x100
21+
--------------------------------------------------
22+
Numba (random) 25.59 ± 0.23 ms
23+
Numba (directed) 17.68 ± 0.72 ms
24+
→ Directed hunting overhead: -30.9%
25+
26+
Grid size: 150x150
27+
--------------------------------------------------
28+
Numba (random) 93.28 ± 29.97 ms
29+
Numba (directed) 40.18 ± 4.25 ms
30+
→ Directed hunting overhead: -56.9%
31+
32+
======================================================================
33+
PCF COMPUTATION BENCHMARK
34+
======================================================================
35+
36+
Grid: 50x50, Prey: 746
37+
--------------------------------------------------
38+
Cell-list PCF (Numba) 9.99 ± 6.74 ms
39+
Brute-force PCF (Python) 835.34 ± 4.51 ms ( 83.7x vs Cell-list)
40+
41+
Grid: 75x75, Prey: 1696
42+
--------------------------------------------------
43+
Cell-list PCF (Numba) 7.56 ± 0.73 ms
44+
Brute-force PCF (Python) 4253.93 ± 8.26 ms (562.5x vs Cell-list)
45+
46+
Grid: 100x100, Prey: 2946
47+
--------------------------------------------------
48+
Cell-list PCF (Numba) 7.49 ± 0.35 ms
49+
50+
======================================================================
51+
CLUSTER MEASUREMENT BENCHMARK
52+
======================================================================
53+
54+
Grid: 50x50, Prey: 746
55+
--------------------------------------------------
56+
Numba flood-fill 0.06 ± 0.00 ms
57+
Scipy label 0.93 ± 0.07 ms ( 14.9x vs Numba)
58+
59+
Grid: 100x100, Prey: 2946
60+
--------------------------------------------------
61+
Numba flood-fill 0.25 ± 0.00 ms
62+
Scipy label 6.05 ± 0.06 ms ( 24.6x vs Numba)
63+
64+
Grid: 150x150, Prey: 6700
65+
--------------------------------------------------
66+
Numba flood-fill 0.55 ± 0.01 ms
67+
Scipy label 23.30 ± 0.07 ms ( 42.6x vs Numba)
68+
69+
======================================================================
70+
FULL SIMULATION BENCHMARK
71+
======================================================================
72+
73+
Grid: 50x50, Steps: 200
74+
--------------------------------------------------
75+
Full sim (random) 42.15 ± 0.84 ms
76+
Full sim (directed) 19.25 ± 0.14 ms
77+
→ Throughput: 4744 steps/sec
78+
79+
Grid: 100x100, Steps: 200
80+
--------------------------------------------------
81+
Full sim (random) 164.50 ± 4.51 ms
82+
Full sim (directed) 69.01 ± 0.93 ms
83+
→ Throughput: 1216 steps/sec
84+
85+
======================================================================
86+
SCALING ANALYSIS
87+
======================================================================
88+
89+
Size Kernel (ms) PCF (ms) Total (ms)
90+
-------------------------------------------------------
91+
30 1.07 1.21 2.29
92+
64 5.09 4.91 10.00
93+
98 11.62 9.12 20.73
94+
132 21.23 13.70 34.93
95+
166 33.57 20.54 54.11
96+
200 49.26 27.42 76.68
97+
98+
======================================================================
99+
BENCHMARK SUMMARY
100+
======================================================================
101+
102+
KEY FINDINGS:
103+
--------------------------------------------------
104+
• Numba kernel speedup: 58.7x (vs Python)
105+
• Cell-list PCF speedup: 83.7x (vs brute-force)
106+
• Numba cluster speedup: 24.6x (vs scipy)
107+
• Directed hunting overhead: -30.9%
108+
• Simulation throughput: 1216 steps/sec (100x100)
109+
110+
======================================================================

benchmarks/benchmark_plots.png

151 KB
Loading

benchmarks/simulation_profile.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1424296 function calls (1403459 primitive calls) in 1.094 seconds
2+
3+
Ordered by: internal time
4+
List reduced from 3270 to 15 due to restriction <15>
5+
6+
ncalls tottime percall cumtime percall filename:lineno(function)
7+
500 0.293 0.001 0.298 0.001 /Users/kimonanagnostopoulos/CSS_Project/scripts/numba_optimized.py:309(update)
8+
7030 0.077 0.000 0.082 0.000 /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/inspect.py:2729(__init__)
9+
835/832 0.062 0.000 0.067 0.000 /Users/kimonanagnostopoulos/CSS_Project/.venv/lib/python3.12/site-packages/llvmlite/binding/ffi.py:210(__call__)
10+
257 0.049 0.000 0.049 0.000 {method 'read' of '_io.BufferedReader' objects}
11+
7547 0.045 0.000 0.095 0.000 /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/inspect.py:879(cleandoc)
12+
13 0.043 0.003 0.043 0.003 {built-in method _imp.create_dynamic}
13+
251 0.028 0.000 0.028 0.000 {built-in method marshal.loads}
14+
204142/203012 0.020 0.000 0.020 0.000 {built-in method builtins.len}
15+
1069 0.015 0.000 0.015 0.000 /Users/kimonanagnostopoulos/CSS_Project/.venv/lib/python3.12/site-packages/scipy/_lib/_docscrape.py:86(is_unindented)
16+
456 0.014 0.000 0.014 0.000 {built-in method builtins.dir}
17+
227 0.013 0.000 0.047 0.000 /Users/kimonanagnostopoulos/CSS_Project/.venv/lib/python3.12/site-packages/matplotlib/artist.py:1433(get_aliases)
18+
10242 0.013 0.000 0.013 0.000 {method 'search' of 're.Pattern' objects}
19+
104235 0.013 0.000 0.013 0.000 {method 'startswith' of 'str' objects}
20+
92646 0.011 0.000 0.011 0.000 {method 'lstrip' of 'str' objects}
21+
1813 0.011 0.000 0.011 0.000 {method 'reduce' of 'numpy.ufunc' objects}

docs/HPC_GUIDE.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
### Snellius Usage Breakdown
22

33
```
4-
ssh <your_username>@snellius.surf.nl
4+
ssh kanagnostopoul@snellius.surf.nl
55
66
# On a separate terminal run the following
77
88
# Upload the entire project directory (including your models/ folder)
9-
scp -r ~/Documents/CSS_Project <your_username>@snellius.surf.nl:~/
9+
scp -r ~/CSS_Project kanagnostopoul@snellius.surf.nl:~/
1010
1111
# On the Snellius terminal
1212
@@ -39,9 +39,13 @@ scancel <JOBID>
3939
4040
tail -f logs_<JOBID>.err
4141
42+
# Watch task completetion
43+
44+
watch -n 10 "ls -1 results_JOBID | wc -l"
45+
4246
# Fetching the results once the job is done
4347
44-
scp -r <your_username>@snellius.surf.nl:~/results_18514601 ~/Downloads/
48+
scp -r kanagnostopoul@snellius.surf.nl:~/results_18532145 ~/Downloads/
4549
```
4650

4751
The jobscript template can be found in ```run_analysis.sh``` (default rome paritition).

docs/Mean_Field_Model.pdf

197 KB
Binary file not shown.
File renamed without changes.

docs/experiments.md

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,175 @@ These phases should be completed sequentially, deepening our understanding at ea
2222
- Create autocorrelation plot of mean population count, following perturbations around the critical point
2323
- Look for critical slowing down: perturbations to states closer to the critical point should more slowly return to the steady state
2424
### Phase 4: model extensions
25-
- Investigate whether hydra effect and SOC still occur with diffusion and directed movement
25+
- Investigate whether hydra effect and SOC still occur with diffusion and directed movement
26+
27+
---
28+
29+
30+
## What we are currently collecting:
31+
32+
### 2D Parameter Sweep
33+
34+
We map the full phase space to find:
35+
- Hydra regions
36+
- Critical points
37+
- Coexistence boundaries
38+
- Evolutionary advantage zones
39+
40+
For now at least we sweep:
41+
42+
```
43+
prey_birth in [0.10, 0.35]
44+
prey_death in [0.001, 0.10]
45+
```
46+
47+
Metrics Collected (so far):
48+
49+
1. Population Dynamics
50+
51+
```
52+
53+
prey_mean: time-averaged prey pop
54+
prey_std: variability in prey
55+
56+
# same for predator as above
57+
58+
prey_survived: did prey persist
59+
pred_survived: did pred perist
60+
61+
```
62+
63+
2. Cluster structure
64+
65+
```
66+
67+
prey_n_clusters: total number of prey clusters
68+
pred_n_clusters: total number of pred clusters
69+
prey_tau: power law exp
70+
prey_s_c: cutoff cluster sizes
71+
pred_tau: pred cluster exp
72+
pred_s_c: pred cutoff
73+
74+
```
75+
76+
3. Order Parameters
77+
78+
```
79+
prey_largest_fraction_mean
80+
prey_largest_fraction_std
81+
pred_largest_fraction_mean
82+
prey_percolation_prob: fraction of samples with spanning cluster
83+
pred_percolation_prob: predator percolation prob
84+
85+
```
86+
87+
88+
4. Spatial Correlations
89+
90+
```
91+
92+
pcf_distances: distance bins in lattice units
93+
pcf_prey_prey_mean: prey-prey correlation function
94+
pcf_pred_pred_mean
95+
pcf_prey_pred_mean
96+
segregation_index: measure spatial mixing
97+
prey_clustering_index: short range prey clustering
98+
pred_clustering_index
99+
100+
```
101+
102+
5. Evolutionary dynamics
103+
104+
```
105+
evolved_prey_death_mean: time avg evolved mortality rate
106+
evolved_prey_death_std
107+
evolved_prey_death_final
108+
evolve_sd: mutation strength used
109+
110+
```
111+
112+
---
113+
114+
### Finite-size scaling
115+
116+
We choose a fixed point identified in the main simulation run ```(target_prey_birth, target_prey_death)``` ideally near hydra boundary.
117+
118+
119+
For selected grid sizes (TBD) we run independent reps for each size.
120+
121+
122+
Metrics:
123+
124+
```
125+
grid_size
126+
prey_mean, prey_std
127+
prey_survived: bool
128+
prey_largest_fraction: order parameter
129+
prey_percolation_prob
130+
prey_tau: grid size dependent exponent
131+
prey_tau_se: SE on tau
132+
prey_s_c: cutoff scales
133+
```
134+
135+
---
136+
137+
### Evo Sensitivity
138+
139+
How does mutation strength affect evolutionary advantage in Hydra regions, speed of adaptation and final evolved mortality rates.
140+
141+
Again. choose fixed point identified from main analysis.
142+
143+
Metrics Dict:
144+
145+
```
146+
prey_mean: in cell units as the below metrics as well
147+
prey_std
148+
pred_mean
149+
pred_std
150+
prey_survived: bool
151+
152+
+ same cluster metrics and spatial correlation metrics
153+
154+
155+
evolved_prey_death_mean: avg mortality across all prey
156+
evolved_prey_death_std
157+
evolved_prey_death_final
158+
evolve_sd
159+
```
160+
161+
162+
## Additions Required:
163+
164+
1. Temporal dynamics for time series analysis. Needed to add critical slowing down effect near phase transitions.
165+
166+
```
167+
result["prey_timeseries"] = prey_pops[::10] # Subsample every 10 steps
168+
result["pred_timeseries"] = pred_pops[::10]
169+
170+
```
171+
172+
```
173+
def run_perturbation_experiment(...):
174+
# Save full time series only for these special runs
175+
```
176+
177+
2. Snapshots of spatial configurations. This is a costly operation so we need to figure out how and when to do it in the sim.
178+
179+
3. Saving final grid states?
180+
181+
```
182+
result["final_grid"] = model.grid.copy()
183+
```
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+

0 commit comments

Comments
 (0)