Skip to content

Commit 0f1f898

Browse files
committed
fix islands map elite
- add example configs
1 parent 96e6187 commit 0f1f898

File tree

7 files changed

+1037
-607
lines changed

7 files changed

+1037
-607
lines changed

configs/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# OpenEvolve Configuration Files
2+
3+
This directory contains configuration files for OpenEvolve with examples for different use cases.
4+
5+
## Configuration Files
6+
7+
### `default_config.yaml`
8+
The main configuration file containing all available options with sensible defaults. This file includes:
9+
- Complete documentation for all configuration parameters
10+
- Default values for all settings
11+
- **Island-based evolution parameters** for proper evolutionary diversity
12+
13+
Use this file as a template for your own configurations.
14+
15+
### `island_config_example.yaml`
16+
A practical example configuration demonstrating proper island-based evolution setup. Shows:
17+
- Recommended island settings for most use cases
18+
- Balanced migration parameters
19+
- Complete working configuration
20+
21+
### `island_examples.yaml`
22+
Multiple example configurations for different scenarios:
23+
- **Maximum Diversity**: Many islands, frequent migration
24+
- **Focused Exploration**: Few islands, rare migration
25+
- **Balanced Approach**: Default recommended settings
26+
- **Quick Exploration**: Small-scale rapid testing
27+
- **Large-Scale Evolution**: Complex optimization runs
28+
29+
Includes guidelines for choosing parameters based on your problem characteristics.
30+
31+
## Island-Based Evolution Parameters
32+
33+
The key new parameters for proper evolutionary diversity are:
34+
35+
```yaml
36+
database:
37+
num_islands: 5 # Number of separate populations
38+
migration_interval: 50 # Migrate every N generations
39+
migration_rate: 0.1 # Fraction of top programs to migrate
40+
```
41+
42+
### Parameter Guidelines
43+
44+
- **num_islands**: 3-10 for most problems (more = more diversity)
45+
- **migration_interval**: 25-100 generations (higher = more independence)
46+
- **migration_rate**: 0.05-0.2 (5%-20%, higher = faster knowledge sharing)
47+
48+
### When to Use What
49+
50+
- **Complex problems** → More islands, less frequent migration
51+
- **Simple problems** → Fewer islands, more frequent migration
52+
- **Long runs** → More islands to maintain diversity
53+
- **Short runs** → Fewer islands for faster convergence
54+
55+
## Usage
56+
57+
Copy any of these files as a starting point for your configuration:
58+
59+
```bash
60+
cp configs/default_config.yaml my_config.yaml
61+
# Edit my_config.yaml for your specific needs
62+
```
63+
64+
Then use with OpenEvolve:
65+
66+
```python
67+
from openevolve import OpenEvolve
68+
evolve = OpenEvolve(
69+
initial_program_path="program.py",
70+
evaluation_file="evaluator.py",
71+
config_path="my_config.yaml"
72+
)
73+
```

configs/default_config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ database:
6868
# Evolutionary parameters
6969
population_size: 1000 # Maximum number of programs to keep in memory
7070
archive_size: 100 # Size of elite archive
71-
num_islands: 5 # Number of islands for island model
71+
num_islands: 5 # Number of islands for island model (separate populations)
72+
73+
# Island-based evolution parameters
74+
# Islands provide diversity by maintaining separate populations that evolve independently.
75+
# Migration periodically shares the best solutions between adjacent islands.
76+
migration_interval: 50 # Migrate between islands every N generations
77+
migration_rate: 0.1 # Fraction of top programs to migrate (0.1 = 10%)
7278

7379
# Selection parameters
7480
elite_selection_ratio: 0.1 # Ratio of elite programs to select

