VmasWrapper¶
- torchrl.envs.VmasWrapper(*args, **kwargs)[source]¶
Vmas 環境包裝器。
GitHub: https://github.com/proroklab/VectorizedMultiAgentSimulator
Paper: 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 的TimeLimittransform 或 torchrl 的StepCounter不同,此引數不會在 tensordict 中設定"truncated"條目。categorical_actions (bool, optional) – 如果環境動作是離散的,是否將它們轉換為分類或獨熱表示。預設為
True。group_map (MarlGroupMapType or Dict[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) – 沒有向量化維度的規範版本
unbatched_observation_spec (TensorSpec) – 沒有向量化維度的規範版本
unbatched_reward_spec (TensorSpec) – 沒有向量化維度的規範版本
het_specs (bool) – 環境是否具有任何延遲載入的規範
het_specs_map (Dict[str, bool]) – 將每個組對映到一個標誌,表示該組是否具有延遲載入的規範的字典
available_envs (List[str]) – 可供構建的場景列表。
警告
VMAS 返回一個單獨的
done標誌,它不區分環境何時達到max_steps和何時終止。如果您認為truncation訊號是必需的,請將max_steps設定為None並使用StepCountertransform。示例
>>> 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)