Skip to content

Commit f02c217

Browse files
committed
Update evaluator.py
1 parent 49ca77a commit f02c217

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

openevolve/evaluator.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,25 @@ async def evaluate_program(
123123
metrics[f"llm_{name}"] = value * self.config.llm_feedback_weight
124124

125125
elapsed = time.time() - start_time
126+
127+
# Safe formatting of metrics to prevent formatting errors
128+
def safe_format_metric_value(value):
129+
"""Safely format a metric value for logging."""
130+
try:
131+
if isinstance(value, (int, float)) and not isinstance(value, bool):
132+
import math
133+
if math.isnan(value) or math.isinf(value):
134+
return str(value)
135+
return f"{value:.4f}"
136+
else:
137+
return str(value)
138+
except (ValueError, TypeError):
139+
return str(value)
140+
141+
metrics_str = ', '.join(f'{name}={safe_format_metric_value(value)}' for name, value in metrics.items())
142+
126143
logger.info(
127-
f"Evaluated program{program_id_str} in {elapsed:.2f}s: "
128-
f"{', '.join(f'{name}={value:.4f}' for name, value in metrics.items())}"
144+
f"Evaluated program{program_id_str} in {elapsed:.2f}s: {metrics_str}"
129145
)
130146

131147
return metrics

0 commit comments

Comments
 (0)