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, optional) – 任務的 Horizon。預設為
None
(無限 Horizon)。每個 Meltingpot 基板都可以是終止或非終止。如果指定max_steps
,則只要達到此 Horizon,也會終止情境(並設定"terminated"
標誌)。不像 gym 的TimeLimit
轉換或 torchrl 的StepCounter
,此引數不會在 tensordict 中設定"truncated"
條目。categorical_actions (bool, optional) – 如果環境動作是離散的,是否將它們轉換為 categorical 或 one-hot。預設為
True
。group_map (MarlGroupMapType 或 Dict[str, List[str]], optional) – 如何在 tensordict 中分組代理以進行輸入/輸出。預設情況下,它們將全部放入一個名為
"agents"
的群組中。否則,可以指定群組地圖或從一些預製選項中選擇。有關更多資訊,請參閱MarlGroupMapType
。
- 變數:
group_map (Dict[str, List[str]]) – 如何在 tensordict 中對 agents 進行分組,以用於輸入/輸出。更多資訊請參閱
MarlGroupMapType
。agent_names (list of str) – 環境中 agent 的名稱列表。
agent_names_to_indices_map (Dict[str, int]) – 將 agent 名稱對應到其在環境中索引的字典。
available_envs (List[str]) – 可用於建構的 scenarios 列表。
警告
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)