Learn descriptors from trajectories with AutoQD¶
AutoQD uses state and action history to discover a repertoire. The evaluator returns trajectories and a scalar fitness to maximize. AutoQD compares discounted occupancy embeddings of the trajectories and uses calibrated weighted principal components as the grid axes.
Install the existing CMA extra in your environment.
python -m pip install -e '.[cma]'
# Or use uv in the current environment:
uv pip install -e '.[cma]'
from qdpy.algorithms import autoqd_search
from qdpy.containers import Grid
def evaluate(genome, seed):
x, y = genome
trajectory = [[0., 0., x, y], [x, y, x, y]]
return 1 - ((x - 0.4) ** 2 + (y + 0.2) ** 2) / 4, (trajectory,)
grid = Grid(shape=(8, 8), features_domain=((-1.2, 1.2),) * 2,
fitness_domain=((0., 1.),), fitness_weights=(1.,))
result = autoqd_search(
evaluate, grid, budget=256, x0=(0., 0.), sigma0=0.5,
threshold_min=0., trajectory_width=4, batch_size=8,
ind_domain=(-1., 1.), gamma=0.5, seed=11,
)
if result.archive:
_, trajectories = evaluate(result.archive.best, 42)
print(result.projector.transform(trajectories))
Pass a tuple of trajectories, even for a single rollout. Each row should contain the state and corresponding action in fixed numeric coordinates. Use consistent input scaling across rollouts and use the supplied seed when the evaluator involves randomness. The candidate budget includes failed evaluations. Rollout and step counters describe valid returned evaluations, so account separately for simulator work lost during failed callbacks.
The random Fourier basis stays fixed. AutoQD learns the projection from
cached embeddings of the current elites every ten full batches by
default. The fit weights embeddings by fitness and maps its 5th and 95th
percentiles to minus and plus one. The grid extends to plus and minus
1.2, and the search clips descriptors at those limits. A successful
update reprojects elites in a fresh grid and restarts CMA-MAE. Read the
returned archive for the final geometry. A rank-deficient fit or failed
rebuild retains the previous grid, projection, and emitter. Set
update_interval=None to keep the initial random projection.
Compare methods at equal candidate and rollout budgets.
python examples/autoqd.py --budget 512 --seeds 11 29 47
Every run used 1,024 rollouts and 20,480 training trajectory steps. Median
held-out coverage was 18.8% for AutoQD, 4.7% for the frozen projection, and
68.8% for hand-written endpoint descriptors. Median held-out QD scores
were respectively 11.74, 2.80, and 40.41. These metrics evaluate the
returned elites again using a common endpoint grid. They describe this
small steering task, where the endpoint is a known descriptor.
Raw runs.
See Hedayatian and Nikolaidis, AutoQD, and the pinned implementation.