metade:Evolving differential evolution with differential evolution: a meta-level optimizer adapts the strategies and parameters of inner DE solvers. Includes JAX and PyTorch implementations.

Evolving differential evolution with differential evolution: a meta-level optimizer adapts the strategies and parameters of inner DE solvers. Includes JAX and PyTorch implementations.

Branch1Tags0

EvoX Logo

🌟 MetaDE: Evolving Differential Evolution by Differential Evolution 🌟

MetaDE Paper on arXiv

MetaDE is an advanced evolutionary framework that dynamically optimizes the strategies and hyperparameters of Differential Evolution (DE) through meta-level evolution. By leveraging DE to fine-tune its own configurations, MetaDE adapts mutation and crossover strategies to suit varying problem landscapes in real-time. With GPU acceleration, it handles large-scale, complex black-box optimization problems efficiently, delivering faster convergence and superior performance. MetaDE is compatible with the EvoX framework.

The GitLab main branch contains source version 0.1.0 and separate JAX and PyTorch implementations. The package pins EvoX 1.1.1; installing the latest EvoX release is not equivalent to the environment used by this checkout. Backend speed depends on hardware, population size, problem and compilation; there is no fixed JAX-to-PyTorch speed ratio.

Features

  • Meta-level Evolution 🌱: Uses DE at a meta-level to evolve hyperparameters and strategies of DE applied at a problem-solving level.
  • Parameterized DE (PDE) πŸ› οΈ: A customizable variant of DE that offers dynamic mutation and crossover strategies adaptable to different optimization problems.
  • Multi-Backend Support πŸ”₯: Provides both JAX and PyTorch implementations for broader hardware/software compatibility.
  • GPU-Accelerated πŸš€: Integrated with GPU acceleration on both JAX and PyTorch, enabling efficient large-scale optimizations.
  • End-to-End Optimization πŸ”„: MetaDE provides a seamless workflow from hyperparameter tuning to solving optimization problems in a fully automated process.
  • Wide Applicability πŸ€–: Supports various benchmarks, including CEC2022, and real-world tasks like evolutionary reinforcement learning in robotics.

RL Tasks Visualization

Using the MetaDE algorithm to solve RL tasks.

The following animations show the behaviors in Brax environments:

Hopper Swimmer Reacher
  • Hopper: Optimizing the environment reward for hopping locomotion.
  • Swimmer: Enhancing movement efficiency in fluid environments.
  • Reacher: Moving the fingertip to a random target.

Requirements and installation

Use a separate Python 3.10 or 3.11 environment. The package metadata declares Python >=3.9, but usable versions also depend on the selected dependency wheels.

git clone --branch main https://gitlab.com/emi-lab/metade.git
cd metade

Install PyTorch for your CPU or GPU using the official installation guide, then install this checkout with the following compatibility pins:

python -m pip install -e . "evox==1.1.1" "jax==0.4.33" "jaxlib==0.4.33" "numpy==1.26.4" "flax==0.8.5" "optax==0.2.3" "orbax-checkpoint==0.6.1" "brax==0.12.1" "mujoco==3.2.7" "mujoco-mjx==3.2.7" tqdm

This installs the CPU JAX runtime. For NVIDIA GPU execution on a supported Linux host, replace the JAX runtime with the matching CUDA extra, retaining its version:

python -m pip install "jax[cuda12]==0.4.33"

The current import structure loads JAX utilities even through some PyTorch imports, and importing the local problem modules also imports Brax. Include the dependencies above for the examples below, including numerical examples that import those modules. mujoco and mujoco-mjx should use matching versions. Use editable installation from the checkout so that bundled CEC2022 data remain available at the paths used by the source.

pyproject.toml installs PyTorch and EvoX 1.1.1, but does not declare the JAX dependencies needed by these imports; the command above supplies them. The original paper setup used Brax 0.10.3. The newer compatibility environment above is for running the current source and does not establish an exact reproduction of the paper's robotics results.

Components

Evolver

MetaDE employs Differential Evolution (DE) as the evolver to optimize the parameters of its executor.

  • Mutation: DE's mutation strategies evolve based on feedback from the problem landscape.
  • Crossover: Different crossover strategies (binomial, exponential, arithmetic) can be used and adapted. Evolver Image

Executor

The executor is a Parameterized Differential Evolution (PDE), a variant of DE designed to accommodate various mutation and crossover strategies dynamically.

  • Parameterization: Flexible mutation strategies like DE/rand/1/bin or DE/best/2/exp can be selected based on problem characteristics.
  • Parallel Execution: Core operations of PDE are optimized for parallel execution on GPUs(via JAX or PyTorch). Executor Image

