Skip to content

Commit 744cf34

Browse files
committed
add configs
1 parent 75b714c commit 744cf34

File tree

4 files changed

+304
-10
lines changed

4 files changed

+304
-10
lines changed

README.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,75 @@ from openevolve import OpenEvolve
4040

4141
# Initialize the system
4242
evolve = OpenEvolve(
43-
initial_program="path/to/initial_program.py",
44-
evaluation_function="path/to/evaluator.py",
45-
config="path/to/config.yaml"
43+
initial_program_path="path/to/initial_program.py",
44+
evaluation_file="path/to/evaluator.py",
45+
config_path="path/to/config.yaml"
4646
)
4747

4848
# Run the evolution
49-
best_program = evolve.run(iterations=1000)
50-
print(f"Best program found: {best_program.path}")
51-
print(f"Score: {best_program.score}")
49+
best_program = await evolve.run(iterations=1000)
50+
print(f"Best program metrics:")
51+
for name, value in best_program.metrics.items():
52+
print(f" {name}: {value:.4f}")
5253
```
5354

55+
### Command-Line Usage
56+
57+
OpenEvolve can also be run from the command line:
58+
59+
```bash
60+
python openevolve-run.py path/to/initial_program.py path/to/evaluator.py --config path/to/config.yaml --iterations 1000
61+
```
62+
63+
## Configuration
64+
65+
OpenEvolve is highly configurable. You can specify configuration options in a YAML file:
66+
67+
```yaml
68+
# Example configuration
69+
max_iterations: 1000
70+
llm:
71+
primary_model: "gemini-2.0-flash-lite"
72+
secondary_model: "gemini-2.0-flash"
73+
temperature: 0.7
74+
database:
75+
population_size: 500
76+
num_islands: 5
77+
```
78+
79+
Sample configuration files are available in the `configs/` directory:
80+
- `default_config.yaml`: Comprehensive configuration with all available options
81+
- `matrix_multiplication_config.yaml`: Configuration optimized for matrix multiplication
82+
- `min_max_distance_config.yaml`: Configuration for geometric optimization
83+
84+
See the [Configuration Guide](configs/default_config.yaml) for a full list of options.
85+
5486
## Examples
5587

5688
See the `examples/` directory for complete examples of using OpenEvolve on various problems:
57-
- Matrix multiplication optimization
58-
- Packing problems
59-
- Algorithmic discovery
60-
- Scheduling optimization
89+
90+
### Matrix Multiplication Optimization
91+
Evolves more efficient matrix multiplication algorithms:
92+
```bash
93+
cd examples/matrix_multiplication
94+
python optimize.py --iterations 100
95+
```
96+
97+
### Min-Max Distance Optimization
98+
Finds optimal point configurations that minimize the ratio of maximum to minimum distances:
99+
```bash
100+
cd examples/min_max_distance
101+
python optimize.py --iterations 150 --num-points 16
102+
```
103+
104+
## Preparing Your Own Problems
105+
106+
To use OpenEvolve for your own problems:
107+
108+
1. **Mark code sections** to evolve with `# EVOLVE-BLOCK-START` and `# EVOLVE-BLOCK-END` comments
109+
2. **Create an evaluation function** that returns a dictionary of metrics
110+
3. **Configure OpenEvolve** with appropriate parameters
111+
4. **Run the evolution** process
61112

62113
## Citation
63114