configs/island_config_example.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# OpenEvolve Island-Based Evolution Configuration
2+
# This configuration demonstrates the proper use of island-based evolution
3+
4+
# General settings
5+
max_iterations: 1000
6+
checkpoint_interval: 100
7+
log_level: "INFO"
8+
9+
# LLM configuration
10+
llm:
11+
primary_model: "gemini-2.0-flash-lite"
12+
primary_model_weight: 0.8
13+
secondary_model: "gemini-2.0-flash"
14+
secondary_model_weight: 0.2
15+
temperature: 0.7
16+
top_p: 0.95
17+
max_tokens: 4096
18+
19+
# Database configuration with proper island settings
20+
database:
21+
population_size: 500
22+
archive_size: 100
23+
24+
# Island-based evolution settings
25+
num_islands: 5 # Number of separate populations
26+
migration_interval: 50 # Migrate every 50 generations
27+
migration_rate: 0.1 # Migrate 10% of top programs
28+
29+
# Selection parameters
30+
elite_selection_ratio: 0.1
31+
exploration_ratio: 0.3
32+
exploitation_ratio: 0.7
33+
34+
# Feature map dimensions for MAP-Elites
35+
feature_dimensions: ["score", "complexity"]
36+
feature_bins: 10
37+
38+
# Prompt configuration
39+
prompt:
40+
num_top_programs: 3
41+
num_diverse_programs: 2
42+
use_template_stochasticity: true
43+
44+
# Evaluator configuration
45+
evaluator:
46+
timeout: 300
47+
max_retries: 3
48+
cascade_evaluation: true
49+
parallel_evaluations: 4
50+
51+
# Evolution settings
52+
diff_based_evolution: true
53+
allow_full_rewrites: false
54+
max_code_length: 10000

configs/island_examples.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# OpenEvolve Island-Based Evolution Configuration Examples
2+
# Different configurations for various use cases
3+
4+
# Configuration for Maximum Diversity (Many Islands, Frequent Migration)
5+
# Use this when you want to explore the search space thoroughly
6+
# Good for: Complex problems, avoiding local optima, long runs
7+
max_diversity:
8+
database:
9+
num_islands: 10 # More islands = more diversity
10+
migration_interval: 25 # More frequent migration
11+
migration_rate: 0.2 # Higher migration rate
12+
population_size: 1000
13+
archive_size: 200
14+
15+
# Configuration for Focused Exploration (Few Islands, Rare Migration)
16+
# Use this when you want deeper exploration within each island
17+
# Good for: Problems with clear structure, shorter runs
18+
focused_exploration:
19+
database:
20+
num_islands: 3 # Fewer islands = deeper exploration
21+
migration_interval: 100 # Less frequent migration
22+
migration_rate: 0.05 # Lower migration rate
23+
population_size: 500
24+
archive_size: 50
25+
26+
# Configuration for Balanced Approach (Default Settings)
27+
# Use this as a starting point for most problems
28+
# Good for: General use, medium-length runs
29+
balanced:
30+
database:
31+
num_islands: 5 # Balanced number of islands
32+
migration_interval: 50 # Moderate migration frequency
33+
migration_rate: 0.1 # Moderate migration rate
34+
population_size: 1000
35+
archive_size: 100
36+
37+
# Configuration for Quick Exploration (Small Scale)
38+
# Use this for rapid prototyping and testing
39+
# Good for: Small problems, quick experiments
40+
quick_exploration:
41+
database:
42+
num_islands: 3
43+
migration_interval: 20
44+
migration_rate: 0.15
45+
population_size: 200
46+
archive_size: 30
47+
48+
# Configuration for Large-Scale Evolution (High Performance)
49+
# Use this for complex problems requiring extensive search
50+
# Good for: Complex optimization, long evolutionary runs
51+
large_scale:
52+
database:
53+
num_islands: 15 # Many islands for parallel exploration
54+
migration_interval: 75 # Balanced migration timing
55+
migration_rate: 0.08 # Conservative migration rate
56+
population_size: 2000 # Large populations
57+
archive_size: 300
58+
59+
# Guidelines for choosing parameters:
60+
#
61+
# num_islands:
62+
# - More islands = more diversity, slower convergence
63+
# - Fewer islands = faster convergence, risk of premature convergence
64+
# - Recommended: 3-10 for most problems
65+
#
66+
# migration_interval:
67+
# - Lower values = more frequent knowledge sharing
68+
# - Higher values = more independent evolution
69+
# - Recommended: 25-100 generations
70+
#
71+
# migration_rate:
72+
# - Higher values = faster knowledge propagation
73+
# - Lower values = preserve island diversity longer
74+
# - Recommended: 0.05-0.2 (5%-20%)
75+
#
76+
# Rule of thumb:
77+
# - Complex problems → More islands, less frequent migration
78+
# - Simple problems → Fewer islands, more frequent migration
79+
# - Long runs → More islands to maintain diversity
80+
# - Short runs → Fewer islands for faster convergence

