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
Nonewhen unknown.Predicates built from
trajexpressions report the exact set of keys they need, which letsReplayBuffer.queryfetch only those entries from the storage. Predicates wrapping opaque callables returnNone.