Skip to content

Commit e84532c

Browse files
author
henrique
committed
rename some constants
1 parent f4d75e8 commit e84532c

7 files changed

Lines changed: 32 additions & 29 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ Optional:
549549
output_directory/
550550
├── config.yaml # Copy of configuration used
551551
├── 0/ # Island 0 results
552-
│ ├── island.log # Detailed execution log
552+
│ └── logs/ # Logs
553+
│ ├── run_1.log
554+
│ ├── run_2.log
555+
│ └── ...
553556
│ ├── best_sol.py # Best solution found
554557
│ ├── best_prompt.txt # Best prompt evolved
555558
│ └── ckpt/ # Checkpoints

src/codeevolve/evolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ def _create_timeout_scheduler(
11411141
kwargs: Dict[str, Any] = timeout_cfg.get("kwargs", {})
11421142
scheduler_type: str = timeout_cfg.get("type", "ExponentialScheduler")
11431143
return SCHEDULER_TYPES[scheduler_type](
1144-
value=float(budget["eval_timeout"]),
1144+
value=float(kwargs["min_value"]),
11451145
**kwargs,
11461146
)
11471147

@@ -1442,7 +1442,7 @@ async def codeevolve(
14421442
components.logger.info("Waiting for other islands to finish setup...")
14431443
global_data.barrier.wait()
14441444
components.logger.info("All islands finished. Starting CodeEvolve loop.")
1445-
1445+
14461446
await codeevolve_loop(
14471447
components.start_epoch,
14481448
components.evolve_state,

src/codeevolve/runner.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ def async_run_codeevolve(
136136
error_msg = f"Island {isl_data.id} crashed with exception: {type(e).__name__}: {str(e)}"
137137
full_traceback = traceback.format_exc()
138138
try:
139-
isl_out_dir: Path = run_args.get("isl_out_dir")
140-
if isl_out_dir:
141-
_write_island_crash_log(isl_out_dir, error_msg, full_traceback)
139+
isl_logs_dir: Path = run_args.get("logs_dir")
140+
if isl_logs_dir:
141+
_write_island_crash_log(isl_logs_dir, error_msg, full_traceback, int(global_data.start_time.value))
142142
except Exception:
143143
pass
144144

@@ -247,29 +247,29 @@ def cleanup_log_daemon(
247247
# ---------------------------------------------------------------------------
248248

249249

250-
def _write_island_crash_log(isl_out_dir: Path, error_msg: str, full_traceback: str) -> None:
250+
def _write_island_crash_log(isl_logs_dir: Path, error_msg: str, full_traceback: str, time: int = 0) -> None:
251251
"""Writes detailed crash information to an island's crash log file.
252252
253253
Called from within the child process where the exception occurred.
254254
255255
Args:
256-
isl_out_dir: Island's output directory.
256+
isl_logs_dir: Island's logs directory.
257257
error_msg: Summary error message.
258258
full_traceback: Full Python traceback string.
259+
time: Int identifying global time of the run.
259260
"""
260-
crash_log_path: Path = isl_out_dir.joinpath(CRASH_LOG_FILE)
261-
timestamp: str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
261+
crash_log_path: Path = isl_logs_dir.joinpath(CRASH_LOG_FILE.format(time=time))
262262
with open(crash_log_path, "a") as f:
263263
f.write(f"\n{'='*60}\n")
264-
f.write(f"CRASH REPORT - {timestamp}\n")
264+
f.write(f"CRASH REPORT\n")
265265
f.write(f"{'='*60}\n")
266266
f.write(f"{error_msg}\n\n")
267267
f.write("Full Traceback:\n")
268268
f.write(full_traceback)
269269
f.write(f"{'='*60}\n\n")
270270

271271

272-
def _write_crash_summary(out_dir: Path, island_id: int, exit_code: int, message: str) -> None:
272+
def _write_crash_summary(out_dir: Path, island_id: int, exit_code: int, message: str, time: int = 0) -> None:
273273
"""Writes crash summary to the main output directory's crash log.
274274
275275
Called from the parent process when it detects an island has crashed.
@@ -279,18 +279,17 @@ def _write_crash_summary(out_dir: Path, island_id: int, exit_code: int, message:
279279
island_id: ID of the island that crashed.
280280
exit_code: Exit code of the crashed process.
281281
message: Summary message.
282+
time: Int identifying global time of the run.
282283
"""
283-
crash_log_path: Path = out_dir.joinpath(CRASH_LOG_FILE)
284-
timestamp: str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
285-
284+
crash_log_path: Path = out_dir.joinpath(CRASH_LOG_FILE.format(time=time))
286285
with open(crash_log_path, "a") as f:
287286
f.write(f"\n{'='*60}\n")
288-
f.write(f"CRASH REPORT - {timestamp}\n")
287+
f.write(f"CRASH REPORT\n")
289288
f.write(f"{'='*60}\n")
290289
f.write(f"Island: {island_id}\n")
291290
f.write(f"Exit Code: {exit_code}\n")
292291
f.write(f"Message: {message}\n")
293-
f.write(f"See island {island_id}/{CRASH_LOG_FILE} for full traceback.\n")
292+
f.write(f"See island_{island_id}/logs/{CRASH_LOG_FILE.format(time=time)} for full traceback.\n")
294293
f.write(f"{'='*60}\n\n")
295294

296295

@@ -327,6 +326,7 @@ def monitor_island_processes(
327326
"""
328327
num_islands: int = len(processes)
329328
completed: List[bool] = [False] * num_islands
329+
time: int = int(global_data.start_time.value)
330330

331331
try:
332332
while not all(completed):
@@ -345,13 +345,12 @@ def monitor_island_processes(
345345
error_msg: str = (
346346
f"Island {i} died unexpectedly with exit code {process.exitcode}"
347347
)
348-
349-
_write_crash_summary(out_dir, i, process.exitcode, error_msg)
348+
_write_crash_summary(out_dir, i, process.exitcode, error_msg, time)
350349

351350
print(f"\n{'='*60}", file=sys.stderr)
352351
print(f"ERROR: {error_msg}", file=sys.stderr)
353352
print(
354-
f"See {out_dir}/{CRASH_LOG_FILE} and island logs for details.",
353+
f"See {out_dir}/{CRASH_LOG_FILE.format(time=time)} and island logs for details.",
355354
file=sys.stderr,
356355
)
357356
print(f"{'='*60}\n", file=sys.stderr)

src/codeevolve/utils/cli_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def setup_island_args(
210210

211211
for island_id in range(num_islands):
212212
isl_args: Dict[str, Any] = args.copy()
213-
isl_out_dir: Path = args["out_dir"].joinpath(f"{island_id}")
213+
isl_out_dir: Path = args["out_dir"].joinpath(f"island_{island_id}")
214214
ckpt_dir: Path = isl_out_dir.joinpath("ckpt")
215215
logs_dir: Path = isl_out_dir.joinpath("logs")
216216

src/codeevolve/utils/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
# ---------------------------------------------------------------------------
4242

4343
LOCK_FILE: str = ".codeevolve.lock"
44-
ISLAND_LOG_FILE: str = "island_{time}.log"
45-
CRASH_LOG_FILE: str = "crash.log"
44+
ISLAND_LOG_FILE: str = "run_{time}.log"
45+
CRASH_LOG_FILE: str = "crash_{time}.log"
4646
RUN_METADATA_FILE: str = "run_metadata.json"
4747
BEST_SOLUTION_FILE: str = "best_sol"
4848
BEST_PROMPT_FILE: str = "best_prompt.txt"

tests/test_ckpt.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ def test_save_and_load_metadata(self, tmp_path: Path):
210210
best_sol.depth.value = 5
211211

212212
save_run_metadata(
213-
tmp_path, epoch=10, elapsed_time=120.5, cpu_count=8, global_best_sol=best_sol
213+
tmp_path, epoch=10, elapsed_time=120.5, cpu_count=8, global_best_sol=best_sol,early_stop_counter=5
214214
)
215215

216216
metadata: Optional[Dict[str, Any]] = load_run_metadata(tmp_path, epoch=10)
217217
assert metadata is not None
218218
assert metadata["elapsed_time"] == 120.5
219219
assert metadata["cpu_count"] == 8
220+
assert metadata["early_stop_counter"] == 5
220221
assert metadata["best_sol"]["fitness"] == 42.0
221222

222223
def test_load_nonexistent_metadata(self, tmp_path: Path):
@@ -228,7 +229,7 @@ def test_load_missing_epoch(self, tmp_path: Path):
228229
"""Tests loading metadata for a missing epoch returns empty dict."""
229230
best_sol: GlobalBestProg = GlobalBestProg()
230231
save_run_metadata(
231-
tmp_path, epoch=10, elapsed_time=100.0, cpu_count=4, global_best_sol=best_sol
232+
tmp_path, epoch=10, elapsed_time=100.0, cpu_count=4, global_best_sol=best_sol, early_stop_counter=5
232233
)
233234

234235
metadata: Optional[Dict[str, Any]] = load_run_metadata(tmp_path, epoch=99)
@@ -238,10 +239,10 @@ def test_metadata_accumulates(self, tmp_path: Path):
238239
"""Tests that multiple saves accumulate in the same file."""
239240
best_sol: GlobalBestProg = GlobalBestProg()
240241
save_run_metadata(
241-
tmp_path, epoch=10, elapsed_time=100.0, cpu_count=4, global_best_sol=best_sol
242+
tmp_path, epoch=10, elapsed_time=100.0, cpu_count=4, global_best_sol=best_sol, early_stop_counter=5
242243
)
243244
save_run_metadata(
244-
tmp_path, epoch=20, elapsed_time=200.0, cpu_count=4, global_best_sol=best_sol
245+
tmp_path, epoch=20, elapsed_time=200.0, cpu_count=4, global_best_sol=best_sol, early_stop_counter=10
245246
)
246247

247248
metadata_file: Path = tmp_path / RUN_METADATA_FILE

tests/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ def test_logger_without_results_dir(self):
137137
assert logger is not None
138138
assert logger.level == logging.INFO
139139

140-
def test_logger_with_results_dir(self, tmp_path: Path):
140+
def test_logger_with_logs_dir(self, tmp_path: Path):
141141
"""Tests that a logger creates a log file in logs_dir."""
142142
logger: logging.Logger = get_logger(island_id=0, logs_dir=tmp_path, time=100)
143143
logger.info("test message")
144-
log_file: Path = tmp_path / "island_100.log"
144+
log_file: Path = tmp_path / "run_100.log"
145145
assert log_file.exists()
146146

147147
def test_logger_unique_names(self, tmp_path: Path):

0 commit comments

Comments
 (0)