@@ -945,73 +945,7 @@ def run_phase4(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
945945
946946def run_phase5 (cfg : Config , output_dir : Path , logger : logging .Logger ) -> List [Dict ]:
947947 """
948- Phase 5: Perturbation analysis (critical slowing down).
949-
950- - Points around critical point
951- - Full time series for autocorrelation analysis
952- - Measure relaxation times
953- """
954- from joblib import Parallel , delayed
955-
956- warmup_numba_kernels (cfg .grid_size , directed_hunting = cfg .directed_hunting )
957-
958- pb = cfg .critical_prey_birth
959- base_pd = cfg .critical_prey_death
960-
961- jobs = []
962- for offset in cfg .prey_death_offsets :
963- pd = base_pd + offset
964- if pd <= 0 :
965- continue
966-
967- for rep in range (cfg .n_replicates ):
968- params = {"offset" : offset , "phase" : 5 }
969- seed = generate_unique_seed (params , rep )
970- jobs .append (
971- (
972- pb ,
973- pd ,
974- cfg .predator_birth ,
975- cfg .predator_death ,
976- cfg .grid_size ,
977- seed ,
978- cfg ,
979- False ,
980- )
981- )
982-
983- logger .info (f"Phase 5: { len (jobs ):,} simulations" )
984- logger .info (f" prey_death offsets: { cfg .prey_death_offsets } " )
985- logger .info (f" Base critical point: pb={ pb } , pd={ base_pd } " )
986-
987- output_jsonl = output_dir / "phase5_results.jsonl"
988- all_results = []
989-
990- with open (output_jsonl , "w" , encoding = "utf-8" ) as f :
991- executor = Parallel (n_jobs = cfg .n_jobs , return_as = "generator" )
992- tasks = (delayed (run_single_simulation )(* job ) for job in jobs )
993-
994- for result in tqdm (executor (tasks ), total = len (jobs ), desc = "Phase 5" ):
995- f .write (json .dumps (result , default = str ) + "\n " )
996- f .flush ()
997- all_results .append (result )
998-
999- meta = {
1000- "phase" : 5 ,
1001- "description" : "Perturbation analysis / critical slowing down" ,
1002- "n_sims" : len (all_results ),
1003- "timestamp" : time .strftime ("%Y-%m-%d %H:%M:%S" ),
1004- }
1005- with open (output_dir / "phase5_metadata.json" , "w" ) as f :
1006- json .dump (meta , f , indent = 2 , default = str )
1007-
1008- logger .info (f"Phase 5 complete. Results: { output_jsonl } " )
1009- return all_results
1010-
1011-
1012- def run_phase6 (cfg : Config , output_dir : Path , logger : logging .Logger ) -> List [Dict ]:
1013- """
1014- Execute Phase 6 of the simulation: Global 4D parameter sweep with directed hunting.
948+ Execute Phase 5 of the simulation: Global 4D parameter sweep with directed hunting.
1015949
1016950 This phase performs a comprehensive sensitivity analysis by varying four key
1017951 parameters (prey birth/death and predator birth/death) while directed
@@ -1054,7 +988,7 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
1054988 other_param_values = np .linspace (0.0 , 1.0 , 11 ) # 11 values for the rest
1055989
1056990 # Logging
1057- logger .info (f"Phase 6 : Full 4D Parameter Sweep (Directed Hunting)" )
991+ logger .info (f"Phase 5 : Full 4D Parameter Sweep (Directed Hunting)" )
1058992 logger .info (f" prey_death: 10 values from 0.05 to 0.95" )
1059993 logger .info (f" prey_birth, pred_birth, pred_death: 11 values each from 0 to 1" )
1060994 logger .info (f" Grid Size: { cfg .grid_size } " )
@@ -1101,7 +1035,7 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
11011035 f" Total simulations: { len (jobs ):,} "
11021036 ) # 11 * 10 * 11 * 11 * n_reps = 13,310 * n_reps
11031037
1104- output_jsonl = output_dir / "phase6_results .jsonl"
1038+ output_jsonl = output_dir / "phase5_results .jsonl"
11051039 all_results = []
11061040
11071041 with open (output_jsonl , "w" , encoding = "utf-8" ) as f :
@@ -1117,7 +1051,7 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
11171051
11181052 # Save Metadata
11191053 meta = {
1120- "phase" : 6 ,
1054+ "phase" : 5 ,
11211055 "description" : "Global 4D Sensitivity Analysis with Directed Hunting" ,
11221056 "prey_death_values" : prey_death_values .tolist (),
11231057 "other_param_values" : other_param_values .tolist (),
@@ -1135,7 +1069,7 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
11351069 with open (output_dir / "phase6_metadata.json" , "w" ) as f :
11361070 json .dump (meta , f , indent = 2 , default = str )
11371071
1138- logger .info (f"Phase 6 complete. Results: { output_jsonl } " )
1072+ logger .info (f"Phase 5 complete. Results: { output_jsonl } " )
11391073 return all_results
11401074
11411075
@@ -1149,7 +1083,6 @@ def run_phase6(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
11491083 3 : run_phase3 ,
11501084 4 : run_phase4 ,
11511085 5 : run_phase5 ,
1152- 6 : run_phase6 ,
11531086}
11541087
11551088
0 commit comments