|
| 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 | + ) |
0 commit comments