SkillAgentSearch skills...

Evogp

A GPU-accelerated library for Tree-based Genetic Programming, leveraging PyTorch and custom CUDA kernels for high-performance evolutionary computation. It supports symbolic regression, classification, and policy optimization with advanced features like multi-output trees and benchmark tools.

Install / Use

npx skills add EMI-Group/evogp

Installs into whichever agent you are using.

About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<h1 align="center"> <a href="https://github.com/EMI-Group/evox"> <picture> <source media="(prefers-color-scheme: dark)" srcset="./imgs/evox_brand_light.svg"> <source media="(prefers-color-scheme: light)" srcset="./imgs/evox_brand_dark.svg"> <img alt="EvoX Logo" height="128" width="500px" src="./imgs/evox_brand_dark.svg"> </picture> </a> <br> </h1> <p align="center"> <picture> <img src="imgs/SymbolicRegression.svg" alt="" height="180"> </picture> <picture> <img src="imgs/Classification.svg" alt="" height="180"> </picture> <picture> <img src="imgs/Halfcheetah.svg" alt="HalfCheetah" height="180"> </picture> </p> <p align="center"> 🌟 EvoGP: A GPU-accelerated Framework for Tree-based Genetic Programming 🌟 </p> <p align="center"> <a href="https://arxiv.org/abs/2501.17168"> <img src="https://img.shields.io/badge/paper-arxiv-red?style=for-the-badge" alt="EvoGP Paper on arXiv"> </a> </p>

Table of Contents

Introduction

EvoGP is a fully GPU-accelerated Tree-based Genetic Programming (TGP) framework built on PyTorch, leveraging custom CUDA kernels for core evolutionary operations like tree generation, mutation, crossover, and fitness evaluation. It supports multi-output trees and includes built-in tools for symbolic regression, policy optimization, and classification, along with standardized benchmarks for evaluation and tuning. EvoGP combines the flexibility of Python with the computational power of GPUs, making it an ideal platform for TGP research and applications. EvoGP is a sister project of <a href="https://github.com/EMI-Group/evox">EvoX</a>.

Key Features

  • CUDA-based parallel approach for TGP:

    • Leverage specialized CUDA kernels to optimize critical TGP operations.
    • Enhance computational efficiency, especially for large populations, enabling faster execution compared to traditional TGP methods.
  • GPU-accelerated framework in Python:

    • Integrates CUDA kernels into Python via custom operators of PyTorch, ensuring compatibility with modern computational ecosystems.
    • Achieve up to a 100x speedup compared to existing TGP implementations while maintaining or improving solution quality.
  • Rich in extended content:

    • Offers a range of genetic operation variants, allowing users to tailor configurations for specific tasks.
    • Supports multi-output trees, making it suitable for complex problems like classification and policy optimization.
    • Supports Symbolic Regression, Classification, and Policy Optimization (Brax) benchmarks.

Installation

To install EvoGP, please follow the steps below:

1. Install NVIDIA CUDA Toolkit

Ensure you have the NVIDIA CUDA Toolkit installed, including nvcc. You can download it from NVIDIA's official website.

  • Check your CUDA version:
    nvcc --version
    

2. Install a C++ Compiler

Ensure you have a compatible C++ compiler installed:

  • Linux/macOS: Install GCC (9.x or later is recommended).
    sudo apt install build-essential  # On Ubuntu
    gcc --version
    
  • Windows: Install the Visual C++ Build Tools. You can download it from this. During installation, ensure that the C++ workload is selected.

3. Install PyTorch

Install the version of PyTorch that matches your installed CUDA Toolkit version.
For example, if you are using CUDA 11.8:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

Important: Make sure to select the PyTorch version compatible with the CUDA Toolkit version (nvcc -V), not the NVIDIA driver version.

You can find more details on the PyTorch installation page.

4. Install EvoGP

Finally, install EvoGP:

pip install git+https://github.com/EMI-Group/evogp.git --no-build-isolation

Note: This process might take a significant amount of time, as it includes the compilation of CUDA kernels.

5. Validate Installation

python -m evogp.sr_test

Building for AMD GPUs (ROCm)

EvoGP also runs on AMD GPUs through ROCm/HIP. The CUDA kernels are compiled with HIP automatically by PyTorch's build system, so the steps mirror the CUDA flow above with two substitutions:

  1. Instead of the NVIDIA CUDA Toolkit, install ROCm (including hipcc).
  2. Install a ROCm build of PyTorch, for example:
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm7.2
    
  3. Install EvoGP the same way:
    pip install git+https://github.com/EMI-Group/evogp.git --no-build-isolation
    