openevolve/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class DatabaseConfig:
7979
# Feature map dimensions for MAP-Elites
8080
feature_dimensions: List[str] = field(default_factory=lambda: ["score", "complexity"])
8181
feature_bins: int = 10
82+
83+
# Migration parameters for island-based evolution
84+
migration_interval: int = 50 # Migrate every N generations
85+
migration_rate: float = 0.1 # Fraction of population to migrate
8286

8387

8488
@dataclass
@@ -203,6 +207,8 @@ def to_dict(self) -> Dict[str, Any]:
203207
"diversity_metric": self.database.diversity_metric,
204208
"feature_dimensions": self.database.feature_dimensions,
205209
"feature_bins": self.database.feature_bins,
210+
"migration_interval": self.database.migration_interval,
211+
"migration_rate": self.database.migration_rate,
206212
},
207213
"evaluator": {
208214
"timeout": self.evaluator.timeout,

openevolve/controller.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,26 @@ async def run(
178178
logger.info(
179179
f"Starting evolution from iteration {start_iteration} for {max_iterations} iterations (total: {total_iterations})"
180180
)
181+
182+
# Island-based evolution variables
183+
programs_per_island = max(1, max_iterations // (self.config.database.num_islands * 10)) # Dynamic allocation
184+
current_island_counter = 0
185+
186+
logger.info(f"Using island-based evolution with {self.config.database.num_islands} islands")
187+
self.database.log_island_status()
181188

182189
for i in range(start_iteration, total_iterations):
183190
iteration_start = time.time()
184-
185-
# Sample parent and inspirations
191+
192+
# Manage island evolution - switch islands periodically
193+
if i > start_iteration and current_island_counter >= programs_per_island:
194+
self.database.next_island()
195+
current_island_counter = 0
196+
logger.debug(f"Switched to island {self.database.current_island}")
197+
198+
current_island_counter += 1
199+
200+
# Sample parent and inspirations from current island
186201
parent, inspirations = self.database.sample()
187202

188203
# Build prompt
@@ -252,8 +267,17 @@ async def run(
252267
},
253268
)
254269

255-
# Add to database
270+
# Add to database (will be added to current island)
256271
self.database.add(child_program, iteration=i + 1)
272+
273+
# Increment generation for current island
274+
self.database.increment_island_generation()
275+
276+
# Check if migration should occur
277+
if self.database.should_migrate():
278+
logger.info(f"Performing migration at iteration {i+1}")
279+
self.database.migrate_programs()
280+
self.database.log_island_status()
257281

258282
# Log progress
259283
iteration_time = time.time() - iteration_start
@@ -271,6 +295,9 @@ async def run(
271295
# Save checkpoint
272296
if (i + 1) % self.config.checkpoint_interval == 0:
273297
self._save_checkpoint(i + 1)
298+
# Also log island status at checkpoints
299+
logger.info(f"Island status at checkpoint {i+1}:")
300+
self.database.log_island_status()
274301

275302
# Check if target score reached
276303
if target_score is not None:

0 commit comments

Comments
 (0)