Return to promising states with Go-Explore¶
Go-Explore addresses sparse exploration by saving cells that the search has reached. Each round chooses a saved cell, returns to its state, then tries new actions from there. QDpy provides this exploration phase with a small Gymnasium-style interface. It can also run with a plain Python environment.
The following task requires five actions of the same kind in sequence. The observation gives the current progress. Its value is a useful cell key.
from qdpy.algorithms import GoExplore
class Sequence:
def reset(self, *, seed):
self.progress = 0
return self.progress, {}
def step(self, action):
self.progress = self.progress + 1 if action == 1 else 0
solved = self.progress == 5
return self.progress, float(solved), solved, False, {}
def close(self):
pass
search = GoExplore(
Sequence, cell=lambda observation, info: observation,
sample_action=lambda observation, info, rng: int(rng.integers(2)),
exploration_steps=3, max_trajectory_steps=20, seed=11,
)
stats = search.explore(250)
print(stats.exploration_steps, stats.replay_steps, stats.occupied_cells)
print(search.best.actions, search.best.return_)
With deterministic replay, each return starts from the same reset seed
and replays the saved prefix. Replay and exploration both spend the
step budget. A changed cell or cumulative reward raises an error.
The archive records the highest-return path to each cell, with a
preference for shorter paths at equal return. The curriculum prefers
cells selected or visited less often. Terminal paths remain available
through cells and best for inspection.
If the environment exposes a snapshot API, pass snapshot(env) and
restore(env, snapshot). The restore callback returns the restored
observation and info. Save the full simulator and wrapper state, including
random generator state and counters. A snapshot must be copyable and
restorable in a fresh environment from the same factory. Snapshot
restoration uses zero env.step calls. A subsequent policy training
phase for robust deployment is outside this exploration workflow.
See Repertoire adaptation, gradient search, and exploration benchmarks for the sparse sequence comparison.
Ecoffet et al., First return, then explore, Nature 2021. Go-Explore: a New Approach for Hard-Exploration Problems, Appendix A.5.