快捷方式

MeltingpotEnv

torchrl.envs.MeltingpotEnv(*args, **kwargs)[source]

Meltingpot 环境包装器。

GitHub: https://github.com/google-deepmind/meltingpot

论文: https://arxiv.org/abs/2211.13746

Melting Pot 评估在涉及熟悉和不熟悉个体的新型社交情境下的泛化能力,其设计旨在测试广泛的社交互动,例如:合作、竞争、欺骗、互惠、信任、顽固等等。Melting Pot 为研究人员提供了一套超过 50 个多智能体强化学习基底(多智能体游戏),用于训练智能体,以及超过 256 个独特的测试场景,用于评估这些训练好的智能体。

参数:

substrate (strml_collections.config_dict.ConfigDict) – 要构建的 meltingpot 基底。可以是 `available_envs` 中的字符串,或者是一个 ConfigDict 来描述基底。

关键字参数:
  • max_steps (int, optional) – 任务的视野。默认为 None(无限视野)。每个 Meltingpot 基底都可以是终止性的或非终止性的。如果指定了 max_steps,当达到该视野时,场景也会终止(并且 "terminated" 标志将被设置)。与 gym 的 TimeLimit 变换或 torchrl 的 StepCounter 不同,此参数不会在 tensordict 中设置 "truncated" 条目。

  • categorical_actions (bool, optional) – 如果环境动作是离散的,是否将其转换为分类或独热编码。默认为 True

  • group_map (MarlGroupMapTypeDict[str, List[str]], optional) – 如何在 tensordicts 中分组智能体以进行输入/输出。默认情况下,它们都将被放入一个名为 "agents" 的组中。否则,可以指定一个组映射,或从一些预制选项中选择。有关更多信息,请参阅 MarlGroupMapType

变量:
  • group_map (Dict[str, List[str]]) – 如何在 tensordicts 中分组智能体以进行输入/输出。有关更多信息,请参阅 MarlGroupMapType

  • agent_names (list of str) – 环境中智能体的名称

  • agent_names_to_indices_map (Dict[str, int]) – 将智能体名称映射到其在环境中的索引的字典

  • available_envs (List[str]) – 可用于构建的场景列表。

警告

Meltingpot 返回一个单一的 done 标志,该标志不区分环境何时达到 max_steps 和何时终止。如果您认为 truncation 信号是必需的,请将 max_steps 设置为 None 并使用 StepCounter 变换。

示例

>>> from torchrl.envs.libs.meltingpot import MeltingpotEnv
>>> env_torchrl = MeltingpotEnv("commons_harvest__open")
>>> print(env_torchrl.rollout(max_steps=5))
TensorDict(
    fields={
        RGB: Tensor(shape=torch.Size([5, 144, 192, 3]), device=cpu, dtype=torch.uint8, is_shared=False),
        agents: TensorDict(
            fields={
                action: Tensor(shape=torch.Size([5, 7]), device=cpu, dtype=torch.int64, is_shared=False),
                observation: TensorDict(
                    fields={
                        COLLECTIVE_REWARD: Tensor(shape=torch.Size([5, 7, 1]), device=cpu, dtype=torch.float64, is_shared=False),
                        READY_TO_SHOOT: Tensor(shape=torch.Size([5, 7, 1]), device=cpu, dtype=torch.float64, is_shared=False),
                        RGB: Tensor(shape=torch.Size([5, 7, 88, 88, 3]), device=cpu, dtype=torch.uint8, is_shared=False)},
                    batch_size=torch.Size([5, 7]),
                    device=cpu,
                    is_shared=False)},
            batch_size=torch.Size([5, 7]),
            device=cpu,
            is_shared=False),
        done: Tensor(shape=torch.Size([5, 1]), device=cpu, dtype=torch.bool, is_shared=False),
        next: TensorDict(
            fields={
                RGB: Tensor(shape=torch.Size([5, 144, 192, 3]), device=cpu, dtype=torch.uint8, is_shared=False),
                agents: TensorDict(
                    fields={
                        observation: TensorDict(
                            fields={
                                COLLECTIVE_REWARD: Tensor(shape=torch.Size([5, 7, 1]), device=cpu, dtype=torch.float64, is_shared=False),
                                READY_TO_SHOOT: Tensor(shape=torch.Size([5, 7, 1]), device=cpu, dtype=torch.float64, is_shared=False),
                                RGB: Tensor(shape=torch.Size([5, 7, 88, 88, 3]), device=cpu, dtype=torch.uint8, is_shared=False)},
                            batch_size=torch.Size([5, 7]),
                            device=cpu,
                            is_shared=False),
                        reward: Tensor(shape=torch.Size([5, 7, 1]), device=cpu, dtype=torch.float64, is_shared=False)},
                    batch_size=torch.Size([5, 7]),
                    device=cpu,
                    is_shared=False),
                done: Tensor(shape=torch.Size([5, 1]), device=cpu, dtype=torch.bool, is_shared=False),
                terminated: Tensor(shape=torch.Size([5, 1]), device=cpu, dtype=torch.bool, is_shared=False)},
            batch_size=torch.Size([5]),
            device=cpu,
            is_shared=False),
        terminated: Tensor(shape=torch.Size([5, 1]), device=cpu, dtype=torch.bool, is_shared=False)},
    batch_size=torch.Size([5]),
    device=cpu,
    is_shared=False)

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源