GPU Acceleration

MetaDE integrates with the EvoX framework for distributed, GPU-accelerated evolutionary computation, significantly enhancing performance on large-scale optimization tasks.

Examples

Global Optimization Benchmark Functions

The small settings below demonstrate the API; increase the populations and iteration budgets for experiments.

import jax.numpy as jnp
import jax
from tqdm import tqdm

from metade.util import StdSOMonitor, StdWorkflow
from metade.algorithms.jax import create_batch_algorithm, decoder_de, MetaDE, ParamDE, DE
from metade.problems.jax.sphere import Sphere

D = 10
BATCH_SIZE = 16
NUM_RUNS = 1
key_start = 42

STEPS = 3
POP_SIZE = BATCH_SIZE

BASE_ALG_POP_SIZE = 16
BASE_ALG_STEPS = 5

tiny_num = 1e-5
param_lb = jnp.array([0, 0, 0, 0, 1, 0])
param_ub = jnp.array([1, 1, 4 - tiny_num, 4 - tiny_num, 5 - tiny_num, 3 - tiny_num])

evolver = DE(
    lb=param_lb,
    ub=param_ub,
    pop_size=POP_SIZE,
    base_vector="rand",
    differential_weight=0.5,
    cross_probability=0.9
)

BatchDE = create_batch_algorithm(ParamDE, BATCH_SIZE, NUM_RUNS)
batch_de = BatchDE(
    lb=jnp.full((D,), -100),
    ub=jnp.full((D,), 100),
    pop_size=BASE_ALG_POP_SIZE,
)

base_problem = Sphere()
decoder = decoder_de
key = jax.random.PRNGKey(key_start)

monitor = StdSOMonitor(record_fit_history=False)

meta_problem = MetaDE(
    batch_de,
    base_problem,
    batch_size=BATCH_SIZE,
    num_runs=NUM_RUNS,
    base_alg_steps=BASE_ALG_STEPS
)

workflow = StdWorkflow(
    algorithm=evolver,
    problem=meta_problem,
    pop_transform=decoder,
    monitor=monitor,
    record_pop=True,
)

key, subkey = jax.random.split(key)
state = workflow.init(subkey)

for step in tqdm(range(STEPS)):
    power_up = 1 if step == STEPS - 1 else 0
    state = state.update_child("problem", {"power_up": power_up})
    state = workflow.step(state)

print(f"Best fitness: {monitor.get_best_fitness()}")

If you want to use the PyTorch backend, run python -m examples.pytorch.example from the repository root. Reduce the population and iteration settings in that example for a smoke test.

CEC Benchmark Problems

MetaDE supports several benchmark suites such as CEC2022. Here’s an example (JAX-based) for the CEC2022 test suite:

import jax.numpy as jnp
import jax
from tqdm import tqdm
from metade.util import (
    StdSOMonitor,
    StdWorkflow
)
from metade.algorithms.jax import create_batch_algorithm, decoder_de, MetaDE, ParamDE, DE
from metade.problems.jax import CEC2022TestSuit

D = 10 
FUNC_LIST = jnp.arange(12) + 1
BATCH_SIZE = 16
NUM_RUNS = 1  
key_start = 42

STEPS = 3
POP_SIZE = BATCH_SIZE

BASE_ALG_POP_SIZE = 16
BASE_ALG_STEPS = 5  

tiny_num = 1e-5
param_lb = jnp.array([0, 0, 0, 0, 1, 0])
param_ub = jnp.array([1, 1, 4 - tiny_num, 4 - tiny_num, 5 - tiny_num, 3 - tiny_num])

evolver = DE(
    lb=param_lb,
    ub=param_ub,
    pop_size=POP_SIZE,
    base_vector="rand", differential_weight=0.5, cross_probability=0.9
)

BatchDE = create_batch_algorithm(ParamDE, BATCH_SIZE, NUM_RUNS)
batch_de = BatchDE(
    lb=jnp.full((D,), -100),
    ub=jnp.full((D,), 100),
    pop_size=BASE_ALG_POP_SIZE,
)

