Ordered trajectories and model-guided variation =============================================== The shared example compares descriptors on the same paths, measures continuous-control policies, and times Bayesian search. Path signatures and MCBO-Elites use the base install. AURORA-XCon needs PyTorch, and ASCII-ME uses the existing QDpy RL extra. .. code-block:: bash python examples/ordered_qd.py trajectory --seeds 7 13 23 python examples/ordered_qd.py bayesian --seeds 7 13 23 uv run --extra rl python examples/ordered_qd.py aurora --seeds 7 13 23 uv run --extra rl python examples/ordered_qd.py control --batch-sizes 4 16 See :doc:`ordered_qd_benchmarks` for the budgets and results. .. _ordered-qd-path-signatures: Path-signature CVT-MAP-Elites ----------------------------- An endpoint tells you where a trajectory finishes. An occupancy descriptor records where it spends time. A path signature records the order of changes in observation channels. For example, a clockwise loop and its reversal have the same occupancy and endpoint. Their second-level cross-channel coefficients have opposite signs. .. code-block:: python import numpy as np from qdpy.algorithms import PathSignature, PathSignatureMAPElites square = np.array([[0., 0.], [1., 0.], [1., 1.], [0., 1.], [0., 0.]]) encoder = PathSignature(observation_size=2, order=2) archive = encoder.make_archive([square, square[::-1]], cells=2, seed=7) def evaluate(genome): size, direction = genome path = square if direction < 0.5 else square[::-1] return size, path * size search = PathSignatureMAPElites(archive, budget=96, dimension=2, signature=encoder, seed=7) search.optimise(evaluate) print(archive.filled_bins, encoder.encode(square), encoder.encode(square[::-1])) Use an independent set of reference paths to fit the CVT centroids or provide explicit centroids to a native ``CVTGrid``. All rollouts should use the same channel scales. The second level has one coefficient per pair of input channels. Add ``time_channel=True`` when timing or out-and-back motion matters. The encoder uses normalized elapsed time, and ``encode(path, times=...)`` accepts irregular sample times. Manual ask/tell can use those encoded coefficients directly. The automatic evaluation adapter assumes equally spaced samples. Signatures as implemented are translation invariant and truncated at level two. Feiden, Paparella, and Garcke introduced the use of path signatures for QD and assessed repertoire robustness under environment changes. `Generalizing Diversity with the Signature Transform (GECCO 2024) `_. .. _ordered-qd-aurora-xcon: AURORA-XCon ----------- When suitable descriptors are unclear, AURORA learns a compact representation of the observations and periodically re-encodes the live repertoire. AURORA-XCon changes how the encoder learns and how the archive renews itself. The triplet loss brings trajectories with similar fitness closer together and separates those with dissimilar fitness. At pruning events the best solution and a random subset survive. .. code-block:: python from qdpy.algorithms import AuroraXCon def evaluate(genome, rollout_seed): x, y = genome reward = 1.0 - (x - 0.8)**2 - (y - 0.2)**2 return reward, [(0., 0.), (x, 0.), (x, y)] search = AuroraXCon(2, initial_samples=24, training_period=32, extinction_period=128, target_size=16, seed=7) stats = search.run(evaluate, budget=480) print(stats.refits, stats.pruned, search.archive.best.fitness.values) Return a fixed-shape finite trajectory scaled to ``[-1, 1]`` and a scalar fitness to maximize. Pass the supplied seed to stochastic evaluators. A failed measurement can return ``None``. After warmup, the default size controller adjusts the novelty radius as the live archive grows or shrinks. Set ``size_gain=0`` for a fixed radius. Use ``loss="reconstruction"`` for the reconstruction control and ``extinction_period=0`` to disable pruning. Triplets need at least three live examples, and ties between the two fitness distances skip that triplet. The model refits from the live archive and recreates its container. Read ``search.archive`` after the refit to obtain the current container. Use a fixed reporting descriptor outside the search when comparing coverage across encoders. The reference implementation also studies actor-critic variation. The QDpy implementation uses Iso+LineDD and a fixed refit period with a bounded, nearest-neighbour repertoire. `Coiffard, Templier, and Cully, AURORA-XCon (GECCO 2025) `_. `Grillotti and Cully, AURORA container size control `_. .. _ordered-qd-ascii: ASCII-ME -------- ASCII-ME starts from a measured archive policy. It samples a donor trajectory from the previous evaluation batch, including its rejected candidates. The operator evaluates the parent on the donor's recorded observations. It weights action differences using discounted rewards-to-go, state similarity, and an action kernel. Backpropagation maps that direction to policy parameters. The resulting child still needs a live evaluation before admission. .. code-block:: python import gymnasium as gym import numpy as np from qdpy.containers import Grid from qdpy.rl import ASCIIME, PolicyConfig archive = Grid( shape=(10, 6), features_domain=((-1., 1.), (0., 1.)), fitness_domain=((-1000., 0.),), fitness_weights=(1.,), ) def descriptor(episode): return episode.observations[-1, 0], np.abs(episode.actions).mean() / 2. search = ASCIIME( lambda: gym.make("Pendulum-v1"), archive, descriptor=descriptor, policy=PolicyConfig((32,)), max_episode_steps=50, initial_policies=8, batch_size=8, gradient_batch_size=4, seed=7, ) stats = search.train(max_env_steps=2000) search.best_policy().save("ascii-policy.npz") print(stats.env_steps, stats.optimizer_steps) Policies use a finite Box action space and one scored episode per candidate. Action distances use coordinates normalized to ``[-1, 1]``, and unequal trajectories use their common prefix. The gradient step is vectorized across offspring. Use ``gradient_batch_size`` to bound its memory. Environment calls follow QDpy's synchronous Gymnasium rollout loop. The ``device`` argument selects where the actor and offline updates run. `Mitsides, Faldor, and Cully, ASCII-ME (GECCO 2025) `_. .. _ordered-qd-mcbo: MCBO-Elites ----------- Use MCBO-Elites for bounded numeric search when true evaluations are costly. Each measured fitness and descriptor updates the sparse posterior. For each candidate in a Sobol pool, the acquisition scores samples of the objective and descriptors. A sample earns credit for predicted improvement in the cell to which its descriptor actually maps. .. code-block:: python from qdpy.algorithms import MCBOElites from qdpy.containers import Grid archive = Grid( shape=(8, 8), features_domain=((0., 1.), (0., 1.)), fitness_domain=((0., 1.),), fitness_weights=(1.,), ) def evaluate(genome): x, y, z = genome return (1.0 - (z - 0.25 - 0.5 * x)**2,), (x, y) search = MCBOElites(archive, budget=96, dimension=3, ind_domain=(0., 1.), quality_floor=0.0, inducing_points=24, seed=7) search.optimise(evaluate) print(search.stats, archive.filled_bins) The QDpy variant uses fixed Sobol inducing locations, a shared RBF kernel, independent output posteriors, and fixed observation noise in the scaled outputs. Model updates accumulate sufficient statistics, keeping the surrogate state independent of the number of observations. The optimizer remembers proposed genomes to avoid duplicates. A CVT grid with explicit centroids also works. Descriptor bounds are finite. The quality floor and objective scale refer to signed fitness, so minimizing an objective uses the corresponding negative quality. A batch scores one candidate pool against the current archive. Use one evaluation per batch when the evaluator is so expensive that it is worth incorporating every observation before selecting the next one. `Palmas et al., MCBO-Elites (GECCO 2025) `_. `Bui, Nguyen, and Turner, streaming sparse Gaussian process approximations `_.