Refine diverse starts and coevolve complementary solutions

Use an archive to choose starting points for a local solver, learn which prompts produce useful architectures, or evolve models against changing assessments. QDpy also provides seeded centroid generators for Voronoi archives and an optional cooperative actor-critic method that allocates updates using local observation novelty.

Generate Voronoi sites without fitting k-means

qdpy.containers.generate_centroids() generates sites in a unit cube and scales them to the feature domain. Pass the result to CVTGrid as precomputed centroids. Use scrambled Sobol or Halton sequences, or choose method="blue-noise" to add the most separated point from a small pool at each step. method="uniform" provides a random control. For reproducibility, save the generated sites along with the archive. [Mouret2023]

from qdpy.containers import CVTGrid, generate_centroids

domain = ((-1., 1.), (0., 10.))
sites = generate_centroids(128, domain, method="sobol", seed=11)
archive = CVTGrid(shape=128, centroids=sites, features_domain=domain,
                  fitness_domain=((0., 1.),), fitness_weights=(1.,))

Intervals need positive finite spans. Sobol accepts arbitrary site counts. The helper takes a prefix of the next power-of-two block. A complete power-of-two block retains the sequence’s balance properties. These are direct Voronoi site generators. Cell volumes depend on the site layout and domain geometry. The default k-means initialization in CVTGrid remains available.

Refine diverse initial designs with QDID

qdpy.algorithms.qd_seeded_refinement() first fills a seed archive with measured designs. It then sends one representative per selected niche to a local solver. The original QDID method uses finite-element analysis to score structural seeds and SIMP to refine them. This interface accepts custom evaluation and refinement callbacks so it can also be used with simulation, fitting, and other local solvers. [Xie2024]

from scipy.optimize import minimize
from qdpy.algorithms import qd_seeded_refinement
from qdpy.containers import Grid

def grid():
    return Grid(shape=(10,), features_domain=((0., 1.),),
                fitness_domain=((0., 1.),), fitness_weights=(1.,))

def evaluate(point):
    x, = point
    return (1. - min((x - .2)**2, (x - .8)**2),), (x,)

def refine(start, objective, rng):
    minimize(objective, start, bounds=[(0., 1.)], method="L-BFGS-B")

result = qd_seeded_refinement(
    grid(), grid(), evaluate, refine, dimension=1, search_budget=40,
    starts=4, refinement_budget_per_start=15, seed=11,
)
print(result.search_evaluations, result.refinement_evaluations)

The solver receives a minimization objective. It should send each trial through that callback. The search records the best feasible measured trial or retains the seed if it remains best. Solver return values are advisory. All evaluator attempts, including failures, count within their stage budgets. Proposals outside the configured decision bounds return infinity to the local solver without an evaluator call. Use seed_selection="random" for matched-budget random restarts. The random control can pick several starts from one niche. The archive control can run fewer solves if too few niches have filled.

Learn which prompts produce useful architectures

qdpy.algorithms.llmatic() evolves two archives. One stores architectures by structural descriptors and validation quality. The other stores prompt templates and generation temperatures. Mutation uses one architecture parent. Crossover uses an anchor and nearby architectures in normalized descriptor coordinates. [Nasir2024]

from qdpy.algorithms import llmatic

result = llmatic(
    architecture_grid, prompt_grid, initial=((16,), "relu"),
    prompts=("change width", "add or remove a layer"),
    generate=propose_architecture, evaluate=score_architecture,
    proposal_budget=160, evaluation_budget=60, seed=11,
)
print(result.evaluations, result.duplicates, result.prompt_curiosity)

The generation callback receives an LLMaticRequest with immutable parents, the instruction, the temperature, and a crossover flag. Return an immutable architecture specification or None for a rejected reply. The evaluation callback returns scalar quality and a descriptor vector, such as width divided by depth and a floating-point operation count. It can train the architecture or look it up in a fixed NAS table. Model providers can be attached using the callback pattern in Language models for context rewrites, ideas, and benchmark tasks. The example uses a local typed generator and trains ridge readouts on frozen features.

Choose a prompt grid that covers [0, 1] on both descriptor axes and can store growing integer fitness values. Curiosity is shared by all temperatures of a template. Archive gains reward the template, and rejected or invalid proposals reduce its curiosity. A measured model that exceeds the previous batch’s best score adds a prompt credit. The runner counts generator calls and evaluates each distinct architecture at most once. Setting prompt_exploration=1. selects templates uniformly and provides a control for curiosity-based selection.

Coevolve models and assessments with AC/DC

qdpy.algorithms.acdc() evaluates new models against a common active task panel and keeps specialists that solve tasks missed by fitter models. The novelty score uses each task’s failure rate as its weight. The best model is retained. New tasks need a novel descriptor and at least one passing model to enter the active panel. A separate historical archive retains all admitted tasks. [Dai2026]

from qdpy.algorithms import acdc

