DMControlWrapper¶
- torchrl.envs.DMControlWrapper(*args, **kwargs)[源代码]¶
DeepMind Control 实验室环境封装器。
DeepMind 控制库可在以下位置找到:https://github.com/deepmind/dm_control。
论文:https://arxiv.org/abs/2006.12983
- 参数:
env (dm_control.suite env) –
Task
环境实例。- 关键字参数:
from_pixels (bool, optional) – 如果为
True
,将尝试从 env 返回像素观测。默认情况下,这些观测将写入"pixels"
条目下。默认为False
。pixels_only (bool, optional) – 如果为
True
,则只返回像素观测(默认在输出 tensordict 的"pixels"
条目下)。如果为False
,则在from_pixels=True
时返回观测(例如,状态)和像素。默认为True
。frame_skip (int, optional) – 如果提供,表示相同的动作将重复多少步。返回的观测将是序列的最后一次观测,而奖励将是跨步骤的奖励总和。
device (torch.device, optional) – 如果提供,则数据将转换到该设备上。默认为
torch.device("cpu")
。batch_size (torch.Size, optional) – 环境的批量大小。应与所有观测、完成状态、奖励、动作和信息的领先维度匹配。默认为
torch.Size([])
。allow_done_after_reset (bool, optional) – 如果为
True
,则允许在调用reset()
后立即将 env 设置为done
状态。默认为False
。
- 变量:
available_envs (list) – 一个表示可用环境/任务对的列表,格式为
Tuple[str, List[str]]
。
示例
>>> from dm_control import suite >>> from torchrl.envs import DMControlWrapper >>> env = suite.load("cheetah", "run") >>> env = DMControlWrapper(env, ... from_pixels=True, frame_skip=4) >>> td = env.rand_step() >>> print(td) TensorDict( fields={ action: Tensor(shape=torch.Size([6]), device=cpu, dtype=torch.float64, is_shared=False), next: TensorDict( fields={ done: Tensor(shape=torch.Size([1]), device=cpu, dtype=torch.bool, is_shared=False), pixels: Tensor(shape=torch.Size([240, 320, 3]), device=cpu, dtype=torch.uint8, is_shared=False), position: Tensor(shape=torch.Size([8]), device=cpu, dtype=torch.float64, is_shared=False), reward: Tensor(shape=torch.Size([1]), device=cpu, dtype=torch.float64, is_shared=False), terminated: Tensor(shape=torch.Size([1]), device=cpu, dtype=torch.bool, is_shared=False), truncated: Tensor(shape=torch.Size([1]), device=cpu, dtype=torch.bool, is_shared=False), velocity: Tensor(shape=torch.Size([9]), device=cpu, dtype=torch.float64, is_shared=False)}, batch_size=torch.Size([]), device=cpu, is_shared=False)}, batch_size=torch.Size([]), device=cpu, is_shared=False) >>> print(env.available_envs) [('acrobot', ['swingup', 'swingup_sparse']), ('ball_in_cup', ['catch']), ('cartpole', ['balance', 'balance_sparse', 'swingup', 'swingup_sparse', 'three_poles', 'two_poles']), ('cheetah', ['run']), ('finger', ['spin', 'turn_easy', 'turn_hard']), ('fish', ['upright', 'swim']), ('hopper', ['stand', 'hop']), ('humanoid', ['stand', 'walk', 'run', 'run_pure_state']), ('manipulator', ['bring_ball', 'bring_peg', 'insert_ball', 'insert_peg']), ('pendulum', ['swingup']), ('point_mass', ['easy', 'hard']), ('reacher', ['easy', 'hard']), ('swimmer', ['swimmer6', 'swimmer15']), ('walker', ['stand', 'walk', 'run']), ('dog', ['fetch', 'run', 'stand', 'trot', 'walk']), ('humanoid_CMU', ['run', 'stand', 'walk']), ('lqr', ['lqr_2_1', 'lqr_6_2']), ('quadruped', ['escape', 'fetch', 'run', 'walk']), ('stacker', ['stack_2', 'stack_4'])]