Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openevolve/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ async def run(
Best program found

Raises:
FileNotFoundError: If checkpoint_path is given but does not exist
EvolutionFailedError: If iterations ran but none produced a candidate program
"""
# Ensure run_id exists even if instance was created without __init__ (e.g. in tests)
Expand Down Expand Up @@ -414,7 +415,7 @@ async def _run_evolution(
max_iterations = self.config.max_iterations if iterations is None else iterations
# Determine starting iteration
start_iteration = 0
if checkpoint_path and os.path.exists(checkpoint_path):
if checkpoint_path:
self._load_checkpoint(checkpoint_path)
start_iteration = self.database.last_iteration + 1
logger.info(f"Resuming from checkpoint at iteration {start_iteration}")
Expand Down
32 changes: 32 additions & 0 deletions tests/test_checkpoint_resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,38 @@ async def run_test():
# Run the async test
asyncio.run(run_test())

def test_missing_checkpoint_path_raises(self):
"""A checkpoint_path that does not exist must not silently start a fresh run"""

async def run_test():
with patch("openevolve.controller.Evaluator") as mock_evaluator_class:
mock_evaluator = MockEvaluator()
mock_evaluator_class.return_value = mock_evaluator

controller = OpenEvolve(
initial_program_path=self.test_program_path,
evaluation_file=self.evaluator_path,
config=self.config,
output_dir=self.test_dir,
)

missing = os.path.join(self.test_dir, "checkpoints", "checkpoint_50")
with patch(
"openevolve.controller.ProcessParallelController"
) as mock_parallel_class:
mock_parallel = mock_parallel_class.return_value
mock_parallel.run_evolution = AsyncMock(return_value=None)
mock_parallel.shutdown_event.is_set.return_value = False
mock_parallel.produced_no_candidates = False
with self.assertRaisesRegex(FileNotFoundError, "checkpoint_50"):
await controller.run(iterations=0, checkpoint_path=missing)

mock_parallel_class.assert_not_called()
self.assertEqual(len(controller.database.programs), 0)
self.assertEqual(mock_evaluator.call_count, 0)

asyncio.run(run_test())


if __name__ == "__main__":
unittest.main()
Loading