@@ -646,52 +646,87 @@ def run_phase5(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
646646 return all_results
647647
648648
649- def run_phase6 (cfg : Config , output_dir : Path , logger : logging .Logger ) -> List [Dict ]:
649+
650+ def run_phase4 (cfg : Config , output_dir : Path , logger : logging .Logger ) -> List [Dict ]:
650651 """
651- Phase 6: Model extensions.
652- - Compare directed vs random hunting
653- - Check if Hydra effect and SOC persist
652+ Phase 4: Global Sensitivity Analysis.
653+ Vary: prey_birth, prey_death, predator_birth, predator_death
654+ Range: 0-1 (11 values each)
655+ Reps: 10
656+ Grid size: 250
654657 """
655658 from joblib import Parallel , delayed
659+ import itertools
656660
657661 warmup_numba_kernels (cfg .grid_size , directed_hunting = cfg .directed_hunting )
658662
659- prey_deaths = cfg .get_prey_deaths ()
663+ # Define the global sweep values
664+ sweep_values = np .linspace (0.0 , 1.0 , 11 )
665+
666+ # Logging
667+ logger .info (f"Phase 4: Full 4D Parameter Sweep" )
668+ logger .info (f" Parameters: prey_birth, prey_death, pred_birth, pred_death" )
669+ logger .info (f" Range: 0.0 to 1.0 (11 steps)" )
670+ logger .info (f" Grid Size: { cfg .grid_size } " )
671+ logger .info (f" Replicates: { cfg .n_replicates } " )
672+
673+ param_grid = itertools .product (sweep_values , repeat = 4 )
674+
660675 jobs = []
661- for pd in prey_deaths :
676+
677+ for pb , pd , pred_b , pred_d in param_grid :
662678 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 ))
679+ # Create params dict for unique seed generation
680+ params_id = {
681+ "pb" : pb ,
682+ "pd" : pd ,
683+ "pred_b" : pred_b ,
684+ "pred_d" : pred_d ,
685+ "rep" : rep
686+ }
687+ seed = generate_unique_seed (params_id , rep )
667688
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 } )" )
670-
671- output_jsonl = output_dir / "phase6_results.jsonl"
689+ # Job Signature:
690+ # (prey_birth, prey_death, predator_birth, predator_death, grid_size, seed, cfg, with_evolution)
691+ jobs .append ((
692+ pb ,
693+ pd ,
694+ pred_b ,
695+ pred_d ,
696+ cfg .grid_size ,
697+ seed ,
698+ cfg ,
699+ False
700+ ))
701+
702+ logger .info (f" Total simulations: { len (jobs ):,} " )
703+ output_jsonl = output_dir / "phase4_results.jsonl"
672704 all_results = []
673705
674706 with open (output_jsonl , "w" , encoding = "utf-8" ) as f :
675707 executor = Parallel (n_jobs = cfg .n_jobs , return_as = "generator" )
676708 tasks = (delayed (run_single_simulation )(* job ) for job in jobs )
677709
678- for result in tqdm (executor (tasks ), total = len (jobs ), desc = "Phase 6" ):
710+ # tqdm shows progress for the massive job list
711+ for result in tqdm (executor (tasks ), total = len (jobs ), desc = "Phase 4 (4D Sweep)" ):
679712 f .write (json .dumps (result , default = str ) + "\n " )
680713 f .flush ()
681714 all_results .append (result )
682715
683- # Save metadata
716+ # 4. Save Metadata
684717 meta = {
685- "phase" : 6 ,
686- "description" : "Parameter sweep for critical point with directed hunting" ,
718+ "phase" : 4 ,
719+ "description" : "Global 4D Sensitivity Analysis" ,
720+ "sweep_values" : sweep_values .tolist (),
721+ "parameters_varied" : ["prey_birth" , "prey_death" , "predator_birth" , "predator_death" ],
687722 "n_sims" : len (all_results ),
688723 "timestamp" : time .strftime ("%Y-%m-%d %H:%M:%S" ),
689724 "config" : asdict (cfg ),
690725 }
691- with open (output_dir / "phase6_metadata .json" , "w" ) as f :
726+ with open (output_dir / "phase4_metadata .json" , "w" ) as f :
692727 json .dump (meta , f , indent = 2 , default = str )
693728
694- logger .info (f"Phase 6 complete. Results: { output_jsonl } " )
729+ logger .info (f"Phase 4 complete. Results: { output_jsonl } " )
695730 return all_results
696731# =============================================================================
697732# Main:
0 commit comments