Rate this Page

TrajectoryPredicate#

class torchrl.data.TrajectoryPredicate(fn: Callable[[Trajectory], bool], description: str = 'predicate', keys: frozenset | None = None)[source]#

A boolean predicate over a Trajectory.

Predicates are produced by comparing trajectory expressions (see traj) and compose with & (and), | (or) and ~ (not).

Examples

>>> predicate = (traj.reward.sum() > 100) & (traj.length < 200)
>>> predicate(trajectory)
True
>>> predicate.required_keys()
frozenset({'reward'})
required_keys() frozenset | None[source]#

The data keys the predicate reads, or None when unknown.

Predicates built from traj expressions report the exact set of keys they need, which lets ReplayBuffer.query fetch only those entries from the storage. Predicates wrapping opaque callables return None.