Shortcuts

RandomPolicy

torchrl.envs.utils.RandomPolicy(action_spec: TensorSpec, action_key: NestedKey = 'action')[source]

A random policy for data collectors.

This is a wrapper around the action_spec.rand method.

Parameters:

action_spec – TensorSpec object describing the action specs

Examples

>>> from tensordict import TensorDict
>>> from torchrl.data.tensor_specs import BoundedTensorSpec
>>> action_spec = BoundedTensorSpec(-torch.ones(3), torch.ones(3))
>>> actor = RandomPolicy(action_spec=action_spec)
>>> td = actor(TensorDict({}, batch_size=[])) # selects a random action in the cube [-1; 1]

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources