@@ -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