for func_num in FUNC_LIST:
    base_problem = CEC2022TestSuit.create(int(func_num))
    decoder = decoder_de
    key = jax.random.PRNGKey(key_start)

    monitor = StdSOMonitor(record_fit_history=False)
    print(type(base_problem).__name__)
    meta_problem = MetaDE(
        batch_de,
        base_problem,
        batch_size=BATCH_SIZE,
        num_runs=NUM_RUNS,
        base_alg_steps=BASE_ALG_STEPS
    )

    workflow = StdWorkflow(
        algorithm=evolver,
        problem=meta_problem,
        pop_transform=decoder,
        monitor=monitor,
        record_pop=True,
    )
    key, _ = jax.random.split(key)
    state = workflow.init(key)

    for i in tqdm(range(STEPS)):
        power_up = 1 if i == STEPS - 1 else 0
        state = state.update_child("problem", {"power_up": power_up})
        state = workflow.step(state)

    print(f"Best_fitness: {monitor.get_best_fitness()}")

If you want to use the PyTorch backend, please refer to the PyTorch examples under examples/pytorch/example_cec2022.py in this repository.

Robotics Control (Evolutionary Reinforcement Learning)

MetaDE can also be used for real-world tasks like robotic control through evolutionary reinforcement learning. Note that running these examples requires installing CUDA-enabled JAX and the compatible Brax/JAX environment described above.

from tqdm import tqdm
import metade.problems
from jax import random
from flax import linen as nn
import jax.numpy as jnp
import jax

from metade.util import StdSOMonitor, StdWorkflow, TreeAndVector, parse_opt_direction
from metade.algorithms.jax import create_batch_algorithm, decoder_de, MetaDE, ParamDE, DE

steps = 20
pop_size = 100
key = jax.random.PRNGKey(42)

class HopperPolicy(nn.Module):
    @nn.compact
    def __call__(self, x):
        x = x.astype(jnp.float32)
        x = x.reshape(-1)
        x = nn.Dense(32)(x)
        x = nn.tanh(x)
        x = nn.Dense(32)(x)
        x = nn.tanh(x)
        x = nn.Dense(3)(x)
        x = nn.tanh(x)
        return x

model = HopperPolicy()
weights = model.init(random.PRNGKey(42), jnp.zeros((11,)))
adapter = TreeAndVector(weights)
vector_form_weights = adapter.to_vector(weights)

tiny_num = 1e-5
param_lb = jnp.array([0, 0, 0, 0, 1, 0])
param_ub = jnp.array([1, 1, 4 - tiny_num, 4 - tiny_num, 5 - tiny_num, 3 - tiny_num])
algorithm = DE(
    lb=param_lb,
    ub=param_ub,
    pop_size=pop_size,
    base_vector="rand", differential_weight=0.5, cross_probability=0.9
)

BatchDE = create_batch_algorithm(ParamDE, pop_size, 1)
batch_de = BatchDE(
    lb=jnp.full((vector_form_weights.shape[0],), -10.0),
    ub=jnp.full((vector_form_weights.shape[0],), 10.0),
    pop_size=100,
)

base_problem = metade.problems.jax.Brax(
    env_name="hopper",
    policy=jax.jit(model.apply),
    cap_episode=500,
)

meta_problem = MetaDE(
    batch_de,
    base_problem,
    batch_size=pop_size,
    num_runs=1,
    base_alg_steps=50,
    base_opt_direction="max",
    base_pop_transform=adapter.batched_to_tree,
)

monitor = StdSOMonitor(record_fit_history=False)
workflow = StdWorkflow(
    algorithm=algorithm,
    problem=meta_problem,
    monitor=monitor,
    pop_transform=decoder_de,
    record_pop=True,
)
monitor.set_opt_direction(parse_opt_direction("max"))
key, _ = jax.random.split(key)
state = workflow.init(key)

for i in tqdm(range(steps)):
    power_up = 1 if i == steps - 1 else 0
    state = state.update_child("problem", {"power_up": power_up})
    state = workflow.step(state)

print(f"Best fitness: {monitor.get_best_fitness()}")

If you want to use the PyTorch backend, please refer to the PyTorch examples under examples/pytorch/example_brax.py in this repository.

Community & Support

  • Engage in discussions and share your experiences on GitLab issues.
  • Join our QQ group (ID: 297969717).

Citing MetaDE

@article{metade,
  title = {{MetaDE}: Evolving Differential Evolution by Differential Evolution},
  author = {Chen, Minyang and Feng, Chenchen and Cheng, Ran},
  journal = {IEEE Transactions on Evolutionary Computation},
  year = 2025,
  doi = {10.1109/TEVC.2025.3541587}
}

Introduction

Evolving differential evolution with differential evolution: a meta-level optimizer adapts the strategies and parameters of inner DE solvers. Includes JAX and PyTorch implementations.

Customize your domain