Share policy representations with RefQD¶
RefQD stores the final linear decision layer of each policy. All heads use the same trainable encoder. A cell keeps up to four heads by default. Each saved head includes its measured fitness, descriptor, and the encoder version used to produce those measurements.
Install qdpy[rl] and try the CPU example. It compares RefQD with
full-policy PGA-MAP-Elites on short Pendulum episodes.
python -I examples/refqd.py --steps 8192
import gymnasium as gym
import numpy as np
from qdpy.containers import Grid
from qdpy.rl import PolicyConfig, RefQD
grid = Grid(shape=(8,), fitness_domain=((-500., 0.),),
features_domain=((-2., 2.),))
trainer = RefQD(
lambda: gym.make("Pendulum-v1", max_episode_steps=16),
grid, descriptor=lambda episode: (float(np.mean(episode.actions)),),
policy=PolicyConfig((16,)), max_episode_steps=16,
refresh_every=2, seed=11,
)
trainer.train(256)
cell = next(iter(trainer.heads))
actor = trainer.policy_for(cell)
measured = trainer.audit(128, seed=917)
print(measured.steps, len(measured.archive))
Training spends one budget on offspring and refreshes. A refresh
reevaluates the highest-ranked heads under the current encoder and
moves them to their newly measured cells. Lower-ranked records keep
their last measurement until selected for refresh.
audit() evaluates the top head of each cell with the current encoder
and an independent seed. Use its fresh scores to compare deployment.
The returned policy can be saved with ContinuousPolicy.save().