Compact repertoires and skill composition

Set-scalarized QD returns a fixed-size portfolio of measured designs. RePPO returns a fixed-size population of PPO actors. QDOS uses recorded trajectories to learn skills for an online controller, while MIQD evolves teams with gradient updates guided by short trajectory fragments.

A design portfolio with SSoM and STCH-Set

Choose a panel of behavior targets and a small initial population. The evaluator returns a quality, a descriptor vector, and their Jacobian with respect to the genome. Every design contributes to each target, with quality discounted by a Gaussian of descriptor distance.

import numpy as np

from examples.set_scalarized_design import design
from qdpy.algorithms import set_scalarized_search

points = np.random.default_rng(11).uniform(.2, .8, (6, 2))
targets = np.linspace(0., 1., 65)[:, None]
result = set_scalarized_search(
    design, points, targets, epochs=72, bandwidth=.15, smoothing=.04,
    scalarization="stch-set", reference=np.full(len(targets), -1.25),
)
print(result.evaluations, max(result.target_costs))

The target cost is the negative discounted quality. Smooth Sum-of-Minimum (scalarization="ssom") minimizes the sum of smooth best costs across targets. Smooth Tchebycheff Set ("stch-set") minimizes a smooth maximum shortfall from a per-target reference cost. Supply fixed reference costs when comparing runs. When the reference is omitted, QDpy freezes each target’s initial best cost minus the smoothing temperature.

Each projected Adam step reevaluates the whole set once. The final result includes unsmoothed target costs and can populate an optional Grid or CVTGrid. Use an independent target panel to audit the portfolio. Set a fitness floor in signed quality units if the objective can produce negative quality after accounting for maximization or minimization.

Lin et al., Quality-Diversity Optimization as Multi-Objective Optimization.

Train a compact PPO population

Install qdpy[rl]. RePPO requires a single-environment factory and a bounded behavior signal at each step. Here the simulator reports the executed travel command in its step information. The same callback works for a Box actor and the MultiDiscrete version of the environment.

from examples.compact_policy_search import TwoRoutes, route_feature
from qdpy.rl import PPOConfig, PolicyConfig, RePPO

learner = RePPO(
    lambda: TwoRoutes(discrete=True),
    feature=route_feature, feature_bounds=((-1., 1.),),
    population_size=4, bandwidth=1.2, repulsion_cap=1.,
    policy=PolicyConfig((16,)),
    ppo=PPOConfig(rollout_steps=48, epochs=3, batch_size=24, learning_rate=.003),
    max_episode_steps=6, seed=11,
)
print(learner.train(2304).policy_steps)
for index, actor in enumerate(learner.policies()):
    actor.save(f"route-{index}.npz")

RePPO tracks each member’s completed-episode return and average behavior. It computes local Gaussian repulsion in logit coordinates and maps the resulting directions back to the behavior features. Each actor uses one task GAE channel and one channel per feature. RePPO recomputes the weights after collecting a population rollout and holds them fixed across the minibatch updates. Only completed episodes affect the population summaries. A rollout cut still contributes to PPO with the appropriate value bootstrap.

Set repulsion_cap=0. for the independent-PPO control. MultiDiscrete uses QDpy’s joint log probability over independent categorical factors. The Box version uses its bounded Gaussian actor. Reload each actor with CategoricalPolicy.load or ContinuousPolicy.load.

Hedayatian et al., Repulsive Population Policy Gradients.

Compose offline skills with QDOS

Record complete Episode objects with one more observation than action. Keep the actual successor observation before reset and preserve the termination and truncation flags. The example’s four-step task requires moving left during the first skill window and right during the second.

from examples.compact_policy_search import TwoGates, gate_log
from qdpy.rl import PolicyConfig, QDOS, QDOSConfig, QDOSPolicy, SACConfig

