捷徑

MeltingpotWrapper

torchrl.envs.MeltingpotWrapper(*args, **kwargs)[來源]

Meltingpot 環境包裝器。

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

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

Melting Pot 評估對涉及熟悉和不熟悉個體的新型社會情境的泛化能力,並旨在測試廣泛的社會互動,例如:合作、競爭、欺騙、互惠、信任、頑固等等。 Melting Pot 為研究人員提供了一組超過 50 個多代理強化學習基底(多代理遊戲),用於訓練代理,以及超過 256 個獨特的測試情境,用於評估這些訓練有素的代理。

參數:

env (meltingpot.utils.substrates.substrate.Substrate) – 要包裝的 meltingpot 基底。

關鍵字參數:
  • max_steps (int, optional) – 任務的範圍。預設為 None (無限範圍)。每個 Meltingpot 基底可以是終止的或非終止的。如果指定 max_steps,則只要達到此範圍,情境也會終止(並且設定 "terminated" 旗標)。與 gym 的 TimeLimit 轉換或 torchrl 的 StepCounter 不同,此引數不會在 tensordict 中設定 "truncated" 條目。

  • categorical_actions (bool, optional) – 如果環境動作是離散的,是否將它們轉換為分類的或 one-hot 的。預設為 True

  • group_map (MarlGroupMapTypeDict[str, List[str]], optional) – 如何在 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 meltingpot import substrate
>>> from torchrl.envs.libs.meltingpot import MeltingpotWrapper
>>> substrate_config = substrate.get_config("commons_harvest__open")
>>> mp_env = substrate.build_from_config(
...     substrate_config, roles=substrate_config.default_player_roles
... )
>>> env_torchrl = MeltingpotWrapper(env=mp_env)
>>> 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 的全面開發者文件

檢視文件

教學

取得初學者和進階開發人員的深入教學課程

檢視教學

資源

尋找開發資源並獲得您的問題解答

檢視資源