MeltingpotEnv¶
- torchrl.envs.MeltingpotEnv(*args, **kwargs)[来源]¶
Meltingpot 环境包装器。
GitHub: https://github.com/google-deepmind/meltingpot
论文: https://arxiv.org/abs/2211.13746
Melting Pot 评估在涉及熟悉和不熟悉个体的新的社交情境中的泛化能力,旨在测试广泛的社交互动,例如:合作、竞争、欺骗、互惠、信任、固执等等。Melting Pot 为研究人员提供了一套超过 50 种多智能体强化学习基质(多智能体游戏),用于训练智能体,以及超过 256 种独特的测试场景,用于评估这些训练有素的智能体。
- 参数:
substrate (str 或 ml_collections.config_dict.ConfigDict) – 要构建的 meltingpot 基质。可以是
available_envs
中的字符串或基质的 ConfigDict- 关键词参数:
max_steps (int, 可选) – 任务的最长步数。默认为
None
(无限步数)。每个 Meltingpot 基质可以是终止的或不终止的。如果指定了max_steps
,则当达到此最长步数时,场景也会终止(并且设置"terminated"
标志)。与 gym 的TimeLimit
转换或 torchrl 的StepCounter
不同,此参数不会在 tensordict 中设置"truncated"
条目。categorical_actions (bool, 可选) – 如果环境动作是离散的,是否将其转换为类别型或独热编码。默认为
True
。group_map (MarlGroupMapType 或 Dict[str, List[str]], 可选) – 如何在 tensordict 中对智能体进行分组以进行输入/输出。默认情况下,它们都将放入名为
"agents"
的组中。否则,可以指定组映射或从一些预制选项中选择。有关更多信息,请参见MarlGroupMapType
。
- 变量:
group_map (Dict[str, List[str]]) – 如何在 tensordict 中对智能体进行分组以进行输入/输出。有关更多信息,请参见
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)