rollout(env: Environment, policy: Policy, action_repeat: int = 1, max_steps: int | None = None)Run one episode and return it, ready for the replay buffer.
Parameters
envEnvironmentAnything satisfying the protocol.
policyPolicyReset once here, then called per decision.
action_repeatint= 1Environment steps per decision. The papers use 2 for some
Control Suite tasks and 4 for others, and it is not a free
parameter — it sets what one step of the learned dynamics
means, so the same number has to be used when collecting and
when reporting a return.
max_stepsint or None= NoneCut the episode off after this many recorded steps, reported as
truncation rather than termination.
None runs until the
environment says stop.Returns
Episode(T, ...) tensors, with actions[t] the action taken into
step t — so the first entry is a zero vector, because nothing
was taken into the first observation.
Notes
A repeated action is recorded once per environment step, not once per decision, so the stored sequence is at the environment's own rate and a model trained on it predicts single steps.
Examples
>>> import lucid
>>> from lucid.utils.rollout import RandomPolicy, StepResult, rollout
>>> class Trivial:
... def reset(self):
... self.t = 0
... return lucid.zeros((3, 4, 4))
... def step(self, action):
... self.t += 1
... return StepResult(lucid.zeros((3, 4, 4)), 1.0, False, self.t >= 5)
>>> episode, total = rollout(Trivial(), RandomPolicy(2))
>>> len(episode), total
(5, 5.0)