learner = QDOS(
    TwoGates, episodes=gate_log(11), max_episode_steps=4, seed=11,
    config=QDOSConfig(skill_horizon=2, latent_size=1, batch_size=32,
                      learning_rate=.003),
    policy=PolicyConfig((24, 24)),
    sac=SACConfig(batch_size=32, replay_capacity=4000, learning_starts=32,
                  critic_hidden_sizes=(24, 24), actor_learning_rate=.002,
                  critic_learning_rate=.002, initial_temperature=.05),
)
learner.pretrain(550)
stats = learner.train(2304)
print(stats.offline_updates, stats.online_skills, stats.env_steps)
learner.policy().save("two-gates.npz")

controller = QDOSPolicy.load("two-gates.npz")
environment = TwoGates()
observation, _ = environment.reset(seed=9000)
controller.reset()
action = controller.act(observation)
environment.close()

QDOS splits each logged episode into full, nonoverlapping skill segments and reports any leftover recorded steps. Implicit Q-learning estimates advantage at the segment level. A state-conditioned prior, trajectory encoder, and bounded Gaussian decoder learn skills. The latent-recovery objective decodes random codes on logged states, which keeps pretraining entirely offline. The decoder freezes before online training.

The SAC actor picks a code and holds it for the skill horizon, or until the simulator ends the episode. It trains on live skill transitions and labeled logged segments. Offline rewards come from a learned reward model with a random network distillation bonus. Set optimism=0. to reuse recorded segment rewards. The critic uses the actual skill duration for its discount and bootstraps across time limits. An interrupted budget prefix is counted and left out of replay.

Call controller.reset() when the environment resets. Use select_skill(observation) to inspect the high-level choice and act_skill(observation, code) to test a fixed code. The saved artifact includes both actors and the skill horizon.

Anakewat, Osa, and Harada, Learning Hierarchical Skill Policies with Offline Quality-Diversity Reinforcement Learning.

Use trajectory fragments to guide cooperative teams

Provide a Gymnasium environment with a fixed leading agent axis in both Box spaces. Each agent receives a local observation, and the simulator returns one team reward. Supply an episode descriptor for the archive and a state feature callback in the same coordinates for fragment learning. In the relay example, the episode descriptor averages each role’s commands. The feature callback reads each role’s most recent command, so the fragment critic also sees who acted during a particular phase.

from examples.compact_policy_search import RelayTeam, role_feature, team_descriptor
from qdpy.containers import Grid
from qdpy.rl import MIQD, PolicyConfig, TD3Config

archive = Grid(shape=(8, 8), features_domain=((-1., 1.),) * 2,
               fitness_domain=((0., 6.4),), fitness_weights=(1.,))
learner = MIQD(
    RelayTeam, archive, descriptor=team_descriptor, fragment_feature=role_feature,
    fragment_radius=1, target_neighbors=3, population_size=6,
    policy=PolicyConfig((12,)), critic_steps=4, gradient_steps=2,
    td3=TD3Config(batch_size=16, learning_starts=16, replay_capacity=4000,
                  critic_hidden_sizes=(24,), actor_learning_rate=.005),
    initial_sigma=.32, anchor_interval=3, information_weight=.15,
    max_episode_steps=4, seed=11,
)
print(learner.train(2304).information_updates)
learner.best_policy().save("relay-team.npz")

MIQD applies two centered means within each episode. The critic uses a learned density-ratio reward from matched state-action and fragment pairs, with shuffled fragment labels for the marginal samples. Target values use the highest clipped twin-critic estimate among nearby archived teams. Gradient offspring start from archived policies. Weighted team CEM fits a diagonal Gaussian to the best measured teams. The archive records the external team score and the episode descriptor. Compare with MASQD and with information_weight=0. to see how the fragment reward affects your task.

Chen et al., Quality-Diversity for Multi-Agent Reinforcement Learning, AAMAS 2026.

Run the comparisons

python -m examples.set_scalarized_design
python -m examples.compact_policy_search population
python -m examples.compact_policy_search hierarchy
python -m examples.compact_policy_search team

See Compact repertoire benchmarks for seeds, budgets, and results.