|
| 1 | +# AlgoTune Task Adapter for OpenEvolve |
| 2 | + |
| 3 | +This directory contains tools to convert AlgoTune tasks to OpenEvolve format for evolutionary optimization. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `AlgoTuneTaskAdapter` extracts tasks from an external AlgoTune repository and converts them to OpenEvolve format, creating: |
| 8 | +- `initial_program.py` - The initial implementation to be evolved |
| 9 | +- `evaluator.py` - Evaluation logic with baseline comparison |
| 10 | +- `config.yaml` - OpenEvolve configuration |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +**AlgoTune Repository**: Clone the AlgoTune repository |
| 15 | + ```bash |
| 16 | + git clone https://github.com/oripress/AlgoTune.git |
| 17 | + ``` |
| 18 | + |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +### Basic Usage |
| 23 | + |
| 24 | +```python |
| 25 | +from task_adapter import AlgoTuneTaskAdapter |
| 26 | + |
| 27 | +# Initialize with AlgoTune repository path |
| 28 | +adapter = AlgoTuneTaskAdapter(algotune_path="/path/to/AlgoTune") |
| 29 | + |
| 30 | +# List available tasks |
| 31 | +tasks = adapter.list_available_tasks() |
| 32 | +print(f"Available tasks: {tasks}") |
| 33 | + |
| 34 | +# Create OpenEvolve files for a specific task |
| 35 | +output_dir = adapter.create_task_files("svm") |
| 36 | +print(f"Created files in: {output_dir}") |
| 37 | +``` |
| 38 | + |
| 39 | +### Command Line Usage |
| 40 | + |
| 41 | +#### List Available Tasks |
| 42 | +```bash |
| 43 | +python generate_all_tasks.py --algotune-path /path/to/AlgoTune --list |
| 44 | +``` |
| 45 | + |
| 46 | +#### Generate Files for a Specific Task |
| 47 | +```bash |
| 48 | +python create_task.py --algotune-path /path/to/AlgoTune --task svm |
| 49 | +``` |
| 50 | + |
| 51 | +#### Generate All Tasks |
| 52 | +```bash |
| 53 | +python generate_all_tasks.py --algotune-path /path/to/AlgoTune |
| 54 | +``` |
| 55 | + |
| 56 | +## File Structure |
| 57 | + |
| 58 | +For each task, the adapter creates: |
| 59 | + |
| 60 | +``` |
| 61 | +task_name/ |
| 62 | +├── initial_program.py # Initial implementation to evolve |
| 63 | +├── evaluator.py # Evaluation logic with baseline comparison |
| 64 | +└── config.yaml # OpenEvolve configuration |
| 65 | +``` |
| 66 | + |
| 67 | +## Configuration |
| 68 | + |
| 69 | +The adapter automatically generates OpenEvolve configurations with: |
| 70 | +- Baseline comparison against original AlgoTune implementations |
| 71 | +- Speedup-based fitness scoring |
| 72 | +- Cascade evaluation for efficiency |
| 73 | +- Task-specific problem generation |
| 74 | + |
| 75 | +## Evaluation Features |
| 76 | + |
| 77 | +The generated evaluators include: |
| 78 | +- **Baseline Comparison**: Compares evolved solutions against original AlgoTune implementations |
| 79 | +- **Speedup Measurement**: Calculates performance improvements |
| 80 | +- **Correctness Validation**: Ensures solutions are valid |
| 81 | + |
| 82 | +## Example: SVM Task |
| 83 | + |
| 84 | +Here's an example of how the adapter transforms an AlgoTune SVM task: |
| 85 | + |
| 86 | +### Generated Initial Program (`initial_program.py`) |
| 87 | + |
| 88 | +```python |
| 89 | +# EVOLVE-BLOCK-START |
| 90 | +""" |
| 91 | +SVM Task |
| 92 | +Given labels y ∈ {-1, 1}^n and a feature matrix X ∈ R^{n x p} with rows x_1,...,x_n, |
| 93 | +solve the support vector machine (SVM) task |
| 94 | +
|
| 95 | +min 1/2 || β ||_2^2 + C sum_{i=1}^n ξ_i |
| 96 | +β,β_0,ξ |
| 97 | +
|
| 98 | +subject to ξ_i ≥ 0, i = 1,...,n |
| 99 | + y_i (x_i^T β + β_0) ≥ 1 - ξ_i, i = 1,...,n |
| 100 | +
|
| 101 | +Input: Dictionary with keys "X", "y", "C" |
| 102 | +Output: Dictionary with keys "beta0", "beta", "optimal_value", "misclass_error" |
| 103 | +""" |
| 104 | +import cvxpy as cp |
| 105 | +import numpy as np |
| 106 | + |
| 107 | +class SVMTask: |
| 108 | + def solve(self, problem): |
| 109 | + """Solve the SVM problem using CVXPY.""" |
| 110 | + X = np.array(problem["X"]) |
| 111 | + y = np.array(problem["y"])[:, None] |
| 112 | + C = float(problem["C"]) |
| 113 | + |
| 114 | + p, n = X.shape[1], X.shape[0] |
| 115 | + beta = cp.Variable((p, 1)) |
| 116 | + beta0 = cp.Variable() |
| 117 | + xi = cp.Variable((n, 1)) |
| 118 | + |
| 119 | + objective = cp.Minimize(0.5 * cp.sum_squares(beta) + C * cp.sum(xi)) |
| 120 | + constraints = [ |
| 121 | + xi >= 0, |
| 122 | + cp.multiply(y, X @ beta + beta0) >= 1 - xi, |
| 123 | + ] |
| 124 | + |
| 125 | + problem_cp = cp.Problem(objective, constraints) |
| 126 | + problem_cp.solve() |
| 127 | + |
| 128 | + return { |
| 129 | + "beta0": float(beta0.value), |
| 130 | + "beta": beta.value.flatten().tolist(), |
| 131 | + "optimal_value": float(problem_cp.value), |
| 132 | + "misclass_error": self._compute_misclassification_error(X, y, beta.value, beta0.value) |
| 133 | + } |
| 134 | +# EVOLVE-BLOCK-END |
| 135 | +``` |
| 136 | + |
| 137 | +### Generated Configuration (`config.yaml`) |
| 138 | + |
| 139 | +```yaml |
| 140 | +# Configuration for svm task |
| 141 | +max_iterations: 100 |
| 142 | +checkpoint_interval: 10 |
| 143 | + |
| 144 | +# LLM configuration |
| 145 | +llm: |
| 146 | + primary_model: "gpt-4o-mini" |
| 147 | + temperature: 0.7 |
| 148 | + max_tokens: 4096 |
| 149 | + |
| 150 | +# Prompt configuration |
| 151 | +prompt: |
| 152 | + system_message: "You are an expert programmer specializing in convex_optimization algorithms. Your task is to improve the svm algorithm implementation..." |
| 153 | + |
| 154 | +# AlgoTune task-specific configuration |
| 155 | +algotune: |
| 156 | + num_trials: 5 |
| 157 | + data_size: 5 |
| 158 | + timeout: 30 |
| 159 | +``` |
| 160 | +
|
| 161 | +### Generated Evaluator (`evaluator.py`) |
| 162 | + |
| 163 | +The evaluator: |
| 164 | +- Loads the evolved solve method from `initial_program.py` |
| 165 | +- Generates test problems using the original AlgoTune task |
| 166 | +- Runs the evolved solution and measures performance |
| 167 | +- Validates correctness using the original task's validation method |
| 168 | +- Compares against reference solutions from AlgoTune |
| 169 | + |
| 170 | +## Files |
| 171 | + |
| 172 | +- `task_adapter.py` - Main adapter that converts AlgoTune tasks to OpenEvolve format |
| 173 | +- `create_task.py` - Script to create OpenEvolve files for a single task |
| 174 | +- `generate_all_tasks.py` - Script to generate all 155 AlgoTune tasks |
| 175 | + |
| 176 | +## Integration with OpenEvolve |
| 177 | + |
| 178 | +Once files are generated, you can run OpenEvolve: |
| 179 | + |
| 180 | +```bash |
| 181 | +# Navigate to the task directory |
| 182 | +cd svm/ |
| 183 | +
|
| 184 | +# Run OpenEvolve on the task |
| 185 | + python ../../../openevolve-run.py ./initial_program.py ./evaluator.py \ |
| 186 | + --config ./config.yaml \ |
| 187 | + --output openevolve_output/ |
| 188 | +``` |
0 commit comments