Editable archives, preference drift, and component credit ========================================================= An archive can support design changes during search. You can edit a candidate, choose designs to explore, or measure a component in the context of a complete design. The examples here use the base installation and run on CPU. Run them from the checkout. .. code-block:: shell python -m examples.interactive_design all --seeds 5 To run a single comparison, replace ``all`` with ``interactive``, ``surprise``, ``preference``, or ``mortar``. .. _interactive-design-edit: Edit a design and change the archive axes ----------------------------------------- Interactive Constrained MAP-Elites stores feasible and infeasible breeders in grids with matching axes. Feasible candidates compete on fitness. Infeasible candidates compete on total constraint violation. Both populations can produce offspring, which join the population that matches their measured feasibility. Alvarez et al. used this setup in a room editor, where the designer could also change the dimensions and resolution of the archive. `Alvarez2019`_ .. code-block:: python from qdpy.algorithms import DescriptorAxis, InteractiveConstrainedMAPElites from examples.interactive_design import _layout_measure, _layout_mutate, _layout_sample initial_axes = ( DescriptorAxis("density", (0., 1.), 8), DescriptorAxis("symmetry", (0., 1.), 8), ) search = InteractiveConstrainedMAPElites( initial_axes, fitness_domain=(0., 1.), sample=_layout_sample, mutate=_layout_mutate, cell_capacity=3, seed=6, ) search.run(_layout_measure, 120) search.reproject(( DescriptorAxis("reach", (0., 1.), 8), DescriptorAxis("links", (0., 1.), 10), )) edited = tuple(True for _ in range(25)) search.submit(edited, _layout_measure) search.run(_layout_measure, 120) print(search.archive.filled_bins, search.infeasible_archive.filled_bins) print(search.stats) The evaluator returns scalar fitness, a mapping of named measurements, and inequality residuals. A positive residual indicates a violation. Return measurements for any axes you may want to use later. ``reproject()`` reassigns the current residents of both archives with zero evaluator calls. It commits both grids only once their cached measurements have been checked. A reference to a previous grid still lets you inspect its geometry and residents. ``submit()`` spends one evaluation on an edit and uses a successfully measured genome as a breeding anchor. ``anchor_probability`` controls how often offspring mutate that anchor. The other offspring breed from the feasible and infeasible grids, using optional crossover and tournament selection within a populated cell. In the paper, edits also update the target of the dungeon fitness function. This implementation supplies explicit edited-parent breeding and uses the fitness function given by the caller. .. _interactive-design-surprise: Reward unexpected behavior among feasible candidates ----------------------------------------------------- Constrained Surprise Search maintains two breeding populations. Every forecast interval, it snapshots the mean descriptor of the feasible population and extrapolates its motion from the previous snapshot. Feasible candidates that deviate from the forecast are more likely to breed. An independent feasibility objective ranks the infeasible population. `Gravina2016`_ .. code-block:: python from qdpy.algorithms import ConstrainedSurpriseSearch from qdpy.containers import Grid from examples.interactive_design import _layout_measure, _layout_mutate, _layout_sample report = Grid(shape=(8, 8), features_domain=((0., 1.),) * 2, fitness_domain=((0., 1.),), fitness_weights=(1.,)) def evaluate(genome, rollout_seed): fitness, scores, residuals = _layout_measure(genome, rollout_seed) return fitness, (scores["reach"], scores["links"]), residuals search = ConstrainedSurpriseSearch( report, initializer=_layout_sample, mutate=_layout_mutate, population_size=24, forecast_interval=24, seed=4, ) search.run(evaluate, 400) print(search.prediction, search.stats, report.filled_bins) The default infeasible score is negative total positive violation. Pass ``feasibility_score(residuals)`` to supply a different higher-is-better objective. Before a forecast is available, feasible selection uses nearest-neighbor novelty. Forecasts stay fixed between blocks and can be clipped to descriptor bounds. The reporting grid ranks solutions by measured fitness. The published experiment used generation-level forecasts of spatial distributions. This version uses a mean vector and steady-state updates, with the same interface as the FINS control. .. _interactive-design-preference: Model what the user selected ---------------------------- User-Driven Quality Diversity lets users select examples from a current archive. The model embeds the panel and fits a Gaussian process to project newly measured candidates into that fixed space. Selection drift is the distance to the nearest selected design divided by the sum of the distances to the nearest selected and deselected designs. A value near zero indicates proximity to the selected designs. `Hagg2019`_ .. code-block:: python import numpy as np from qdpy.algorithms import UserDrivenQD from qdpy.containers import Grid archive = Grid(shape=(12,), features_domain=((0., 1.),), fitness_domain=((0., 1.),)) search = UserDrivenQD( archive, sample=lambda rng: rng.random(2), mutate=lambda parent, rng: np.clip(parent + rng.normal(0., .12, 2), 0., 1.), seed=5, ) def evaluate(genome, rollout_seed): style, span = genome ideal = .25 if span < .5 else .75 return 1. - (style - ideal) ** 2, (span,) search.run(evaluate, 120) wanted = [i for i, row in enumerate(search.panel) if row[0] < .5] search.choose(wanted, penalty=.8, projection="pca") search.run(evaluate, 240) elite = search.archive.best print(elite.scores["udqd_raw_fitness"], elite.scores["udqd_drift"]) print(search.measured_archive.filled_bins) Choose a nonempty subset and leave at least one deselected design. Each choice starts a fresh active archive seeded with the selected designs. ``penalty=0.`` yields a reseeding-only control. The default projection uses t-SNE, with PCA for small panels. Set ``projection="pca"`` to use a linear embedding throughout. Both use a fixed Matérn kernel to project new examples. Scale decision coordinates to comparable units before fitting. QDpy applies the paper's multiplicative penalty to normalized utility so it works for either fitness direction and for negative raw values. The active elite's ``udqd_raw_fitness`` and ``udqd_drift`` named scores preserve both measurements. ``measured_archive`` always ranks by raw fitness and is useful for checking the coverage and quality trade-off. .. _interactive-design-mortar: Score components in complete designs with MORTAR ------------------------------------------------ A dial puzzle rule might have little effect alone and create a new route when paired with another rule. MORTAR measures the value of a component in context. It expands a tree that adds one component to a design at each step, evaluates each design, and computes Constrained Importance Through Search (CITS). The score averages restricted Shapley contributions across the measured, nonroot nodes where the component occurs. `Nasir2026`_ .. code-block:: python from qdpy.algorithms import MORTAR from qdpy.containers import Grid from examples.interactive_design import _dial_evaluate strides = (-4, -2, 0, 2, 4) library = tuple((stride, phase) for stride in strides for phase in range(3)) archive = Grid(shape=(5, 3), features_domain=((0., 5.), (0., 3.)), fitness_domain=((-2., 2.),)) search = MORTAR( archive, partners=library, composition_budget=10, sample=lambda rng: library[int(rng.integers(len(library)))], mutate=lambda parent, rng: (parent[0], int(rng.integers(3))), describe=lambda genome: (strides.index(genome[0]) + .5, genome[1] + .5), seed=8, ) search.run(_dial_evaluate, 32) print(search.stats) print(search.last_round.credit) Components are hashable genome sequences. The evaluator receives a tuple of components and a seed. It must treat the components as an unordered set and return quality in ``[-1, 1]``, or ``None`` for a failed composition. ``mortar_skill_score()`` computes Kendall's tau-a from the scores of agents ordered from weakest to strongest. Ties contribute zero. The included example uses four node-expansion budgets for the same dial solver. ``run()`` counts component proposals. ``composition_budget`` caps complete-design calls per proposal, including the singleton root. The measured root contributes a baseline value. At least one successful nonroot measurement is needed to produce component credit. Each composition set is measured at most once per tree. CITS uses value zero for unmeasured subsets. These conventions affect the score when the measurement budget is small. The paper used LLMs to generate components and assemble games. The library accepts application callbacks for those tasks. ``generate_partner(components, rng)`` can supply a candidate partner for a specific branch. The built-in example uses a fixed library and works offline. ``selection="random"`` provides a control for UCB branch selection with the same budget and branching limits. .. _interactive-design-results: Paired CPU comparisons ---------------------- These are means over seeds 0–4. Each pair uses the same number of evaluator calls. .. list-table:: :header-rows: 1 * - Workflow - Control - Comparison * - Editable layout (401 evaluations) - Fixed, 7.6 feasible cells - Edit and switch axes, 8.8 feasible cells * - Constrained layout (500 evaluations) - FINS, 11.2 feasible cells - Surprise, 11.0 feasible cells * - Preference (480 evaluations) - Reseeding, .494 mean drift - Reseeding and penalty, .153 mean drift * - Dial puzzle (864 composition evaluations) - Random traversal, .791 mean skill correlation - UCB traversal, .793 mean skill correlation Both layout methods used the same final reporting axes. The edited search evaluated 163.0 feasible candidates, compared with 135.8 in the fixed control. The comparison measures the edit and axis change together. In the second layout test, FINS recorded a slightly higher QD sum (8.54 versus 8.38). In the preference fixture, the penalty increased the fraction of preferred designs in the active archive from half to all, with 16 occupied cells in both cases. Mean raw fitness fell from .850 to .778. The dial puzzle illustrates budget accounting and CITS on repeatable inputs. Its two traversal rules gave similar results. .. _Alvarez2019: https://doi.org/10.1109/CIG.2019.8848022 .. _Gravina2016: https://doi.org/10.1109/CIG.2016.7860408 .. _Hagg2019: https://doi.org/10.1145/3321707.3321823 .. _Nasir2026: https://doi.org/10.1145/3795095.3805100