OpenEvolve Documentation

repository·main·Indexed 27 days ago

https://github.com/algorithmicsuperintelligence/openevolve

Open-source implementation of AlphaEvolve, an evolutionary coding agent that transforms LLMs into autonomous code optimizers. It uses quality-diversity evolution and MAP-Elites to discover breakthrough algorithms. Features include island-based evolution, support for OpenAI-compatible APIs (including Gemini, Ollama, and vLLM), a CLI for running evolution processes, and an interactive web interface for visualizing evolution trees and performance tracking.

Tokens
10.3K
Snippets
14
Records
59
Agent score
92%

What's inside OpenEvolve

  1. Install OpenEvolve

    main

    You can install OpenEvolve via PyPI for standard use, or via a development install if you are contributing to the repository. For containerized environments, use the official Docker image.

    # PyPI (Recommended)
    pip install openevolve
    
    # Development Install
    git clone https://github.com/algorithmicsuperintelligence/openevolve.git
    cd openevolve
    pip install -e ".[dev]"
    
    # Docker
    docker pull ghcr.io/algorithmicsuperintelligence/openevolve:latest
  2. Configure OpenEvolve using YAML files

    main

    OpenEvolve uses YAML configuration files to define evolution parameters. You can use configs/default_config.yaml as a template, as it contains all available options, default values, and documentation for all parameters.

    To set up your own configuration, copy the default template and modify it to suit your needs:

    cp configs/default_config.yaml my_config.yaml
    # Edit my_config.yaml for your specific needs
    cp configs/default_config.yaml my_config.yaml
  3. Visualize evolution with the interactive web interface

    main

    OpenEvolve provides a real-time evolution tracking tool. You must first install the visualization dependencies, then you can launch the interactive visualizer or point it to a specific checkpoint directory to view the evolution tree, performance tracking, code diffs, and MAP-Elites grids.

    # Install visualization dependencies
    pip install -r scripts/requirements.txt
    
    # Launch interactive visualizer
    python scripts/visualizer.py
    
    # Or visualize specific checkpoint
    python scripts/visualizer.py --path examples/function_minimization/openevolve_output/checkpoints/checkpoint_100/
  4. Craft Effective System Messages for Evolution

    main

    The system_message in your config.yaml is the most critical component for successful evolution. It guides the LLM's domain expertise, constraint awareness, and optimization focus.

    Recommended Structure:

    1. Role Definition: (e.g., "You are an expert Metal GPU programmer")
    2. Task/Context: Define the specific goal and hardware/environment.
    3. Optimization Opportunities: List specific areas for improvement (e.g., memory access, algorithm fusion).
    4. Constraints: Use explicit markers like MUST NOT CHANGE: ❌ and ALLOWED TO OPTIMIZE: ✅ to prevent breaking code signatures or correctness.
    5. Success Criteria: Define what a successful mutation looks like.

    Best Practices:

    • Avoid Vague Instructions: Instead of "Make the code faster", use "Focus on reducing memory allocations. Example: Replace new Vector() with pre-allocated arrays."
    • Include Domain Knowledge: For hardware tasks, mention specific concepts like "Memory coalescing" or "SIMD utilization".
    • Iterative Refinement: Start with a basic draft, observe behavior over 20-50 iterations, and refine based on where the LLM gets stuck.
  5. Configure LLM providers in OpenEvolve

    main

    OpenEvolve supports any OpenAI-compatible API. You can configure the api_base and model in your config.yaml.

    Google Gemini

    To use Gemini, set the api_base to the Google OpenAI-compatible endpoint and export your key as OPENAI_API_KEY.

    Local Models (Ollama/vLLM)

    Point the api_base to your local server address.

    OptiLLM

    For advanced routing and test-time compute, run the OptiLLM proxy and point OpenEvolve to its local port.

    # Example Gemini configuration
    llm:
      api_base: "https://generativelanguage.googleapis.com/v1beta/openai/"
      model: "gemini-2.5-pro"
    
    # Example Local Model (Ollama)
    llm:
      api_base: "http://localhost:11434/v1"
      model: "codellama:7b"
    
    # Example OptiLLM
    llm:
      api_base: "http://localhost:8000/v1"
      model: "moa&readurls-o3"
  6. Use a custom OpenAI-compatible LLM

    main
    OpenEvolve supports any OpenAI-compatible API, including commercial providers (OpenAI, Google, Cohere) and local providers (Ollama, vLLM, LM Studio, text-generation-webui). To use a custom endpoint, set the api_base key in your configuration file to point to your provider's URL.
  7. Configure Feature Engineering for Quality-Diversity

    main

    You can control how programs are organized in the quality-diversity grid by defining feature_dimensions and feature_bins under the database section.

    Supported built-in dimensions:

    • complexity: Based on code length.
    • diversity: Based on structural diversity.
    • performance: Custom dimension derived from your evaluator.

    Note: Your evaluator must return raw values; OpenEvolve handles the binning into categories automatically.

    database:
      feature_dimensions: 
        - "complexity"
        - "diversity"
        - "performance"
        - "memory_usage"
        
      feature_bins:
        complexity: 10
        performance: 20
        memory_usage: 15
  8. Configure OpenEvolve via YAML

    main

    OpenEvolve uses a YAML configuration file to manage evolution parameters, LLM settings, database/population management, and evaluator behavior.

    Key configuration sections include:

    • llm: Define model ensembles (e.g., gemini-2.5-pro, gemini-2.5-flash) with weights and temperature.
    • database: Configure MAP-Elites quality-diversity settings like population_size, num_islands (for parallel evolution), and feature_dimensions.
    • evaluator: Enable enable_artifacts for error feedback, cascade_evaluation for multi-stage testing, and use_llm_feedback for AI-driven code assessment.
    • prompt: Manage the inspiration system (num_top_programs, num_diverse_programs) and custom templates.

    Environment Variables:

    • GEMINI_API_KEY: Required for Gemini embeddings.
    • GOOGLE_API_KEY: Supported as a fallback for Gemini services.
    max_iterations: 1000
    random_seed: 42
    
    llm:
      models:
        - name: "gemini-2.5-pro"
          weight: 0.6
        - name: "gemini-2.5-flash"
          weight: 0.4
      temperature: 0.7
    
    database:
      population_size: 500
      num_islands: 5
      migration_interval: 20
      feature_dimensions: ["complexity", "diversity", "performance"]
      embedding_model: "gemini-embedding-001"
      similarity_threshold: 0.99
    
    evaluator:
      enable_artifacts: true
      cascade_evaluation: true
      use_llm_feedback: true
    
    prompt:
      num_top_programs: 3
      num_diverse_programs: 2
      include_artifacts: true
      template_dir: "custom_prompts/"
      use_template_stochasticity: true
  9. Use Custom Prompt Templates with Stochasticity

    main

    To increase diversity in prompts, you can use custom templates with placeholders. Placeholders like {greeting} or {improvement_suggestion} are replaced by random variations defined in your configuration.

    Set use_template_stochasticity: true and provide a template_dir to enable this feature.

    prompt:
      template_dir: "custom_templates/"
      use_template_stochasticity: true
      template_variations:
        greeting:
          - "Let's enhance this code:"
          - "Time to optimize:"
          - "Improving the algorithm:"
        improvement_suggestion:
          - "Here's how we could improve this code:"
          - "I suggest the following improvements:"
          - "We can enhance this code by:"
  10. Use Claude Code CLI as an LLM backend

    main

    You can use the Claude Code CLI as a backend, which allows for authentication via OAuth without needing an explicit API key. In your config.yaml, set the provider to claude_code and define a list of models with their respective weights and budgets.

    llm:
      provider: "claude_code"
      models:
        - name: "sonnet"
          weight: 0.8
          max_tokens: 16000
          max_budget_usd: 1.0
        - name: "haiku"
          weight: 0.2
          max_tokens: 8000
  11. Configure Island-Based Evolution parameters

    main

    Island-based evolution parameters are used to maintain evolutionary diversity by managing separate populations (islands) and how they interact via migration.

    Parameters

    • num_islands: The number of separate populations. Recommended: 3-10.
    • migration_interval: How many generations to wait between migration events. Recommended: 25-100.
    • migration_rate: The fraction of top programs to migrate between islands. Recommended: 0.05-0.2 (5%-20%).

    Strategy Selection

    Problem TypeIslandsMigration FrequencyGoal
    ComplexMore islandsLess frequentMaintain diversity
    SimpleFewer islandsMore frequentFaster convergence
    Long RunsMore islands-Maintain diversity
    Short RunsFewer islands-Faster convergence
    database:
      num_islands: 5                      # Number of separate populations
      migration_interval: 50              # Migrate every N generations  
      migration_rate: 0.1                 # Fraction of top programs to migrate
  12. Determine program novelty using embeddings and LLM

    main

    The database supports a two-stage novelty check to prevent redundant evolution:

    1. Embedding Similarity: It computes the cosine similarity between the new program's code embedding and existing program embeddings. If the similarity exceeds similarity_threshold, the program is considered potentially non-novel.
    2. LLM Judgment: If a similar program is found, the system calls an LLM (via novelty_llm) to judge if the new code is actually novel compared to the existing code. The LLM must respond with NOVEL or NOT NOVEL.

    If the LLM check fails or returns an empty response, the system defaults to assuming the program is novel.