PyTorch detects the ROCm backend and routes the kernels through HIP; no source changes are required. The same cuda device strings used throughout the examples select the AMD GPU under ROCm. To target a specific AMD GPU architecture, set PYTORCH_ROCM_ARCH before installing (for example export PYTORCH_ROCM_ARCH=gfx1100); by default PyTorch builds for the architecture of the GPU it detects.

Basic API Usage

Start your journey with EvoGP in a few simple steps:

  1. Import necessary modules:
import torch
from evogp.tree import Forest, GenerateDescriptor
from evogp.algorithm import (
    GeneticProgramming,
    DefaultSelection,
    DefaultMutation,
    DefaultCrossover,
)
from evogp.problem import SymbolicRegression
from evogp.pipeline import StandardPipeline
  1. Define a problem (Here is Symbolic Regression with XOR-3d):
XOR_INPUTS = torch.tensor(
    [
        [0, 0, 0],
        [0, 0, 1],
        [0, 1, 0],
        [0, 1, 1],
        [1, 0, 0],
        [1, 0, 1],
        [1, 1, 0],
        [1, 1, 1],
    ],
    dtype=torch.float,
    device="cuda",
)

XOR_OUTPUTS = torch.tensor(
    [[0], [1], [1], [0], [1], [0], [0], [1]],
    dtype=torch.float,
    device="cuda",
)

problem = SymbolicRegression(datapoints=XOR_INPUTS, labels=XOR_OUTPUTS)
  1. Configure the algorithm:
# create decriptor for generating new trees
descriptor = GenerateDescriptor(
    max_tree_len=32,
    input_len=problem.problem_dim,
    output_len=problem.solution_dim,
    using_funcs=["+", "-", "*", "/"],
    max_layer_cnt=4,
    const_samples=[-1, 0, 1],
)

# create the algorithm
algorithm = GeneticProgramming(
    initial_forest=Forest.random_generate(pop_size=5000, descriptor=descriptor),
    crossover=DefaultCrossover(),
    mutation=DefaultMutation(
        mutation_rate=0.2, descriptor=descriptor.update(max_layer_cnt=3)
    ),
    selection=DefaultSelection(survival_rate=0.3, elite_rate=0.01),
)
  1. Run!:
pipeline = StandardPipeline(
    algorithm,
    problem,
    generation_limit=100,
)

best = pipeline.run()
  1. Check the details for the best tree:

Predict results check:

pred_res = best.forward(XOR_INPUTS)
print(pred_res)

Obtain output like this:

tensor([[ 1.0000e-09],
        [ 1.0000e+00],
        [ 1.0000e+00],
        [-1.0000e-09],
        [ 1.0000e+00],
        [ 1.0000e-09],
        [ 1.0000e-09],
        [ 1.0000e+00]], device='cuda:0')

Mathmatics Formula (Sympy expression):

sympy_expression = best.to_sympy_expr()
print(sympy_expression)

Obtain output like this:

(-x2*(x0 + x1) + 1.0)*(1.0*x2*(-x2*(x0 + x1) + 1.0) + (x0 - x1)**2)

Visualize:

best.to_png("./imgs/xor_tree.png")

Obtain:

<img src="imgs/sr_tree.png" alt="" height="300">

The complete code is available in code.

Advanced Genetic Operations

EvoGP includes multiple genetic operators, allowing users to freely assemble them to build customized TGP algorithms.

| Type | Name | |------------|---------------------------------------| | Selection | DefaultSelection | | Selection | RouletteSelection | | Selection | TruncationSelection | | Selection | RankSelection | | Selection | TournamentSelection | | Crossover | DefaultCrossover | | Crossover | DiversityCrossover | | Crossover | LeafBiasedCrossover | | Mutation | DefaultMutation | | Mutation | HoistMutation | | Mutation | SinglePointMutation | | Mutation | MultiPointMutation | | Mutation | InsertMutation | | Mutation | DeleteMutation | | Mutation | SingleConstMutation | | Mutation | MultiConstMutation | | Mutation | CombinedMutation |

Supported Benchmarks

Symbolic Regression

EvoGP supports symbolic regression tasks. You can construct a Problem with your custom dataset:

from evogp.problem import SymbolicRegression

problem = SymbolicRegression(datapoints=YOUR_DATA, labels=YOUR_LA

Related Skills

View on GitHub
GitHub Stars297
CategoryCustomer
Updated3h ago
Forks47

Languages

Python

Security Score

100/100

Audited on Aug 8, 2026

No findings