diff --git a/configs/default_config.yaml b/configs/default_config.yaml index ab54d6a5e..04181b056 100644 --- a/configs/default_config.yaml +++ b/configs/default_config.yaml @@ -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 diff --git a/openevolve/config.py b/openevolve/config.py index cc87455e6..1e81eb0ea 100644 --- a/openevolve/config.py +++ b/openevolve/config.py @@ -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: diff --git a/openevolve/prompt/sampler.py b/openevolve/prompt/sampler.py index 65f15b3ec..d4ec14adb 100644 --- a/openevolve/prompt/sampler.py +++ b/openevolve/prompt/sampler.py @@ -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" ) @@ -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 @@ -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