This repository contains an implementation of the AlphaEvolve algorithm.
Follow these instructions to set up the project locally.
- Python 3.12+
uvinstalled. You can install it with:pip install uv
-
Clone the repository:
git clone https://github.com/zwischenraum/open-alpha-evolve.git cd open-alpha-evolve -
Create a virtual environment and install dependencies: Use
uvto create a virtual environment and install the required packages.uv sync
-
Set up pre-commit hooks: This project uses
rufffor linting and formatting, managed bypre-commit. Installpre-commitand set up the hooks:pip install pre-commit pre-commit install
The hooks will now run automatically on every commit.
To run AlphaEvolve, you need to provide an initial program and an evaluation script.
python main.py <path_to_initial_program> <path_to_evaluation_script> --generations <num_generations><path_to_initial_program>: Path to the Python file containing the initial code to be evolved.<path_to_evaluation_script>: Path to the Python script that evaluates the fitness of a program.--generations(optional): The number of generations to run the evolution for (default is 5).
The repository includes a sample problem. You can run it with:
uv run main.py problem.py evaluate.pyTo use AlphaEvolve on your own problem, you need to create two files:
This is a Python file that contains the initial code you want to evolve. You must mark the section of the code that the LLM is allowed to modify using EVOLVE-BLOCK-START and EVOLVE-BLOCK-END comments.
Example: problem.py
"""
This is a simple problem for AlphaEvolve to solve.
"""
# EVOLVE-BLOCK-START
def get_magic_number():
"""This function should be evolved to return a number."""
return 0
# EVOLVE-BLOCK-ENDThis is a Python script that evaluates the fitness of a given program. It should contain a function called evaluate() that returns a dictionary of scores. The program being evaluated will be available to this script as a module named candidate.
Example: evaluate.py
This script tries to evolve the get_magic_number function to return the number 42.
from candidate import get_magic_number
def evaluate():
"""
Calculates the fitness of the candidate program.
The score is the negative absolute difference between the magic number and 42.
A score of 0 is a perfect score.
"""
score = -abs(42 - get_magic_number())
return {"average_score": score}The evaluation function can return multiple metrics to track different aspects of performance. Common metrics include:
- average_score: Overall performance metric
- runtime: Execution time in seconds
- memory_usage: Memory consumption in bytes
- error_rate: Percentage of failed operations
- latency: Response time for individual operations
- accuracy: Percentage of correct predictions or outputs