Batch acquisition, benchmark instances, feasibility, and scenario risk

These workflows use the base QDpy installation. Run the corresponding CPU comparisons with python examples/batch_risk.py --seeds 11. See CPU pilots for batch acquisition, benchmark instances, feasibility, and risk for budgets, held-out results, and timing.

Batch BOP-Elites

qdpy.algorithms.BatchBOPElites proposes a full generation before measuring its candidates. Use it with a bounded real genome, a rectangular one-elite grid, one fitness objective, and one or two direct descriptors.

The algorithm fits a Gaussian process per output using completed measurements. In each Monte Carlo draw it samples each process jointly across the Sobol candidate pool, with independent draws between output models. Each candidate lands in a cell and contributes its positive improvement over that cell’s incumbent or the empty-cell quality floor. A draw contributes the sum of the largest gain in each cell. Greedy selection adds the candidate with the largest increment to this sum in expectation. The alternative selection="independent" uses the same samples and chooses the top candidates by their individual mean gains.

from concurrent.futures import ThreadPoolExecutor
from qdpy.algorithms import BatchBOPElites
from qdpy.containers import Grid

archive = Grid(shape=(5, 5), features_domain=((0., 1.),) * 2,
               fitness_domain=((0., 1.),), fitness_weights=(1.,))
method = BatchBOPElites(archive, budget=20, dimension=2, ind_domain=(0., 1.),
                        quality_floor=0., batch_size=4, initial_samples=8,
                        candidates=32, samples=64, seed=4,
                        optimisation_task="maximisation")

def evaluate(point):
    x, y = point
    return (1. - (x - .4)**2,), (x, y**2)

points = method.ask_batch()
method.tell_batch([evaluate(point) for point in points])
with ThreadPoolExecutor(max_workers=4) as executor:
    method.optimise(evaluate, budget=16, executor=executor)

Apply manual results in the order returned by ask_batch(). Use None for a failed slot. In managed runs budget limits the number of proposals made by that invocation, with a partial final generation as needed. Warm-up fills whole generations and continues until at least two valid observations have arrived. A seeded run uses the same feedback order with sequential and parallel evaluation. Increase samples to reduce Monte Carlo error. Increase candidates to broaden the search at the cost of larger covariance matrices. Gaussian-process covariance construction and decomposition make this workflow most appropriate for costly evaluations and moderate pools.

The acquisition adapts the cell-based improvement of Kent and Branke’s BOP-Elites using the joint-posterior approach to batch selection illustrated in Daulton et al.’s parallel Bayesian optimization paper. The QDpy batch objective is expected per-cell quality gain.

Discriminatory benchmark instances

qdpy.algorithms.DiscriminatoryInstanceSearch generates instances on which a solver panel makes different decisions or achieves different scores. The margin is the leading solver’s advantage over the runner-up. With target_solver, it is the target’s signed advantage over its best competitor. Pass maximize=False when the solvers return costs.

The breeding population combines a scaled margin and nearest-neighbor novelty. gap_novelty_weight mixes novelty of the scalar margin with novelty of hand-supplied instance features. The instance grid keeps the strongest discriminatory instance per cell. A second grid can report by winning solver index and raw margin. Both record the raw score vector in solver mapping order and the winner.

from qdpy.algorithms import DiscriminatoryInstanceSearch
from qdpy.containers import Grid

archive = Grid(shape=8, features_domain=((0., 1.),),
               fitness_domain=((0., 1.),), fitness_weights=(1.,))
performance = Grid(shape=(2, 6), features_domain=((-0.5, 1.5), (0., 1.)),
                   fitness_domain=((0., 1.),), fitness_weights=(1.,))
search = DiscriminatoryInstanceSearch(
    archive, performance_archive=performance,
    solvers={"first": lambda instance, seed: instance[0],
             "second": lambda instance, seed: 1. - instance[0]},
    initializer=lambda rng: (rng.random(),),
    mutate=lambda instance, rng: ((instance[0] + rng.normal(0., .15)) % 1.,),
    describe=lambda instance: instance, min_gap=.05, seed=7,
)
stats = search.run(200)
assert stats.instances == 100 and stats.solver_calls == 200
assert archive.best.scores["winning_solver"] in search.solver_names

Use comparable units and effort for the solvers. Each panel receives one common seed and consumes one call per solver, so an incomplete budget remainder stays unspent. Solvers can implement their own replications and return a summary. The example benchmark uses three greedy knapsack solvers. For reproducibility, the solver mapping and callback definitions stay fixed during search.

The workflow is based on Marrero et al.’s discriminatory instance generation. QDpy uses steady-state selection and passive grids for reporting.

Scenario-risk MAP-Elites

qdpy.algorithms.ScenarioRiskMAPElites compares each design on the same fixed panel. Choose objective="mean" to maximize average utility, objective="cvar" to maximize utility in the worst tail, or objective="pareto" with a two-objective qdpy.containers.ParetoGrid to retain the tradeoff between mean and tail utility. Set negative fitness weights to minimize costs and use their upper tail. Descriptors are weighted panel averages for all three modes.

from qdpy.algorithms import ScenarioRiskMAPElites, empirical_cvar
from qdpy.containers import Grid

archive = Grid(shape=5, features_domain=((0., 1.),),
               fitness_domain=((-1., 1.),), fitness_weights=(1.,))
search = ScenarioRiskMAPElites(
    archive, (.1, .5, .9), tail_fraction=.25, objective="cvar",
    initializer=lambda rng: tuple(rng.random(2)),
    mutate=lambda point, rng: (point[0], rng.random()), seed=7,
)

def evaluate(point, stress):
    capacity, reserve = point
    quality = .6 + .2 * capacity - .4 * reserve - max(0., stress - reserve)
    return quality, (capacity,)

stats = search.run(evaluate, 120)
audit = search.audit(evaluate, (.2, .4, .7, .95))
assert stats.scenario_calls == 120 and stats.candidates == 40
assert audit.stats.scenario_calls == 4 * len(archive)
assert empirical_cvar([1., 2., 5., 9.], .375) == 4. / 3.

tail_fraction is the probability mass of the worst tail. In the last line, the tail takes all the mass of the worst outcome and half the mass of the next outcome. The optional probabilities argument assigns unequal weights. Use fixed scenario seeds as part of the scenario objects if the evaluator is stochastic. Provide a separate panel to audit(). The audited archive and per-design measurements come with their own cost counters and use the measured audit descriptors. For Pareto reporting, audit costs scale with the number of elites retained per cell. See Rockafellar and Uryasev’s Optimization of Conditional Value-at-Risk.