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
7 changes: 7 additions & 0 deletions configs/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ prompt:
max_artifact_bytes: 20480 # Maximum artifact size in bytes (20KB default)
artifact_security_filter: true # Apply security filtering to artifacts

# Feature extraction and program labeling thresholds
# These control how the LLM perceives and categorizes programs
suggest_simplification_after_chars: 500 # Suggest simplifying if program exceeds this many characters
include_changes_under_chars: 100 # Include change descriptions in features if under this length
concise_implementation_max_lines: 10 # Label as "concise" if program has this many lines or fewer
comprehensive_implementation_min_lines: 50 # Label as "comprehensive" if program has this many lines or more

# Note: meta-prompting features are not yet implemented

# Database configuration
Expand Down
9 changes: 9 additions & 0 deletions openevolve/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ class PromptConfig:
max_artifact_bytes: int = 20 * 1024 # 20KB in prompt
artifact_security_filter: bool = True

# Feature extraction and program labeling
suggest_simplification_after_chars: Optional[int] = 500 # Suggest simplifying if program exceeds this many characters
include_changes_under_chars: Optional[int] = 100 # Include change descriptions in features if under this length
concise_implementation_max_lines: Optional[int] = 10 # Label as "concise" if program has this many lines or fewer
comprehensive_implementation_min_lines: Optional[int] = 50 # Label as "comprehensive" if program has this many lines or more

# Backward compatibility - deprecated
code_length_threshold: Optional[int] = None # Deprecated: use suggest_simplification_after_chars


@dataclass
class DatabaseConfig:
Expand Down
10 changes: 6 additions & 4 deletions openevolve/prompt/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def _identify_improvement_areas(
improvement_areas = []

# Check program length
if len(current_program) > 500:
# Support both old and new parameter names for backward compatibility
threshold = self.config.suggest_simplification_after_chars or self.config.code_length_threshold
if threshold and len(current_program) > threshold:
improvement_areas.append(
"Consider simplifying the code to improve readability and maintainability"
)
Expand Down Expand Up @@ -499,7 +501,7 @@ def _extract_unique_features(self, program: Dict[str, Any]) -> str:
metadata = program.get("metadata", {})
if "changes" in metadata:
changes = metadata["changes"]
if isinstance(changes, str) and len(changes) < 100:
if isinstance(changes, str) and self.config.include_changes_under_chars and len(changes) < self.config.include_changes_under_chars:
features.append(f"Modification: {changes}")

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

# Default if no specific features found
Expand Down