Co-design bodies and controllers with Pollination

Pollination MAP-Elites searches over body parameters and controller weights together. It bins policies by body descriptors. A body mutation can carry its parent’s controller into another cell. Periodically, the search learns one controller from several nearby elites and tests that controller on the teachers’ bodies.

Install qdpy[rl]. This example varies two Pendulum parameters while keeping the observation and action spaces identical.

import gymnasium as gym
import numpy as np
from qdpy.containers import Grid
from qdpy.rl import PolicyConfig, PollinationMAPElites

def make_env(body):
    gravity, mass = body
    env = gym.make("Pendulum-v1", g=6 + 8*gravity, max_episode_steps=12)
    env.unwrapped.m = .5 + mass
    return env

def mutate(body, rng):
    return tuple(np.clip(np.array(body) + rng.normal(0, .12, size=2), 0, 1))

archive = Grid(shape=(5, 5), fitness_domain=((-500., 0.),),
               features_domain=((0., 1.), (0., 1.)))
search = PollinationMAPElites(
    make_env, archive, initial_bodies=[(.4, .4), (.6, .6)],
    body_descriptor=lambda body: body, mutate_body=mutate,
    policy=PolicyConfig((16,)), max_episode_steps=12,
    pollination_every=1, seed=11,
)
stats = search.train(384)
print(stats.env_steps, stats.pollinated, stats.migrations)

Use a fixed-width numeric body tuple and two fixed morphology descriptors. If the controller needs body information, include it in the environment’s fixed-shape observation. The student starts from the anchor teacher and fits the pooled observation–action pairs. Each student evaluation repeats its teacher’s reset seed. The default acceptance threshold is the measured teacher return on that seed. Set pollination_every=None for ordinary co-design.

The step budget includes teacher and student rollouts. A round that runs out of steps leaves the archive intact. Use body_for() and policy_for() to retrieve an archived solution for evaluation. The runnable CPU pilot uses a synthetic tracking plant.

Mertan and Cheney, GECCO 2025.