Deep archives and scenario discovery ==================================== Bayesian Deep QD searches for configuration alternatives within a descriptor cell. Mid-evolution descriptor mutation changes what a running archive measures. QD-MAPPER uses a search to build planner benchmarks, and QD-Rec keeps diverse explanations for items in a fixed catalog. All four use the base installation. .. _bayesian-deep-qd: Find conditional designs with Bayesian Deep QD ---------------------------------------------- The evaluator reports one scalar fitness, measured descriptors, and the residuals for the configuration's active constraints. A residual above zero marks a violation. As with Conditional Bayesian QD, models use only the variables that are active in each branch. .. code-block:: python from examples.scenario_discovery import ( CONFIGURATIONS, VARIABLES, evaluate_frame, frame_archive, ) from qdpy.algorithms import BayesianDeepQD archive = frame_archive() search = BayesianDeepQD( archive, 144, VARIABLES, configurations=CONFIGURATIONS, batch_size=4, initial_samples=4, surrogate_budget=80, quality_floor=0., seed=11, ) def evaluate(genome): return evaluate_frame(search.decode(genome)) search.optimise(evaluate) print(search.nb_evaluations, search.deep_archive.configuration_counts) laminated = search.deep_archive.configuration_grid(1) The native archive shows the best candidate per cell. Use ``deep_archive.cell_elites(cell)`` to inspect the configuration alternatives. Each proposal's expected improvement uses its configuration's incumbent when available. For a missing configuration, the acquisition relaxes the reference using the difference between predicted and measured coverage in that branch. ``coverage_multipliers`` exposes the latest adjustment. QDpy uses finite per-branch proposal pools, posterior-mean cell assignment, and probability-of-feasibility weights. Candidates in the same cell may compete independently across configurations during acquisition. The original paper uses constrained optimization of each infill cell. All admissions use actual measured fitness, descriptors, and residuals. Count exact evaluations and surrogate queries separately. `Baraton et al., Enhancing the diversity of solutions in system design optimization `_. .. _descriptor-mutation: Replace one descriptor during MAP-Elites ---------------------------------------- Return fitness and a dictionary of named behavior measurements. Include the active axes in every evaluation. Include likely replacement descriptors when they can be computed from the same rollout. .. code-block:: python from examples.scenario_discovery import FLEX, RISE, SPAN, panel_measurement from qdpy.algorithms import DescriptorMutationMAPElites search = DescriptorMutationMAPElites( (SPAN, FLEX), 3, fitness_domain=(0., 1.), iso_sigma=.11, seed=11, ) search.run(panel_measurement, 72) change = search.switch_axis("flex", RISE) search.run(panel_measurement, 72) print(change.projected_elites, change.refresh_evaluations, search.archive.filled_bins) The switch projects elites onto the unchanged axes, keeps each projected cell's highest-quality member, and transfers those members to a grid with the replacement axis. When an axis is the only one, only the best elite survives the projection. The successful switch replaces the active grid. An earlier grid reference keeps the previous archive. For missing replacement descriptors, provide ``refresh(genome, seed)`` returning that descriptor and set ``refresh_budget``. The entire missing set must fit before refresh starts. If a callback raises, the previous archive remains active and completed or failed refresh attempts remain counted. Future offspring need to return the new active measurement. Use ``report(axes)`` to compare retained elites in a common geometry without new calls. `Van der Bank and Nitschke, Dynamic Descriptor Mutations Improve Automated Quality-Diversity `_. .. _qd-mapper: Generate paired planner benchmarks with QD-MAPPER ------------------------------------------------- Supply a map generator, a seeded case builder, and one or two planners. Planner callbacks return a finite cost, with higher costs meaning harder cases. For two planners, the default objective is the mean cost for the first minus the mean cost for the second. .. code-block:: python import numpy as np from examples.map_and_catalog_qd import joint_cost, map_case, map_features, priority_cost from qdpy.algorithms import ConnectedMapRepair, NeuralCellularMap, QDMapper from qdpy.containers import Grid pattern = np.indices((5, 5)).sum(axis=0) % 2 generator = NeuralCellularMap(pattern, iterations=2) repair = ConnectedMapRepair(pattern.shape, (2, 11)) archive = Grid(shape=(6, 6), features_domain=((0., .5), (0., 1.)), fitness_domain=((-1.25, 1.25),), fitness_weights=(1.,)) search = QDMapper( archive, generator.dimension, generate=generator, repair=repair, make_case=map_case, describe=map_features, planners=(priority_cost, joint_cost), panel_size=4, seed=11, ) print(search.run(30, proposal_budget=600)) print(search.audit(archive.best.scores["layout"], range(50000, 50016))) The cellular automaton applies shared local rules to a fixed seed map. An obstacle is 1 and an open cell is 0. The repair solver finds a minimum-edit connected layout with an open root and the requested obstacle range. Use a custom generator or repair callback if your maps need different rules. QDpy uses bounded Iso+LineDD as the search operator and a small NumPy automaton. The paper searches larger neural generators with CMA-MAE. The map budget counts distinct repaired layouts sent to a planner panel. Keep a separate proposal cap when the generator or repair yields many repeats. Both planners receive the identical case on each layout. Use fresh seeds with ``audit`` and report those planner calls separately. Each elite stores the actual evaluated layout, so audits reuse it directly. `Qian et al., QD-MAPPER, AAMAS 2026 `_. .. _qd-rec: Explore catalog explanations with QD-Rec ---------------------------------------- Give the bandit a fixed item embedding for every catalog identifier. Give the archive a separate embedding for the entire item–hypothesis pair. The generator and evaluators can be ordinary Python functions. .. code-block:: python from qdpy.algorithms import QDRec, Recommendation search = QDRec(("examples", "exercises"), ((1., 0.), (0., 1.)), seed=11) def propose(item, parents, rng): angle = rng.choice(("short reference", "hands-on practice")) return f"{angle} for {item}" def score(pair): return .85 if pair.hypothesis.startswith("hands-on") else .55 def embed(pair): return (float(pair.item == "examples"), float(pair.item == "exercises"), float(pair.hypothesis.startswith("hands-on"))) def novel(candidate, neighbors): return all(embed(candidate) != embed(other) for other in neighbors) def compare(first, second): return int(score(second) > score(first)) search.run(propose, score, embed, novel, compare, budget=10, initial=(Recommendation("examples", "short reference for examples"),)) print(search.best.recommendation, search.stats) The bandit samples a linear predictor from its posterior and adds distance to the nearest archived item. The novelty judge receives nearby recommendations. On a non-novel result, the pairwise judge receives the candidate and its nearest competitor in random order, without their scores. Return the winning index. The bandit learns from all fully processed scores, including rejections. Exact repeated item–hypothesis pairs spend proposal calls and reuse previous feedback. Count scoring, novelty, and comparison calls separately. For a uniform-selection control use ``selection="uniform"``. Set ``exemplars=0`` to omit archive parents from the generator. `Ishida et al., QD-Rec `_. Run the comparisons ------------------- .. code-block:: bash python -m examples.scenario_discovery depth python -m examples.scenario_discovery descriptors python -m examples.map_and_catalog_qd maps python -m examples.map_and_catalog_qd catalog See :doc:`scenario_discovery_benchmarks` for seeds, budgets, and results. Use :ref:`adaptive-diversity-equal` to give each configuration an equal share of the exact evaluation budget.