result = acdc(
    seed_models, seed_tasks, vary_model=merge_and_mutate,
    propose_task=generate_task, evaluate=check_answer,
    task_descriptor=describe_task, valid_task=check_task,
    budget=240, rounds=20, team_size=3, team_budget=100, seed=11,
)
print(result.assessments, result.team_assessments, result.team_coverage)

A task proposal receives an ACDCTaskRequest with a parent, reference tasks, the parent’s pass rate, and a request for a harder, easier, or novel variant. Keep tasks and models immutable and make scores deterministic for each pair. A task descriptor must be a nonzero vector of fixed length for cosine novelty. Use valid_model to screen unusable models and valid_task to check tasks independently of model success. This variant accepts caller-supplied variation, scoring, and validation. The example uses arithmetic tasks and bounded specialists.

Search admits a candidate only after its full set of assessments fits the remaining budget. A cached pair never spends another assessment. Final greedy team selection covers as many tasks as possible with team_size models. If the missing historical pairs fit team_budget, it can select from the historical archives. Otherwise it uses the complete active panel. Use the returned team_tasks to see which tasks underlie the reported coverage. Assess generalization on an independent panel. Set propose_task=None for fixed tasks, or selection="quality" to select only by the fraction of tasks solved.

Allocate cooperative learning updates with MADECM

Install qdpy[rl] for qdpy.rl.MADECM. The environment should return one team reward. Its numeric observation and continuous bounded action spaces need the same leading agent axis, with fixed agent order and equal observation and action width per role. Each role’s actor sees only its own observation, while the centralized critic sees all observations and actions during training. [Wu2026]

from qdpy.rl import MADECM, MADECMConfig, MADECMPolicy

search = MADECM(
    make_team_environment, archive, descriptor=describe_team_episode,
    config=MADECMConfig(batch_size=32, extra_updates=4),
    max_episode_steps=60, population_size=3, seed=11,
)
print(search.train(12_000))
search.best_policy().save("team.npz")
actor = MADECMPolicy.load("team.npz")

After a noisy learning episode, fixed random target networks and trained predictors estimate novelty on each agent’s local replay observations. Every role receives one centralized critic and actor update. The extra_updates are then allocated in proportion to the prediction errors. Set allocation="uniform" to control for the same number of updates allocated uniformly across roles.

The QDpy variant uses a staged schedule with one learning rollout, one learned-team evaluation, then archive variation. Only complete evaluations enter the archive. Archive fitness comes from measured environment returns or the caller’s episode fitness. Training and evaluation steps have one shared environment budget. Calls to train() can resume between complete stages. Policy exports contain the local actors, so inference works independently of replay and the critics.

Reproduce the CPU comparisons

The example script writes one JSON record per seed and configuration. Only the team comparison uses the RL extra. The runs below used CPython 3.12, NumPy 2.5.5, SciPy 1.18.1, scikit-learn 1.9.1, and PyTorch 2.15.0 on a Linux x86-64 CPU.

python examples/coupled_search.py centroids --seeds 11 22 33 44 55
python examples/coupled_search.py starts --seeds 11 22 33 44 55
python examples/coupled_search.py architectures --seeds 11 22 33 44 55
python examples/coupled_search.py tasks --seeds 11 22 33 44 55
python examples/coupled_search.py teams --seeds 11 22 33 44 55

For 64 Voronoi sites, the median setup time for k-means was 39 ms in two dimensions and 69 ms in twelve. Sobol, Halton, and blue noise took 0.7–1.5 ms and 1.3–2.3 ms, respectively. Across 12,000 uniform probes, k-means produced the most even estimated cell volumes. The mean coefficient of variation was 0.14 in two dimensions and 0.11 in twelve. Among the direct generators, Sobol was most even in two dimensions at 0.21 and Halton in twelve at 0.51.

QDID and its control both used 96 seed evaluations and 78 local solver calls per seed. QDID reached all six basins in every run. The random starts reached 3.6 on average.

At 56 trained architectures per seed, curiosity-based prompt selection filled 18.8 cells on average and the uniform control filled 18.2. Best validation accuracy averaged 84.1% and 85.0%, respectively. Curiosity used an average of 88.2 proposal calls, compared with 80.0 for the uniform control.

The AC/DC variants shared a cap of 176 model-task assessments. They used between 172 and 175.2 assessments on average, depending on how many new pairs remained reachable. The evolving task panel admitted a mean 4.4 new tasks with novelty-based model selection. On a separate twelve-task audit, coevolution and quality-only selection covered 51.7% on average. The fixed-task control covered 75.0%.

The two MADECM allocations both used 960 environment steps, 234 actor updates, and 546 total optimizer updates per seed. In the 96-step held-out audit, the mean team return was 4.26 with curiosity allocation and 4.07 with uniform allocation. The two archives filled about 36 cells each. These comparisons exercise the methods on small CPU fixtures.