Skip to content

Commit cfb3022

Browse files
committed
Refactor evolution config to remove allow_full_rewrites
Removed the allow_full_rewrites option from configuration and codebase, consolidating evolution mode selection under diff_based_evolution. Updated prompt sampling and controller logic to use diff_based_evolution exclusively, and adjusted example configs accordingly. Added a proposed validation snippet to prevent incompatible evolution settings.
1 parent 33d1797 commit cfb3022

File tree

6 files changed

+74
-17
lines changed

6 files changed

+74
-17
lines changed

configs/default_config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ random_seed: null # Random seed for reproducibility (null =
1111

1212
# Evolution settings
1313
diff_based_evolution: true # Use diff-based evolution (true) or full rewrites (false)
14-
allow_full_rewrites: false # Allow occasional full rewrites even in diff-based mode
1514
max_code_length: 10000 # Maximum allowed code length in characters
1615

1716
# LLM configuration
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
PROPOSED FIX for OpenEvolve Configuration Bug
3+
4+
Issue: diff_based_evolution=True and allow_full_rewrites=True are incompatible
5+
but no validation prevents this configuration from being used.
6+
7+
PROBLEM:
8+
- Prompt sampler uses allow_full_rewrites to choose template
9+
- Controller uses diff_based_evolution to choose parser
10+
- These can create contradictory behavior
11+
12+
SOLUTION:
13+
Add validation to Config class __post_init__ method
14+
"""
15+
16+
# Add this to openevolve/config.py in the Config class __post_init__ method:
17+
18+
def __post_init__(self):
19+
"""Post-initialization validation"""
20+
21+
# Validate evolution settings compatibility
22+
if self.diff_based_evolution and self.allow_full_rewrites:
23+
raise ValueError(
24+
"Configuration Error: diff_based_evolution=True and allow_full_rewrites=True "
25+
"are incompatible. Use one of these combinations:\n"
26+
" - diff_based_evolution=True, allow_full_rewrites=False (diff-based evolution)\n"
27+
" - diff_based_evolution=False, allow_full_rewrites=True (rewrite-based evolution)\n"
28+
" - diff_based_evolution=False, allow_full_rewrites=False (rewrite with diff template)"
29+
)
30+
31+
# Other existing validations...
32+
33+
34+
# Alternative: Add a helper method to validate and suggest fixes:
35+
36+
def validate_evolution_settings(self) -> None:
37+
"""Validate evolution configuration and provide helpful error messages"""
38+
39+
if self.diff_based_evolution and self.allow_full_rewrites:
40+
suggested_configs = [
41+
"# Option 1: Pure diff-based evolution (recommended for iterative improvements)",
42+
"diff_based_evolution: true",
43+
"allow_full_rewrites: false",
44+
"",
45+
"# Option 2: Pure rewrite-based evolution (recommended for major changes)",
46+
"diff_based_evolution: false",
47+
"allow_full_rewrites: true"
48+
]
49+
50+
raise ValueError(
51+
f"❌ Configuration Error: Incompatible evolution settings detected!\n\n"
52+
f"Current settings:\n"
53+
f" diff_based_evolution: {self.diff_based_evolution}\n"
54+
f" allow_full_rewrites: {self.allow_full_rewrites}\n\n"
55+
f"🔧 Suggested fixes:\n" + "\n".join(suggested_configs) + "\n\n"
56+
f"💡 Explanation:\n"
57+
f" - diff_based_evolution=True makes the controller parse responses as diff blocks\n"
58+
f" - allow_full_rewrites=True makes the prompt ask for complete code rewrites\n"
59+
f" - These create a contradiction: LLM returns complete code but controller expects diffs\n"
60+
)

examples/signal_processing/config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Configuration for Real-Time Adaptive Signal Processing Example
2-
max_iterations: 200
3-
checkpoint_interval: 25
2+
max_iterations: 100
3+
checkpoint_interval: 10
44
log_level: "INFO"
55

66
# LLM configuration
77
llm:
8-
primary_model: "gemini-2.0-flash-lite"
8+
primary_model: "gemini-2.5-flash-lite-preview-06-17"
99
primary_model_weight: 0.8
1010
secondary_model: "gemini-2.5-flash"
1111
secondary_model_weight: 0.2
1212
api_base: "https://generativelanguage.googleapis.com/v1beta/openai/"
13-
temperature: 0.7
13+
temperature: 0.6
1414
top_p: 0.95
15-
max_tokens: 4096
15+
max_tokens: 32000
1616

1717
# Prompt configuration
1818
prompt:
@@ -38,4 +38,4 @@ evaluator:
3838

3939
# Evolution settings
4040
diff_based_evolution: true
41-
allow_full_rewrites: true
41+
max_code_length: 60000

openevolve/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ class Config:
222222

223223
# Evolution settings
224224
diff_based_evolution: bool = True
225-
allow_full_rewrites: bool = False
226225
max_code_length: int = 10000
227226

228227
@classmethod
@@ -329,7 +328,6 @@ def to_dict(self) -> Dict[str, Any]:
329328
},
330329
# Evolution settings
331330
"diff_based_evolution": self.diff_based_evolution,
332-
"allow_full_rewrites": self.allow_full_rewrites,
333331
"max_code_length": self.max_code_length,
334332
}
335333

openevolve/controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ async def run(
272272
top_programs=[p.to_dict() for p in inspirations],
273273
language=self.language,
274274
evolution_round=i,
275-
allow_full_rewrite=self.config.allow_full_rewrites,
275+
diff_based_evolution=self.config.diff_based_evolution,
276276
program_artifacts=parent_artifacts if parent_artifacts else None,
277277
)
278278

@@ -340,7 +340,7 @@ async def run(
340340
# Log prompts
341341
self.database.log_prompt(
342342
template_key=(
343-
"full_rewrite_user" if self.config.allow_full_rewrites else "diff_user"
343+
"full_rewrite_user" if not self.config.diff_based_evolution else "diff_user"
344344
),
345345
program_id=child_id,
346346
prompt=prompt,
@@ -354,7 +354,7 @@ async def run(
354354
# Log prompts
355355
self.database.log_prompt(
356356
template_key=(
357-
"full_rewrite_user" if self.config.allow_full_rewrites else "diff_user"
357+
"full_rewrite_user" if not self.config.diff_based_evolution else "diff_user"
358358
),
359359
program_id=child_id,
360360
prompt=prompt,

openevolve/prompt/sampler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def build_prompt(
5353
top_programs: List[Dict[str, Any]] = [],
5454
language: str = "python",
5555
evolution_round: int = 0,
56-
allow_full_rewrite: bool = False,
56+
diff_based_evolution: bool = True,
5757
template_key: Optional[str] = None,
5858
program_artifacts: Optional[Dict[str, Union[str, bytes]]] = None,
5959
**kwargs: Any,
@@ -69,24 +69,24 @@ def build_prompt(
6969
top_programs: List of top-performing programs
7070
language: Programming language
7171
evolution_round: Current evolution round
72-
allow_full_rewrite: Whether to allow a full rewrite
72+
diff_based_evolution: Whether to use diff-based evolution (True) or full rewrites (False)
7373
template_key: Optional override for template key
7474
program_artifacts: Optional artifacts from program evaluation
7575
**kwargs: Additional keys to replace in the user prompt
7676
7777
Returns:
7878
Dictionary with 'system' and 'user' keys
7979
"""
80-
# Select template based on whether we want a full rewrite (with overrides)
80+
# Select template based on evolution mode (with overrides)
8181
if template_key:
8282
# Use explicitly provided template key
8383
user_template_key = template_key
8484
elif self.user_template_override:
8585
# Use the override set with set_templates
8686
user_template_key = self.user_template_override
8787
else:
88-
# Default behavior
89-
user_template_key = "full_rewrite_user" if allow_full_rewrite else "diff_user"
88+
# Default behavior: diff-based vs full rewrite
89+
user_template_key = "diff_user" if diff_based_evolution else "full_rewrite_user"
9090

9191
# Get the template
9292
user_template = self.template_manager.get_template(user_template_key)

0 commit comments

Comments
 (0)