Skip to content

Commit 9ec0513

Browse files
committed
phase 6 config and runner for directed hunting equivalent
1 parent 251b970 commit 9ec0513

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

hpc/run_phase3.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ echo "CPUs: $SLURM_CPUS_PER_TASK"
3535
echo "Start: $(date)"
3636
echo "Working dir: $(pwd)"
3737
echo "========================================"
38-
x
3938
# -----------------------------------------------------------------------------
4039
# Environment Setup
4140
# -----------------------------------------------------------------------------
@@ -93,5 +92,4 @@ echo " 1. Download phase3_results.jsonl"
9392
echo " 2. Analyze cluster size distributions P(s) for each grid size"
9493
echo " 3. Fit power-law exponent tau from P(s) ~ s^(-tau)"
9594
echo " 4. Check finite-size cutoff s_max ~ L^D (fractal dimension)"
96-
echo "========================================"
97-
EOF
95+
echo "========================================"

models/config.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,22 @@ def estimate_runtime(self, n_cores: int = 32) -> str:
262262
timeseries_subsample=1, # Full resolution for autocorrelation
263263
)
264264

265-
# Phase 6: Model extensions
266-
PHASE6_CONFIG = Config() #FIXME: Will be defined later
265+
# Phase 6: Model extensions (directed hunting); same config as phase 1 but with directed hunting
266+
PHASE6_CONFIG = Config(
267+
grid_size=1000,
268+
n_prey_death=20,
269+
prey_birth=0.2,
270+
prey_death_range=(0.09, 0.12),
271+
predator_birth=0.8,
272+
predator_death=0.05,
273+
n_replicates=30,
274+
warmup_steps=1000,
275+
measurement_steps=1000,
276+
collect_pcf=True,
277+
pcf_sample_rate=0.2,
278+
save_timeseries=False,
279+
directed_hunting=True,
280+
)
267281

268282
PHASE_CONFIGS = {
269283
1: PHASE1_CONFIG,

scripts/experiments.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,47 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
652652
- Compare directed vs random hunting
653653
- Check if Hydra effect and SOC persist
654654
"""
655-
pass
655+
from joblib import Parallel, delayed
656+
657+
warmup_numba_kernels(cfg.grid_size, directed_hunting=cfg.directed_hunting)
658+
659+
prey_deaths = cfg.get_prey_deaths()
660+
jobs = []
661+
for pd in prey_deaths:
662+
for rep in range(cfg.n_replicates):
663+
params = {"pd": pd}
664+
seed = generate_unique_seed(params, rep)
665+
jobs.append((cfg.prey_birth, pd, cfg.predator_birth, cfg.predator_death,
666+
cfg.grid_size, seed, cfg, False))
667+
668+
logger.info(f"Phase 6: {len(jobs):,} simulations (directed hunting)")
669+
logger.info(f" Grid: {cfg.n_prey_death} prey_death values × {cfg.n_replicates} reps (prey_birth={cfg.prey_birth})")
656670

671+
output_jsonl = output_dir / "phase1_results.jsonl"
672+
all_results = []
673+
674+
with open(output_jsonl, "w", encoding="utf-8") as f:
675+
executor = Parallel(n_jobs=cfg.n_jobs, return_as="generator")
676+
tasks = (delayed(run_single_simulation)(*job) for job in jobs)
677+
678+
for result in tqdm(executor(tasks), total=len(jobs), desc="Phase 6"):
679+
f.write(json.dumps(result, default=str) + "\n")
680+
f.flush()
681+
all_results.append(result)
682+
683+
# Save metadata
684+
meta = {
685+
"phase": 6,
686+
"description": "Parameter sweep for critical point with directed hunting",
687+
"n_sims": len(all_results),
688+
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
689+
"config": asdict(cfg),
690+
}
691+
with open(output_dir / "phase6_metadata.json", "w") as f:
692+
json.dump(meta, f, indent=2, default=str)
693+
694+
logger.info(f"Phase 6 complete. Results: {output_jsonl}")
695+
return all_results
657696
# =============================================================================
658697
# Main:
659698
# =============================================================================

0 commit comments

Comments
 (0)