configs/default_config.yaml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# OpenEvolve Default Configuration
2+
# This file contains all available configuration options with sensible defaults
3+
# You can use this as a template for your own configuration
4+
5+
# General settings
6+
max_iterations: 1000 # Maximum number of evolution iterations
7+
checkpoint_interval: 50 # Save checkpoints every N iterations
8+
log_level: "INFO" # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
9+
log_dir: null # Custom directory for logs (default: output_dir/logs)
10+
random_seed: null # Random seed for reproducibility (null = random)
11+
12+
# Evolution settings
13+
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
15+
max_code_length: 10000 # Maximum allowed code length in characters
16+
17+
# LLM configuration
18+
llm:
19+
# Primary model (used most frequently)
20+
primary_model: "gemini-2.0-flash-lite"
21+
primary_model_weight: 0.8 # Sampling weight for primary model
22+
23+
# Secondary model (used for occasional high-quality generations)
24+
secondary_model: "gemini-2.0-flash"
25+
secondary_model_weight: 0.2 # Sampling weight for secondary model
26+
27+
# API configuration
28+
api_base: "https://api.openai.com/v1" # Base URL for API (change for non-OpenAI models)
29+
api_key: null # API key (defaults to OPENAI_API_KEY env variable)
30+
31+
# Generation parameters
32+
temperature: 0.7 # Temperature for generation (higher = more creative)
33+
top_p: 0.95 # Top-p sampling parameter
34+
max_tokens: 4096 # Maximum tokens to generate
35+
36+
# Request parameters
37+
timeout: 60 # Timeout for API requests in seconds
38+
retries: 3 # Number of retries for failed requests
39+
retry_delay: 5 # Delay between retries in seconds
40+
41+
# Prompt configuration
42+
prompt:
43+
template_dir: null # Custom directory for prompt templates
44+
system_message: "You are an expert coder helping to improve programs through evolution."
45+
46+
# Number of examples to include in the prompt
47+
num_top_programs: 3 # Number of top-performing programs to include
48+
num_diverse_programs: 2 # Number of diverse programs to include
49+
50+
# Template stochasticity
51+
use_template_stochasticity: true # Use random variations in templates for diversity
52+
template_variations: # Different phrasings for parts of the template
53+
improvement_suggestion:
54+
- "Here's how we could improve this code:"
55+
- "I suggest the following improvements:"
56+
- "We can enhance this code by:"
57+
58+
# Meta-prompting (experimental)
59+
use_meta_prompting: false # Use LLM to generate parts of the prompt
60+
meta_prompt_weight: 0.1 # Weight for meta-prompting influence
61+
62+
# Database configuration
63+
database:
64+
# General settings
65+
db_path: null # Path to persist database (null = in-memory only)
66+
in_memory: true # Keep database in memory for faster access
67+
68+
# Evolutionary parameters
69+
population_size: 1000 # Maximum number of programs to keep in memory
70+
archive_size: 100 # Size of elite archive
71+
num_islands: 5 # Number of islands for island model
72+
73+
# Selection parameters
74+
elite_selection_ratio: 0.1 # Ratio of elite programs to select
75+
exploration_ratio: 0.2 # Ratio of exploration vs exploitation
76+
exploitation_ratio: 0.7 # Ratio of exploitation vs random selection
77+
diversity_metric: "edit_distance" # Diversity metric (edit_distance, feature_based)
78+
79+
# Feature map dimensions for MAP-Elites
80+
feature_dimensions: # Dimensions for MAP-Elites feature map
81+
- "score" # Performance score
82+
- "complexity" # Code complexity (length)
83+
feature_bins: 10 # Number of bins per dimension
84+
85+
# Evaluator configuration
86+
evaluator:
87+
# General settings
88+
timeout: 300 # Maximum evaluation time in seconds
89+
max_retries: 3 # Maximum number of retries for evaluation
90+
91+
# Resource limits
92+
memory_limit_mb: null # Memory limit for evaluation (null = no limit)
93+
cpu_limit: null # CPU limit for evaluation (null = no limit)
94+
95+
# Evaluation strategies
96+
cascade_evaluation: true # Use cascade evaluation to filter bad solutions early
97+
cascade_thresholds: # Thresholds for advancing to next evaluation stage
98+
- 0.5 # First stage threshold
99+
- 0.75 # Second stage threshold
100+
- 0.9 # Third stage threshold
101+
102+
# Parallel evaluation
103+
parallel_evaluations: 4 # Number of parallel evaluations
104+
distributed: false # Use distributed evaluation
105+
106+
# LLM-based feedback (experimental)
107+
use_llm_feedback: false # Use LLM to evaluate code quality
108+
llm_feedback_weight: 0.1 # Weight for LLM feedback in final score
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Matrix Multiplication Optimization Configuration
2+
# This is a specific configuration for optimizing matrix multiplication algorithms
3+
4+
# General settings
5+
max_iterations: 100 # Number of iterations for this optimization task
6+
checkpoint_interval: 10 # Save checkpoints every 10 iterations
7+
log_level: "INFO" # Standard logging level
8+
random_seed: 42 # Fixed seed for reproducibility
9+
10+
# Evolution settings
11+
diff_based_evolution: true # Use targeted code modifications
12+
allow_full_rewrites: false # Don't allow full rewrites for this task
13+
max_code_length: 5000 # Limit code length to avoid excessive complexity
14+
15+
# LLM configuration
16+
llm:
17+
primary_model: "gemini-2.0-flash-lite" # Faster model for most generations
18+
primary_model_weight: 0.8
19+
secondary_model: "gemini-2.0-flash" # More powerful model for occasional insights
20+
secondary_model_weight: 0.2
21+
22+
# Higher temperature encourages more creative optimizations
23+
temperature: 0.8
24+
top_p: 0.95
25+
max_tokens: 4096
26+
27+
# Prompt configuration
28+
prompt:
29+
system_message: "You are an expert algorithmic optimization engineer specializing in numerical computing and matrix operations. Your task is to optimize matrix multiplication algorithms for better performance while maintaining correctness."
30+
31+
# Include more top programs to learn from previous successful optimizations
32+
num_top_programs: 4
33+
num_diverse_programs: 2
34+
35+
# Template variations specific to algorithm optimization
36+
template_variations:
37+
improvement_focus:
38+
- "Focus on loop ordering and memory access patterns."
39+
- "Consider algorithmic improvements like block-based multiplication."
40+
- "Think about SIMD and vectorization opportunities."
41+
- "Look for ways to reduce cache misses and improve locality."
42+
43+
# Database configuration
44+
database:
45+
# Smaller population for this focused task
46+
population_size: 200
47+
archive_size: 20
48+
num_islands: 3
49+
50+
# More exploitation since we're optimizing a well-known algorithm
51+
elite_selection_ratio: 0.2
52+
exploitation_ratio: 0.8
53+
exploration_ratio: 0.1
54+
55+
# Use performance and complexity as feature dimensions
56+
feature_dimensions:
57+
- "performance"
58+
- "complexity"
59+
60+
# Evaluator configuration
61+
evaluator:
62+
# Strict cascade evaluation for matrix multiplication
63+
cascade_evaluation: true
64+
cascade_thresholds:
65+
- 1.0 # First stage: must be 100% correct
66+
- 0.5 # Second stage: reasonable performance
67+
68+
# Parallel evaluation for faster iteration
69+
parallel_evaluations: 8
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Min-Max Distance Optimization Configuration
2+
# This is a specific configuration for the geometric optimization problem
3+
4+
# General settings
5+
max_iterations: 150 # More iterations for this harder problem
6+
checkpoint_interval: 15
7+
log_level: "INFO"
8+
random_seed: null # Use random seeds for more diversity
9+
10+
# Evolution settings
11+
diff_based_evolution: true
12+
allow_full_rewrites: true # Allow occasional full rewrites for this problem
13+
max_code_length: 3000
14+
15+
# LLM configuration
16+
llm:
17+
primary_model: "gemini-2.0-flash" # Use more powerful model as primary
18+
primary_model_weight: 0.7
19+
secondary_model: "gemini-2.0-pro" # Use most capable model occasionally
20+
secondary_model_weight: 0.3
21+
22+
# High temperature for creative geometric solutions
23+
temperature: 0.9
24+
top_p: 0.95
25+
max_tokens: 4096
26+
27+
# Prompt configuration
28+
prompt:
29+
system_message: "You are an expert in computational geometry and mathematical optimization. Your task is to design algorithms that find optimal point configurations with minimal ratio between maximum and minimum pairwise distances."
30+
31+
num_top_programs: 3
32+
num_diverse_programs: 3
33+
34+
template_variations:
35+
improvement_focus:
36+
- "Consider known geometric patterns like Fibonacci spirals or regular polygons."
37+
- "Think about symmetry and how it affects the distance ratio."
38+
- "Consider optimization techniques like simulated annealing or gradient descent."
39+
- "Explore perturbation methods that maintain approximately equal minimum distances."
40+
41+
# Database configuration
42+
database:
43+
# Large population for diverse geometric solutions
44+
population_size: 500
45+
archive_size: 50
46+
num_islands: 7
47+
48+
# Balance exploration and exploitation
49+
elite_selection_ratio: 0.15
50+
exploitation_ratio: 0.6
51+
exploration_ratio: 0.25
52+
53+
# Use score and stability as feature dimensions
54+
feature_dimensions:
55+
- "ratio_score"
56+
- "stability"
57+
58+
# Evaluator configuration
59+
evaluator:
60+
# Less strict cascade for this problem
61+
cascade_evaluation: true
62+
cascade_thresholds:
63+
- 0.3 # First stage: modest performance
64+
65+
# Multiple parallel evaluations for different random seeds
66+
parallel_evaluations: 6

0 commit comments

Comments
 (0)