Skip to content

Commit e74fbc8

Browse files
committed
fixing config
1 parent e10b916 commit e74fbc8

2 files changed

Lines changed: 21 additions & 102 deletions

File tree

models/config.py

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from typing import Tuple, Optional
2222
import numpy as np
2323

24+
#FIXME: Tidy up config file for submission
25+
2426

2527
@dataclass
2628
class Config:
@@ -106,28 +108,28 @@ class Config:
106108
"""
107109

108110
# Grid settings
109-
grid_size: int = 1000 # FIXME: Decide default configuration
111+
grid_size: int = 1000
110112
densities: Tuple[float, float] = (
111113
0.30,
112114
0.15,
113-
) # (prey, predator) #FIXME: Default densities
115+
) # (prey, predator)
114116

115117
# For FSS experiments: multiple grid sizes
116118
grid_sizes: Tuple[int, ...] = (50, 100, 250, 500, 1000, 2500)
117119

118120
# Default/fixed parameters
119121
prey_birth: float = 0.2
120122
prey_death: float = 0.05
121-
predator_birth: float = 0.8 # FIXME: Default predator death rate
122-
predator_death: float = 0.05 # FIXME: Default predator death rate
123+
predator_birth: float = 0.8
124+
predator_death: float = 0.05
123125

124126
# Critical point (UPDATE AFTER PHASE 1)
125127
critical_prey_birth: float = 0.20
126128
critical_prey_death: float = 0.947
127129

128130
# Prey parameter sweep (Phase 1)
129131
prey_death_range: Tuple[float, float] = (0.0, 0.2)
130-
n_prey_birth: int = 15 # FIXME: Decide number of grid points along prey axes
132+
n_prey_birth: int = 15
131133
n_prey_death: int = 5
132134

133135
# Predator parameter sweep (Phase 4 sensitivity)
@@ -136,13 +138,13 @@ class Config:
136138
0.20,
137139
0.25,
138140
0.30,
139-
) # FIXME: Bogus values for now
141+
)
140142
predator_death_values: Tuple[float, ...] = (
141143
0.05,
142144
0.10,
143145
0.15,
144146
0.20,
145-
) # FIXME: Bogus values for now
147+
)
146148

147149
# Perturbation offsets from critical point (Phase 5)
148150
prey_death_offsets: Tuple[float, ...] = (
@@ -151,14 +153,14 @@ class Config:
151153
0.0,
152154
0.01,
153155
0.02,
154-
) # FIXME: Bogus values for now
156+
)
155157

156158
# Number of replicates per parameter configuration
157-
n_replicates: int = 15 # FIXME: Decide number of indep. runs per parameter config
159+
n_replicates: int = 15
158160

159161
# Simulation steps
160-
warmup_steps: int = 300 # FIXME: Steps to run before measuring
161-
measurement_steps: int = 500 # FIXME: Decide measurement steps
162+
warmup_steps: int = 300
163+
measurement_steps: int = 500
162164

163165
# Evo
164166
with_evolution: bool = False
@@ -173,7 +175,7 @@ class Config:
173175
0.10,
174176
0.15,
175177
0.20,
176-
) # FIXME: Don't know if we use yet
178+
)
177179

178180
# Update mode
179181
synchronous: bool = False # Always False for this model
@@ -184,7 +186,7 @@ class Config:
184186

185187
# Temporal data collection (time series)
186188
save_timeseries: bool = False
187-
timeseries_subsample: int = 10 # FIXME: Save every how many steps
189+
timeseries_subsample: int = 10
188190

189191
# PCF settings
190192
collect_pcf: bool = True
@@ -319,7 +321,6 @@ def estimate_runtime(self, n_cores: int = 32) -> str:
319321
# Experimental Phase Configurations
320322
############################################################################################
321323

322-
# FIXME: These configs are arbitraty and should be finalized before running experiments.
323324

324325
PHASE1_CONFIG = Config(
325326
grid_size=1000,
@@ -381,22 +382,8 @@ def estimate_runtime(self, n_cores: int = 32) -> str:
381382
directed_hunting=False,
382383
)
383384

384-
385-
# Phase 5: Perturbation analysis (critical slowing down)
386-
PHASE5_CONFIG = Config(
387-
grid_size=100,
388-
prey_death_offsets=(-0.02, -0.01, 0.0, 0.01, 0.02), # FIXME: Is this what we vary?
389-
n_replicates=20,
390-
warmup_steps=500,
391-
measurement_steps=2000,
392-
perturbation_magnitude=0.1,
393-
collect_pcf=False,
394-
save_timeseries=True,
395-
timeseries_subsample=1, # Full resolution for autocorrelation
396-
)
397-
398385
# Phase 6: Model extensions (directed reproduction); same config as phase 4 but with directed reproduction
399-
PHASE6_CONFIG = Config(
386+
PHASE5_CONFIG = Config(
400387
grid_size=250,
401388
n_replicates=10,
402389
warmup_steps=500,
@@ -414,7 +401,6 @@ def estimate_runtime(self, n_cores: int = 32) -> str:
414401
3: PHASE3_CONFIG,
415402
4: PHASE4_CONFIG,
416403
5: PHASE5_CONFIG,
417-
6: PHASE6_CONFIG,
418404
}
419405

420406

scripts/experiments.py

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -945,73 +945,7 @@ def run_phase4(cfg: Config, output_dir: Path, logger: logging.Logger) -> List[Di
945945

946946
def 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

Comments
 (0)