Skip to content

Commit ccd9a1a

Browse files
committed
tests and docs done
1 parent 1822933 commit ccd9a1a

23 files changed

Lines changed: 2253 additions & 3145 deletions

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,66 @@
11
#!/usr/bin/env python3
22
"""
3-
Predator-Prey Hydra Effect Experiments - HPC Version
4-
5-
Experimental phases (run sequentially):
6-
Phase 1: Parameter sweep to find critical point (bifurcation + cluster analysis)
7-
Phase 2: Self-organization analysis (evolution toward criticality)
8-
Phase 3: Finite-size scaling at critical point
9-
Phase 4: Sensitivity analysis across parameter regimes
10-
Phase 5: Model extensions (directed hunting comparison)
11-
12-
Usage:
13-
python experiments.py --phase 1 # Run phase 1
14-
python experiments.py --phase 1 --dry-run # Estimate runtime
15-
python experiments.py --phase all # Run all phases
16-
python experiments.py --phase 1 --output results/ # Custom output
3+
Predator-Prey Hydra Effect Experiments
4+
======================================
5+
6+
HPC-ready experiment runner for investigating the Hydra effect in
7+
predator-prey cellular automata.
8+
9+
Experimental Phases
10+
-------------------
11+
- **Phase 1**: Parameter sweep to find critical point (bifurcation + cluster analysis)
12+
- **Phase 2**: Self-organization analysis (evolution toward criticality)
13+
- **Phase 3**: Finite-size scaling at critical point
14+
- **Phase 4**: Sensitivity analysis across parameter regimes
15+
- **Phase 5**: Model extensions (directed hunting comparison)
16+
17+
Functions
18+
---------
19+
```python
20+
run_single_simulation # Execute one simulation run and collect metrics.
21+
run_phase1, run_phase2, run_phase3, run_phase4, run_phase5 # Phase-specific experiment runners.
22+
```
23+
24+
Utilities
25+
---------
26+
```python
27+
generate_unique_seed # Deterministic seed generation from parameters.
28+
count_populations # Count species populations on grid.
29+
get_evolved_stats # Statistics for evolved parameters.
30+
average_pcfs # Average multiple PCF measurements.
31+
save_results_jsonl, load_results_jsonl, save_results_npz # I/O functions for experiment results.
32+
```
33+
34+
Command Line Usage
35+
------------------
36+
```bash
37+
python experiments.py --phase 1 # Run phase 1
38+
python experiments.py --phase 1 --dry-run # Estimate runtime
39+
python experiments.py --phase all # Run all phases
40+
python experiments.py --phase 1 --output results/ # Custom output
41+
```
42+
43+
Programmatic Usage
44+
------------------
45+
```python
46+
from experiments import run_single_simulation, run_phase1
47+
from models.config import PHASE1_CONFIG
48+
49+
# Single simulation
50+
result = run_single_simulation(
51+
prey_birth=0.2,
52+
prey_death=0.05,
53+
predator_birth=0.8,
54+
predator_death=0.1,
55+
grid_size=100,
56+
seed=42,
57+
cfg=PHASE1_CONFIG,
58+
)
59+
60+
# Full phase (writes to output directory)
61+
import logging
62+
results = run_phase1(PHASE1_CONFIG, Path("results/"), logging.getLogger())
63+
```
1764
"""
1865

1966
import argparse
@@ -45,7 +92,6 @@
4592
from models.numba_optimized import (
4693
compute_all_pcfs_fast,
4794
get_cluster_stats_fast,
48-
get_percolating_cluster_fast,
4995
warmup_numba_kernels,
5096
set_numba_seed,
5197
NUMBA_AVAILABLE,
@@ -419,7 +465,6 @@ def run_single_simulation(
419465
"predator_birth": predator_birth,
420466
},
421467
seed=seed,
422-
synchronous=cfg.synchronous,
423468
directed_hunting=cfg.directed_hunting,
424469
)
425470

misc/mean_field.py

Lines changed: 0 additions & 201 deletions
This file was deleted.

models/CA.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
#!/usr/bin/env python3
12
"""
2-
Cellular automaton base class.
3+
Cellular Automaton Framework
4+
============================
5+
6+
This module provides the base cellular automaton class and the
7+
Predator-Prey (PP) implementation with Numba-accelerated kernels.
8+
9+
Classes
10+
-------
11+
CA: Abstract base class for spatial cellular automata.
12+
13+
PP: Predator-Prey model with configurable hunting behavior.
14+
15+
Example
16+
-------
17+
```python
18+
from models.CA import PP
19+
20+
# Basic usage
21+
model = PP(rows=100, cols=100, densities=(0.3, 0.15), seed=42)
22+
model.run(steps=1000)
23+
24+
# With evolution enabled
25+
model = PP(rows=100, cols=100, seed=42)
26+
model.evolve("prey_death", sd=0.05, min_val=0.01, max_val=0.15)
27+
model.run(steps=500)
28+
29+
# With directed hunting
30+
model = PP(rows=100, cols=100, directed_hunting=True, seed=42)
31+
```
332
"""
433

534
from typing import Tuple, Dict, Optional
@@ -610,7 +639,4 @@ def update(self) -> None:
610639
"""
611640
Dispatch the simulation step based on the configured update mode.
612641
"""
613-
if self.synchronous:
614-
self.update_sync()
615-
else:
616-
self.update_async()
642+
self.update_async()

0 commit comments

Comments
 (0)