快捷方式

VmasWrapper

torchrl.envs.VmasWrapper(*args, **kwargs)[原始碼]

Vmas 環境包裝器。

GitHub: https://github.com/proroklab/VectorizedMultiAgentSimulator

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

引數:

env (vmas.simulator.environment.environment.Environment) – 要包裝的 vmas 環境。

關鍵字引數:
  • num_envs (int) – 向量化模擬環境的數量。VMAS 使用 PyTorch 進行向量化模擬。此引數指示應在批次中模擬的向量化環境的數量。它還將確定環境的批次大小。

  • device (torch.device, optional) – 模擬裝置。預設為預設裝置。VMAS 建立的所有張量都將放置在此裝置上。

  • continuous_actions (bool, optional) – 是否使用連續動作。預設為 True。如果為 False,則動作為離散的。動作的數量及其大小將取決於所選的場景。有關更多資訊,請參閱 VMAS 儲存庫。

  • max_steps (int, optional) – 任務的範圍。預設為 None(無限範圍)。每個 VMAS 場景都可以是終止性的,也可以不是。如果指定了 max_steps,則當達到此範圍時,場景也會終止(並且 "terminated" 標誌會被設定)。與 gym 的 TimeLimit 轉換或 torchrl 的 StepCounter 不同,此引數不會在 tensordict 中設定 "truncated" 條目。

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

  • group_map (MarlGroupMapTypeDict[str, List[str]], optional) – 如何在 tensordicts 中對代理進行輸入/輸出分組。預設情況下,如果代理名稱遵循 "<name>_<int>" 約定,它們將按 "<name>" 進行分組。如果它們不遵循此約定,它們將被全部放入一個名為 "agents" 的組中。否則,可以指定一個組對映或從一些預製選項中選擇。有關更多資訊,請參閱 MarlGroupMapType

變數:
  • group_map (Dict[str, List[str]]) – 如何在 tensordicts 中分組智慧體以用於輸入/輸出。有關更多資訊,請參閱 MarlGroupMapType

  • agent_names (list of str) – 環境中智慧體的名稱

  • agent_names_to_indices_map (Dict[str, int]) – 將智慧體名稱對映到其在環境中的索引的字典

  • unbatched_action_spec (TensorSpec) – 刪除了向量化維度的 spec 版本

  • unbatched_observation_spec (TensorSpec) – 刪除了向量化維度的 spec 版本

  • unbatched_reward_spec (TensorSpec) – 刪除了向量化維度的 spec 版本

  • het_specs (bool) – 環境是否具有任何惰性 spec

  • het_specs_map (Dict[str, bool]) – 字典,將每個組對映到表示該組是否具有惰性 spec 的標誌

  • available_envs (List[str]) – 可用於構建的場景列表。

警告

VMAS 返回一個單一的 done 標誌,該標誌不區分環境何時達到 max_steps 和終止。如果您認為 truncation 訊號是必需的,請將 max_steps 設定為 None 並使用 StepCounter 轉換。

示例

>>>  env = VmasWrapper(
...      vmas.make_env(
...          scenario="flocking",
...          num_envs=32,
...          continuous_actions=True,
...          max_steps=200,
...          device="cpu",
...          seed=None,
...          # Scenario kwargs
...          n_agents=5,
...      )
...  )
>>>  print(env.rollout(10))
TensorDict(
    fields={
        agents: TensorDict(
            fields={
                action: Tensor(shape=torch.Size([32, 10, 5, 2]), device=cpu, dtype=torch.float32, is_shared=False),
                info: TensorDict(
                    fields={
                        agent_collision_rew: Tensor(shape=torch.Size([32, 10, 5, 1]), device=cpu, dtype=torch.float32, is_shared=False),
                        agent_distance_rew: Tensor(shape=torch.Size([32, 10, 5, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
                    batch_size=torch.Size([32, 10, 5]),
                    device=cpu,
                    is_shared=False),
                observation: Tensor(shape=torch.Size([32, 10, 5, 18]), device=cpu, dtype=torch.float32, is_shared=False)},
            batch_size=torch.Size([32, 10, 5]),
            device=cpu,
            is_shared=False),
        done: Tensor(shape=torch.Size([32, 10, 1]), device=cpu, dtype=torch.bool, is_shared=False),
        next: TensorDict(
            fields={
                agents: TensorDict(
                    fields={
                        info: TensorDict(
                            fields={
                                agent_collision_rew: Tensor(shape=torch.Size([32, 10, 5, 1]), device=cpu, dtype=torch.float32, is_shared=False),
                                agent_distance_rew: Tensor(shape=torch.Size([32, 10, 5, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
                            batch_size=torch.Size([32, 10, 5]),
                            device=cpu,
                            is_shared=False),
                        observation: Tensor(shape=torch.Size([32, 10, 5, 18]), device=cpu, dtype=torch.float32, is_shared=False),
                        reward: Tensor(shape=torch.Size([32, 10, 5, 1]), device=cpu, dtype=torch.float32, is_shared=False)},
                    batch_size=torch.Size([32, 10, 5]),
                    device=cpu,
                    is_shared=False),
                done: Tensor(shape=torch.Size([32, 10, 1]), device=cpu, dtype=torch.bool, is_shared=False),
                terminated: Tensor(shape=torch.Size([32, 10, 1]), device=cpu, dtype=torch.bool, is_shared=False)},
            batch_size=torch.Size([32, 10]),
            device=cpu,
            is_shared=False),
        terminated: Tensor(shape=torch.Size([32, 10, 1]), device=cpu, dtype=torch.bool, is_shared=False)},
    batch_size=torch.Size([32, 10]),
    device=cpu,
    is_shared=False)

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

為初學者和高階開發者提供深入的教程

檢視教程

資源

查詢開發資源並讓您的問題得到解答

檢視資源