Multiple descriptors and CMA-based search¶
The examples on this page use four independent searches. Each receives
new archives and a private seed. Evaluators return measurements and the
search updates archives in the calling process. Install qdpy[cma]
for Dynamic CMA-ME, DDS-KDE, and CMA-MEGA (ES). Multi-descriptor
MAP-Elites Success uses the base package.
Multi-descriptor MAP-Elites Success¶
Use qdpy.algorithms.multi_bd_mes() when one evaluation supplies
several views of behavior. For example, one navigation run can yield
both its endpoint and the centroid of the path it followed. Define a
success condition such as reaching a goal. Each descriptor view has
its own Grid or CVTGrid, and the same evaluation can enter several
archives. Fitness compares elites of equal success status. A successful
candidate can replace an unsuccessful one even when its shaping fitness
is lower. Parent selection favours successful elites in the current view.
from qdpy.algorithms import multi_bd_mes
from qdpy.containers import Grid
archives = {
name: Grid(shape=8, features_domain=((0., 1.),), fitness_domain=((0., 1.),),
fitness_weights=(1.,))
for name in ("distance", "balance")
}
def evaluate(genome):
left, right = genome
distance = (left + right) / 2
balance = 1 - abs(left - right)
return distance > .75, (distance,), {"distance": (distance,), "balance": (balance,)}
result = multi_bd_mes(archives, evaluate, dimension=2, budget=64, seed=7)
print(result.attempts, result.successful_evaluations, result.admissions)
The implementation uses a steady-state loop, round-robin view selection,
and bounded Gaussian mutation. Each stored elite has a success named
score. Declare the success criterion and descriptor views in your
evaluator. The reference uses a model to propose these functions.
Garrabé, Khoramshahi, and Doncieux (2026 preprint).
Dynamic CMA-ME¶
qdpy.algorithms.dynamic_cma_me() probes the least recently checked
elite for a change in fitness or descriptors. When a probe detects a
shift, it refreshes the incumbents of the cells targeted by the new
offspring. If an incumbent moves to another occupied cell, it also
refreshes that cell’s incumbent. The search stages those measurements
before committing them. If a refresh fails or exhausts the remaining
budget, that generation leaves the archive as it was. The attempts still
count toward the budget.
from qdpy.algorithms import dynamic_cma_me
from qdpy.containers import Grid
archive = Grid(shape=(6, 6), features_domain=((0., 1.),) * 2,
fitness_domain=((0., 1.),))
def evaluate(genome, tick):
centre = .25 if tick < 32 else .75
cost = sum((x - centre) ** 2 for x in genome) / len(genome)
return (cost,), genome[:2]
result = dynamic_cma_me(archive, evaluate, x0=[.5] * 4,
budget=93, batch_size=8, seed=7)
print(result.offspring_attempts, result.detection_attempts, result.refresh_attempts)
Use a deterministic evaluator at each tick. Each generation freezes its
tick at the current number of spent attempts. Probe and refresh calls
share that tick. The implementation uses one improvement emitter and
passes only a complete offspring population to CMA. Use refresh=False
for the matched static control. Audit both archives at the same final
tick and keep audit calls separate from search. Gallotta, Liapis,
and Yannakakis (2024).
Density Descent Search with a kernel density estimate¶
qdpy.algorithms.dds_kde() ranks new solutions by descriptor
density using a Gaussian kernel and a bounded reservoir of past
descriptors. The results grid reports discoveries. CMA and the
reservoir update independently of admission to that grid. Supply
constant fitness to isolate diversity in a comparison. Bandwidth
is in descriptor units, so use comparable scales for distinct axes.
from qdpy.algorithms import dds_kde
from qdpy.containers import Grid
archive = Grid(shape=(8, 8), features_domain=((0., 1.),) * 2,
fitness_domain=((0., 1.),), fitness_weights=(1.,))
result = dds_kde(archive, lambda genome: ((1.,), genome[:2]),
x0=[.5] * 4, budget=128, bandwidth=.1,
reservoir_size=64, batch_size=12, seed=7)
print(result.attempts, result.reservoir_size, archive.filled_bins)
The Gaussian estimate scores a population against the prior reservoir. Reservoir sampling adds the current population after ranking. Valid descriptors can inform the estimate even if their result falls outside the reporting grid. This is the KDE variant from Lee et al. (2024).
For the continuous normalizing flow variant on the same CMA scheduler, see Fit a continuous descriptor density.
CMA-MEGA with ES gradient estimates¶
qdpy.algorithms.cma_mega_es() estimates fitness and descriptor
gradients from the same set of mirrored perturbations. It samples
linear combinations of the normalised gradients and adapts its
coefficient distribution using archive improvement. As in the authors’
reference configuration, centre and perturbation measurements can enter
the archive. A bounded search clips candidates to its declared genome
bounds. Failed measurements count toward the budget. A pair enters the
gradient estimate only if both perturbations returned valid measurements.
from qdpy.algorithms import cma_mega_es
from qdpy.containers import Grid
archive = Grid(shape=(6, 6), features_domain=((0., 1.),) * 2,
fitness_domain=((0., 1.),))
def evaluate(genome):
cost = sum((x - .25) ** 2 for x in genome) / len(genome)
return (cost,), genome[:2]
result = cma_mega_es(archive, evaluate, x0=[.5] * 4, budget=93,
es_samples=8, batch_size=12, seed=7)
print(result.centre_attempts, result.perturbation_attempts, result.offspring_attempts)
The reported total includes all three phases. DDS-KDE and CMA-MEGA (ES)
also accept a caller-owned executor exposing ordered map. For process
workers, define the evaluator at module scope. See Tjanaka et al. (2022) for the algorithm and original RL experiments.
Reproduce the CPU comparisons¶
From the repository root, use the installed QDpy package to run the example with three seeds and 388 candidate calls per search.
python -m pip install ".[cma]"
python -m examples.descriptor_cma --output build/descriptor-cma/results.json
To run the navigation comparison with the base package, pass
--studies success. The dynamic comparison reports an independent
final-tick audit. The density comparison uses identical reporting grids
and constant quality. The gradient comparison counts the perturbation
cost for both ES methods. The default budget fits ME-ES initialization
and whole generations exactly.
The following values are medians over seeds 7, 13, and 23. All 36 trials spent 388 search calls each. A second run reproduced every saved record.
Study |
New method |
Baselines |
|---|---|---|
Navigation, successful endpoint cells |
Multi-descriptor MES 7 |
Single-grid MES 7, MAP-Elites 1 |
Shifting sphere, final archive freshness |
Dynamic CMA-ME 54.8% |
Static CMA-ME 38.7%, Dynamic MAP-Elites 64.9% |
Constant quality, coverage |
DDS-KDE 96.9% |
Novelty search 78.1%, CMA-MAE 100.0% |
Rastrigin, QD score |
CMA-MEGA (ES) 43.23 |
ME-ES 6.54, CMA-MAE 40.00 |
Multi-descriptor MES found a successful endpoint on all three seeds. Single-grid MES did so on two. Dynamic CMA-ME spent a median of 23 probes and 78 refresh calls. Dynamic MAP-Elites spent a median of 184 refresh calls and had higher final freshness on this task. The saved results include corrected coverage and QD scores from the independent audit.
Download the per-seed results.
- qdpy.algorithms.multi_bd_mes(archives, evaluate, *, dimension, budget, ind_domain=(0, 1), mutation_sigma=0.1, seed=0, on_step=None)[source]¶
Run steady-state multi-descriptor MAP-Elites Success.
Each grid has independent local competition. A success takes precedence within its cell. Fitness breaks comparisons between entries with equal success status. Select parent grids in round-robin order, falling back to a populated grid if necessary. Within each grid, sample uniformly from successful elites when available, or from all elites while searching for a first success. Mutate real-valued candidates with bounded Gaussian noise. Garrabé et al. use the multi-grid method with inferred descriptor functions. This runner accepts them as part of the supplied evaluator.
- Parameters:
archives – Mapping from descriptor view names to distinct, empty, parentless, best-only Grid or CVTGrid instances.
evaluate – Callable taking an immutable genome and returning (success, (fitness,), {view: descriptors}). Success is a bool.
dimension – Number of real variables in each genome.
budget – Total evaluator attempts across all descriptor views.
ind_domain – Inclusive lower and upper genome bounds.
mutation_sigma – Gaussian standard deviation as a fraction of the bounds’ span.
seed – Private random seed for initialization, selection and mutation.
on_step – Optional callback taking the archives and keyword arguments iteration and evaluations after each attempted evaluation.
- Returns:
Live archives and shared evaluation accounting.
- qdpy.algorithms.dynamic_cma_me(archive, evaluate, *, x0, budget, sigma0=0.15, batch_size=16, ind_domain=(0, 1), seed=0, refresh=True, on_step=None)[source]¶
Run Dynamic CMA-ME with oldest-elite detection and replacee refresh.
A generation shares one tick, the number of attempts already spent when it starts. Probe the least recently checked elite, including with the final available call. If the probe changed, refresh occupied destinations and follow incumbent moves. Commit the updates together before ranking offspring by cell improvement. Failed or unfinished refreshes leave the archive untouched and restart the strategy. Only offspring from a full generation enter CMA feedback.
- Parameters:
archive – Empty, parentless, best-only Grid or CVTGrid.
evaluate – Callable taking an immutable genome and a tick. Return a singleton fitness vector and its descriptors.
x0 – Initial genome used before the first archive admission.
budget – All attempted evaluations, including probes and refreshes.
sigma0 – Initial CMA sampling scale.
batch_size – CMA population size.
ind_domain – Common bounds, or None for unbounded search.
seed – Private CMA and restart seed.
refresh – Enable detection and refresh. False runs static CMA-ME with the same improvement emitter and tick convention.
on_step – Optional callback receiving the archive, iteration and evaluations.
- Returns:
The live archive and counts per evaluation phase.
- qdpy.algorithms.dds_kde(archive, evaluate, *, x0, budget, bandwidth, reservoir_size=1024, sigma0=0.15, batch_size=16, ind_domain=(0, 1), seed=0, executor=None, on_step=None)[source]¶
Run Density Descent Search with kernel density estimation.
Each generation is ranked against the descriptor reservoir from earlier generations. Reuse the previous order to break equal densities. Offer measured solutions to a passive archive. Fitness and archive admission never enter CMA feedback. Valid measurements outside the archive’s bounds still inform the density model.
- Parameters:
archive – Empty, parentless, best-only Grid or CVTGrid.
evaluate – Callable taking an immutable genome and returning a singleton fitness vector and its descriptors. Use constant fitness for a pure diversity task.
x0 – Initial genome for CMA and its restarts.
budget – Total attempted evaluations.
bandwidth – Positive Gaussian bandwidth in descriptor units.
reservoir_size – Maximum number of past descriptors to retain.
sigma0 – Initial CMA sampling scale in genome coordinates.
batch_size – CMA population size. Commit a final partial batch to the passive archive and reservoir.
ind_domain – Shared bounds, or None for unbounded search.
seed – Private seed for CMA and uniform reservoir sampling.
executor – Optional caller-owned executor with ordered map.
on_step – Optional callback receiving the archive, iteration and evaluations.
- Returns:
Passive archive and run accounting.
- qdpy.algorithms.cma_mega_es(archive, evaluate, *, x0, budget, es_samples=32, es_sigma=0.02, sigma0=0.2, step_size=1.0, batch_size=16, ind_domain=(0, 1), seed=0, executor=None, on_step=None)[source]¶
Run CMA-MEGA (ES) with measured fitness and black-box descriptors.
Evaluate the centre and mirrored perturbations first. Use one rank gradient per output, estimated from the same perturbations. Offer all valid measurements to the archive. Branch along combinations of the normalised gradients and adapt CMA in coefficient space using archive improvement. Advance the centre by rank-weighted gradient ascent. If the budget ends, archive measured partial phases without adapting CMA from a short batch. Discard incomplete mirrored pairs when estimating gradients.
- Parameters:
archive – Empty, parentless, best-only Grid or CVTGrid.
evaluate – Callable taking an immutable real-valued genome and returning a singleton fitness vector and its descriptors.
x0 – Initial centre in genome coordinates.
budget – Total attempted centre, perturbation and offspring evaluations.
es_samples – Even number of perturbations including both signs.
es_sigma – Perturbation standard deviation in genome coordinates.
sigma0 – Initial CMA step size in gradient coefficient coordinates.
step_size – Multiplier for the rank-weighted centre displacement.
batch_size – CMA offspring population size.
ind_domain – Inclusive bounds, or None for unbounded search.
seed – Private seed for perturbations, CMA and restart centres.
executor – Optional caller-owned executor with ordered map.
on_step – Optional callback receiving the archive, iteration and evaluations.
- Returns:
The live archive and counts for each phase.