Composite designs, surrogate niching, and heuristics

CoME searches for compatible components. SPHEN spends expensive calls on promising surrogate elites. MOLE traces local trade-offs between two differentiable objectives. Heuristic design builds a library of rules and chooses a rule for each new instance. All four use the base package.

Coevolve complementary components with CoME

Give each component its own initializer, mutation, and descriptor function. Both archives need the same shape so a cell index on either side can serve as a starting point for finding partners. Their descriptor bounds can differ. The score callback evaluates one complete pair.

from qdpy.algorithms import CoME
from qdpy.containers import Grid

def component_grid():
    return Grid(shape=(8,), features_domain=((0., 1.),),
                fitness_domain=((0., 1.),), fitness_weights=(1.,))

def initialize(rng):
    return float(rng.random())

def mutate(value, rng):
    return float(min(1., max(0., value + rng.normal(0., .12))))

def describe(value):
    return (value,)

search = CoME(
    (component_grid(), component_grid()),
    initialize=(initialize, initialize),
    mutations=(mutate, mutate), descriptors=(describe, describe),
    evaluate=lambda pair: 1. - abs(sum(pair) - 1.),
    coupling="local-best", partners=3, radius=2., seed=11,
)
stats = search.run(160)
print(stats.evaluations, [archive.best for archive in search.archives])

Each archive indexes a measured pair on its own component’s descriptors. For breeding, CoME takes the component on the corresponding side. It proposes up to partners pairs per mutation from occupied cells in the neighborhood of the mapped cell. radius is a strict Euclidean distance in cell-index units. A radius of 1 uses only the mapped cell.

With local-best, each cell remembers the partner cell from its best observed pair. global-best uses the partner from the best observed pair across the archive. center, identity, and random provide fixed or random controls. Budget counts actual pair evaluations, including initialization and repeated pairs.

Medvet, Lippolis, and Nadizar, Quality-diversity in problems with composite solutions.

Use SPHEN when descriptors are also expensive

Return measured fitness and descriptors together. SPHEN fits a Gaussian process for each response. An auxiliary MAP-Elites run ranks offspring by upper confidence bound on signed fitness, using posterior-mean descriptors for cell assignment. Sobol targets select acquisition cells.

from examples.composite_surrogate_qd import black_box, design_grid
from qdpy.algorithms import SPHEN

measured = design_grid((6, 6))
search = SPHEN(measured, 64, 2, initial_samples=8, batch_size=4, seed=11)
search.optimise(black_box)
print(measured.filled_bins, search.misclassified, search.prediction_checks)
for prediction in search.prediction_map(192, seed=11):
    print(prediction.cell, prediction.genome, prediction.fitness)

The measured archive assigns cells by exact descriptors. The prediction map uses posterior-mean fitness and has its own cheap-query budget. A predicted design may land in another cell when measured. Use prediction_checks as the denominator for misclassified. For manual evaluations use ask_batch() and tell_batch().

QDpy shares a fixed RBF kernel between responses and uses the supplied grid for both maps. The paper fits kernel hyperparameters and demonstrates a finer prediction geometry to compensate for misclassified descriptors.

Hagg et al., Designing Air Flow with Surrogate-Assisted Phenotypic Niching.

Trace local trade-offs with MOLE

Supply two costs to minimize and their analytic Jacobian. Starting points in different attraction basins can recover separate curves even when their objective values coincide.

from examples.composite_surrogate_qd import two_curves
from qdpy.algorithms import MOLE

search = MOLE(((-1., 1.), (-1., 1.)), step_size=.1)
result = search.run(two_curves, [(0., .8), (0., -.8)], 512)
for curve in result.sets:
    print(curve[0].genome, curve[-1].genome)
print(result.transitions, result.evaluations)

MOLE jointly descends from each start, predicts the next point along a curve, and corrects the prediction with further joint descent. It records directed transitions when the correction reaches a different locally efficient set. The callback budget includes descent, continuation, and rejected trials.

This bounded bi-objective version uses analytic gradients, monotone backtracking, and a spatial step limit. The paper also describes numerical derivatives, nonmonotone descent, and hypervolume refinement. The recovered curves depend on the starts, step limits, and budget.

Schäpermeier, Grimme, and Kerschke, MOLE: Digging Tunnels Through Multimodal Multi-Objective Landscapes.

Build a repertoire of scheduling rules

Calibrate on several rules and a fixed training panel. Choose structural features that the proposal operator can change. The example counts references to job duration and due date in the syntax of a priority rule.

import numpy as np
from qdpy.algorithms import QDHeuristicDesign
from examples.composite_surrogate_qd import (
    design_grid, propose_schedule, schedule_cost, schedule_structure,
)

search = QDHeuristicDesign(
    design_grid((7, 7), (-1., 1.), -1., (0., 1.)),
    structure=schedule_structure, propose=propose_schedule,
    evaluate=schedule_cost, instance_features=lambda case: (case[2],),
    descriptor_indices=(0, 1), neighbors=4, seed=11,
)
# Each case contains processing times, due dates, and tardiness weight.
durations = np.array([3., 1., 2.])
deadlines = np.array([1., 5., 3.])
training = [(durations, deadlines, weight) for weight in (0., .5, 1.)]
stats = search.run([(8, 0), (0, 8), (4, 4)], training, 60)
held_out = (np.array([4., 1., 2.]), np.array([2., 6., 5.]), .8)
rule = search.select(held_out)
print(stats.evaluations, rule, schedule_cost(rule, held_out))

Calibration gives linear Shapley attributions for the structural features. The descriptor axes use selected attributions, scaled to fit the grid. The calibration stays fixed so cells keep the same meaning. The proposal callback receives the parent and its full attribution vector.

The selector returns the elite with the best measured fitness on the nearest training instances. The final evaluation above is independent of training. Search budget counts heuristic–instance calls.

The paper uses an LLM for variation and SHAP on AST features. QDpy’s variant uses a fixed ridge calibration, caller-controlled proposals, and nearest-neighbor selection. A proposal callback may call a model provided by the application. ast_node_counts extracts basic Python syntax features from a source string.

Illuminating Heuristic Design: Language-Model-Driven Quality-Diversity Evolution for Combinatorial Optimization.

Run the examples

python -m examples.composite_surrogate_qd components
python -m examples.composite_surrogate_qd surrogate
python -m examples.composite_surrogate_qd landscape
python -m examples.composite_surrogate_qd scheduling

See Composite design and heuristic search benchmarks for the settings and results.