Skip to content

Commit 8a263e7

Browse files
committed
Improve error logging and handle stale feature map references
Use logger.exception for better error tracebacks in controller.py. In database.py, ensure feature map entries are updated if the referenced program no longer exists, preventing stale references and improving robustness.
1 parent 656e153 commit 8a263e7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

openevolve/controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ async def run(
405405
break
406406

407407
except Exception as e:
408-
logger.error(f"Error in iteration {i+1}: {str(e)}")
409-
traceback.print_exc()
408+
logger.exception(f"Error in iteration {i+1}: {str(e)}")
410409
continue
411410

412411
# Get the best program using our tracking mechanism

openevolve/database.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,20 @@ def add(
161161

162162
# Add to feature map (replacing existing if better)
163163
feature_key = self._feature_coords_to_key(feature_coords)
164-
if feature_key not in self.feature_map or self._is_better(
165-
program, self.programs[self.feature_map[feature_key]]
166-
):
164+
should_replace = feature_key not in self.feature_map
165+
166+
if not should_replace:
167+
# Check if the existing program still exists before comparing
168+
existing_program_id = self.feature_map[feature_key]
169+
if existing_program_id not in self.programs:
170+
# Stale reference, replace it
171+
should_replace = True
172+
logger.debug(f"Replacing stale program reference {existing_program_id} in feature map")
173+
else:
174+
# Program exists, compare fitness
175+
should_replace = self._is_better(program, self.programs[existing_program_id])
176+
177+
if should_replace:
167178
self.feature_map[feature_key] = program.id
168179

169180
# Add to specific island (not random!)

0 commit comments

Comments
 (0)