From 9704f2ffc4d3b834c2f786156a7069a1a103c0dc Mon Sep 17 00:00:00 2001 From: Tony Beta Lambda Date: Mon, 28 Jul 2025 18:40:28 +0800 Subject: [PATCH 1/2] Add configurable program length check --- openevolve/config.py | 3 +++ openevolve/prompt/sampler.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/openevolve/config.py b/openevolve/config.py index cc87455e6..9fa2d8c05 100644 --- a/openevolve/config.py +++ b/openevolve/config.py @@ -142,6 +142,9 @@ class PromptConfig: max_artifact_bytes: int = 20 * 1024 # 20KB in prompt artifact_security_filter: bool = True + # Improvement areas + code_length_threshold: Optional[int] = 500 + @dataclass class DatabaseConfig: diff --git a/openevolve/prompt/sampler.py b/openevolve/prompt/sampler.py index 65f15b3ec..51988fe62 100644 --- a/openevolve/prompt/sampler.py +++ b/openevolve/prompt/sampler.py @@ -171,7 +171,7 @@ def _identify_improvement_areas( improvement_areas = [] # Check program length - if len(current_program) > 500: + if self.config.code_length_threshold and len(current_program) > self.config.code_length_threshold: improvement_areas.append( "Consider simplifying the code to improve readability and maintainability" ) From c4c842cb58b287ce53fd7c14e701fa9b75dcd2a9 Mon Sep 17 00:00:00 2001 From: Asankhaya Sharma Date: Tue, 29 Jul 2025 10:17:39 +0800 Subject: [PATCH 2/2] 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. --- configs/default_config.yaml | 7 +++++++ openevolve/config.py | 10 ++++++++-- openevolve/prompt/sampler.py | 10 ++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) 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 9fa2d8c05..1e81eb0ea 100644 --- a/openevolve/config.py +++ b/openevolve/config.py @@ -142,8 +142,14 @@ class PromptConfig: max_artifact_bytes: int = 20 * 1024 # 20KB in prompt artifact_security_filter: bool = True - # Improvement areas - code_length_threshold: Optional[int] = 500 + # 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 diff --git a/openevolve/prompt/sampler.py b/openevolve/prompt/sampler.py index 51988fe62..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 self.config.code_length_threshold and len(current_program) > self.config.code_length_threshold: + # 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