From 7c4d3d9fe1f20d679fbe2aaae6e0ec37129b9fc2 Mon Sep 17 00:00:00 2001 From: xihuai18 Date: Sat, 28 Sep 2024 23:33:13 +0800 Subject: [PATCH 1/3] fix: :bug: FIxed obsk=None: obsk only influence obs construction, but not the action factorization. --- .../envs/multiagent_mujoco/mujoco_multi.py | 40 +++++-------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py index 8ea964db..b0dc8572 100755 --- a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py +++ b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py @@ -15,7 +15,6 @@ This project is covered by the Apache 2.0 License. """ - from __future__ import annotations import os @@ -127,25 +126,16 @@ def __init__( self.agent_obsk = agent_obsk # if None, fully observable else k>=0 implies observe nearest k agents or joints # load the agent factorization - if self.agent_obsk is not None: - if agent_factorization is None: - ( - self.agent_action_partitions, - mujoco_edges, - self.mujoco_globals, - ) = get_parts_and_edges(scenario, agent_conf) - else: - self.agent_action_partitions = agent_factorization["partition"] - mujoco_edges = agent_factorization["edges"] - self.mujoco_globals = agent_factorization["globals"] + if agent_factorization is None: + ( + self.agent_action_partitions, + mujoco_edges, + self.mujoco_globals, + ) = get_parts_and_edges(scenario, agent_conf) else: - self.agent_action_partitions = [ - tuple( - Node("dummy_node", None, None, i) - for i in range(self.single_agent_env.action_space.shape[0]) - ) - ] - mujoco_edges = [] + self.agent_action_partitions = agent_factorization["partition"] + mujoco_edges = agent_factorization["edges"] + self.mujoco_globals = agent_factorization["globals"] # Create agent lists self.possible_agents = [ @@ -293,9 +283,6 @@ def map_local_actions_to_global_action( AssertionError: If the Agent action factorization is badly defined (if an action is double defined or not defined at all) """ - if self.agent_obsk is None: - return actions[self.possible_agents[0]] - assert self.single_agent_env.action_space.shape is not None global_action = ( np.zeros((self.single_agent_env.action_space.shape[0],)) + np.nan @@ -329,9 +316,6 @@ def map_global_action_to_local_actions( AssertionError: If the Agent action factorization sizes are badly defined """ - if self.agent_obsk is None: - return {self.possible_agents[0]: action} - local_actions = {} for agent_id, partition in enumerate(self.agent_action_partitions): local_actions[self.possible_agents[agent_id]] = np.array( @@ -417,12 +401,6 @@ def create_observation_mapping(self) -> dict[str, np.ndarray[np.float64]]: Returns: A cache that indexes global osbervations to local. """ - if self.agent_obsk is None: - return { - self.possible_agents[0]: np.arange( - self.single_agent_env.observation_space.shape[0] - ) - } if not hasattr(self.single_agent_env.unwrapped, "observation_structure"): return None From 343df62e9a4f7f6e7785a173e22fa8a53fd704b4 Mon Sep 17 00:00:00 2001 From: xihuai18 Date: Sat, 28 Sep 2024 23:37:06 +0800 Subject: [PATCH 2/3] docs: :memo: update agent_obsk docs --- gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py index b0dc8572..95ef0ef0 100755 --- a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py +++ b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py @@ -93,7 +93,7 @@ def __init__( If set to 0 it only observes local state, If set to 1 it observes local state + 1 joint over, If set to 2 it observes local state + 2 joints over, - If it set to None the task becomes single agent (the agent observes the entire environment, and performs all the actions) + If it set to None the task becomes single agent (the agents observe the entire environment) The Default value is: 1 agent_factorization: A custom factorization of the MuJoCo environment (overwrites agent_conf), see DOC [how to create new agent factorizations](https://robotics.farama.org/envs/MaMuJoCo/index.html#how-to-create-new-agent-factorizations). From 21d4786384a5a07005e2c49d244da4ce3ef6698e Mon Sep 17 00:00:00 2001 From: xihuai18 Date: Sat, 28 Sep 2024 23:39:31 +0800 Subject: [PATCH 3/3] style: :lipstick: pass pre-commit --- gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py index 95ef0ef0..0cb159b3 100755 --- a/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py +++ b/gymnasium_robotics/envs/multiagent_mujoco/mujoco_multi.py @@ -30,7 +30,6 @@ CoupledHalfCheetahEnv, ) from gymnasium_robotics.envs.multiagent_mujoco.obsk import ( - Node, build_obs, get_joints_at_kdist, get_parts_and_edges,