Bayesian optimisation of elites

Use qdpy.algorithms.BOPElites to decide where to spend the next expensive evaluation. The example uses a cheap stand-in, a two-variable quadratic cost with a product descriptor. Its archive keeps the best genuine evaluation per descriptor cell.

Run from the repository root after installing the base package.

python examples/bop_elites.py
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Fit Gaussian processes for both quality and descriptors.

"""Run a small Bayesian search with genuine evaluations and a fixed grid."""

from qdpy.algorithms import BOPElites
from qdpy.containers import Grid
from qdpy.simple import run


def evaluate(candidate):
    """Return the raw cost and the product descriptor."""
    x, y = candidate
    return ((x - 0.2) ** 2 + (y - 0.4) ** 2,), (x * y,)


if __name__ == "__main__":
    unit = (0.0, 1.0)
    archive = Grid(shape=4, fitness_domain=((0, 2),), features_domain=(unit,))
    search = BOPElites(
        archive, budget=24, dimension=2, ind_domain=unit, quality_floor=-2,
        initial_samples=8, candidate_pool=16, restarts=2,
    )
    result = run(search, evaluate, seed=42)
    print(f"Evaluations: {result.evaluations}")
    print(f"Finite observations: {search.n_observations}")
    print(f"Occupied cells: {archive.filled_bins}/{len(archive.solutions)}")
    for cell, entries in archive.solutions.items():
        if entries:
            elite = entries[0]
            print(f"Cell {cell}: descriptor {elite.features[0]:.4f}, raw cost {elite.fitness.values[0]:.4f}")

The first eight proposals here come from a scrambled Sobol sequence. The default warm-up is ten proposals per decision variable, so set initial_samples below the budget when you want a shorter run to reach the modelled phase. Once the search has enough observations, it fits separate fixed Matérn Gaussian processes for the objective and each descriptor. Acquisition combines the expected improvement in each cell with the predicted probability of landing there. The runner evaluates one proposal at a time and updates the models with its result.

Use the printed cell entries to check the measured descriptor and cost of each elite. n_observations counts finite measurements, including points with descriptors outside the grid. A failed call spends one attempt and the search remembers that genome. Set quality_floor in signed units. For a declared raw minimisation range of [0, 2], use -2 as the empty-cell floor.

For a second descriptor, return two descriptor values from the evaluator and give the grid a two-axis shape and one interval per axis. candidate_pool and restarts control the amount of work spent searching each acquisition function. Compare both attempted evaluations and wall time when tuning these settings. See Differentiable, Bayesian, and high-dimensional QD pilots for a comparison with Sobol and MAP-Elites.

Known feasibility and shared descriptor inputs

Set model_feasibility=True if the evaluator can tell that a design is infeasible. Return (None, None, {"bop_valid": False}) for that outcome. An evaluator error spends an attempt and leaves the feasibility data unchanged. After at least three outcomes in each class, a three-fold sigmoid-calibrated SVM weights the acquisition by the probability of feasibility. Successful measurements outside the grid still provide positive feasibility labels. Inspect n_invalid_observations for the explicit negative count.

The descriptor_transform option is useful when several descriptors share a measured quantity and you know how to compute each descriptor from it. Fit Gaussian processes to the source quantities and pass the same draws to every descriptor that uses them. This estimates a joint cell probability. A sample outside the grid contributes to no cell. The following transform receives rows of raw genomes and source values.

import numpy as np
from qdpy.algorithms import BOPElites
from qdpy.containers import Grid

def descriptors(genomes, latents):
    flow = latents[:, 0]
    return np.column_stack((flow, flow + 0.1 * genomes[:, 0]))

grid = Grid(shape=(8, 8), fitness_domain=((0.0, 3.0),),
            features_domain=((0.0, 1.0), (0.0, 1.0)))
search = BOPElites(
    grid, budget=32, dimension=2, ind_domain=(0.0, 1.0),
    quality_floor=0.0, optimisation_task="maximisation",
    initial_samples=8, candidate_pool=16, restarts=1, seed=11,
    model_feasibility=True, descriptor_transform=descriptors,
    latent_size=1, posterior_samples=128,
)

def evaluate(genome):
    x, y = genome
    if x + y > 1.2:
        return None, None, {"bop_valid": False}
    flow = 0.1 + 0.75 * y
    quality = 3 - (x - 0.6)**2 - (y - 0.4)**2
    return (quality,), None, {"bop_latents": (flow,)}

for _ in range(search.budget):
    (candidate,) = search.ask_batch()
    search.tell_batch([evaluate(candidate)])
print(search.n_observations, search.n_invalid_observations)

Use ordinary grid features and a deterministic, vectorized transform. The transform sets the archived descriptor from the original measurement. The source GPs and the objective GP remain independent. The transform accounts for dependence introduced by reusing the sources. Joint cell sampling is a QDpy extension. Its draw count is a power of two and controls acquisition cost and resolution.

Local Pareto, team, feedback, graph, and Bayesian QD pilots compares the four combinations on a constrained analytic task.

See Kent et al. (2025).