Skip to content

Commit 2876039

Browse files
committed
Add feature extraction and labeling thresholds to config
Introduces new configuration options for feature extraction and program labeling, including thresholds for suggesting simplification, including change descriptions, and labeling implementations as concise or comprehensive. Updates PromptConfig and PromptSampler to use these new parameters, while maintaining backward compatibility with the deprecated code_length_threshold.
1 parent 52b8085 commit 2876039

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

configs/default_config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ prompt:
6868
max_artifact_bytes: 20480 # Maximum artifact size in bytes (20KB default)
6969
artifact_security_filter: true # Apply security filtering to artifacts
7070

71+
# Feature extraction and program labeling thresholds
72+
# These control how the LLM perceives and categorizes programs
73+
suggest_simplification_after_chars: 500 # Suggest simplifying if program exceeds this many characters
74+
include_changes_under_chars: 100 # Include change descriptions in features if under this length
75+
concise_implementation_max_lines: 10 # Label as "concise" if program has this many lines or fewer
76+
comprehensive_implementation_min_lines: 50 # Label as "comprehensive" if program has this many lines or more
77+
7178
# Note: meta-prompting features are not yet implemented
7279

7380
# Database configuration

openevolve/config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,14 @@ class PromptConfig:
142142
max_artifact_bytes: int = 20 * 1024 # 20KB in prompt
143143
artifact_security_filter: bool = True
144144

145-
# Improvement areas
146-
code_length_threshold: Optional[int] = 500
145+
# Feature extraction and program labeling
146+
suggest_simplification_after_chars: Optional[int] = 500 # Suggest simplifying if program exceeds this many characters
147+
include_changes_under_chars: Optional[int] = 100 # Include change descriptions in features if under this length
148+
concise_implementation_max_lines: Optional[int] = 10 # Label as "concise" if program has this many lines or fewer
149+
comprehensive_implementation_min_lines: Optional[int] = 50 # Label as "comprehensive" if program has this many lines or more
150+
151+
# Backward compatibility - deprecated
152+
code_length_threshold: Optional[int] = None # Deprecated: use suggest_simplification_after_chars
147153

148154

149155
@dataclass

openevolve/prompt/sampler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ def _identify_improvement_areas(
171171
improvement_areas = []
172172

173173
# Check program length
174-
if self.config.code_length_threshold and len(current_program) > self.config.code_length_threshold:
174+
# Support both old and new parameter names for backward compatibility
175+
threshold = self.config.suggest_simplification_after_chars or self.config.code_length_threshold
176+
if threshold and len(current_program) > threshold:
175177
improvement_areas.append(
176178
"Consider simplifying the code to improve readability and maintainability"
177179
)
@@ -499,7 +501,7 @@ def _extract_unique_features(self, program: Dict[str, Any]) -> str:
499501
metadata = program.get("metadata", {})
500502
if "changes" in metadata:
501503
changes = metadata["changes"]
502-
if isinstance(changes, str) and len(changes) < 100:
504+
if isinstance(changes, str) and self.config.include_changes_under_chars and len(changes) < self.config.include_changes_under_chars:
503505
features.append(f"Modification: {changes}")
504506

505507
# Analyze metrics for standout characteristics
@@ -521,9 +523,9 @@ def _extract_unique_features(self, program: Dict[str, Any]) -> str:
521523
features.append("NumPy-based implementation")
522524
if "for" in code_lower and "while" in code_lower:
523525
features.append("Mixed iteration strategies")
524-
if len(code.split("\n")) < 10:
526+
if self.config.concise_implementation_max_lines and len(code.split("\n")) <= self.config.concise_implementation_max_lines:
525527
features.append("Concise implementation")
526-
elif len(code.split("\n")) > 50:
528+
elif self.config.comprehensive_implementation_min_lines and len(code.split("\n")) >= self.config.comprehensive_implementation_min_lines:
527529
features.append("Comprehensive implementation")
528530

529531
# Default if no specific features found

0 commit comments

Comments
 (0)