Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to

#### ml-agents / ml-agents-envs
- Fixed PPO and POCA value estimates being overwritten by returns in the training buffer, preventing value loss clipping around the original predictions. (#6281, #6337)
- Fixed the PettingZoo wrappers sending only the first component of a continuous, multi-discrete or hybrid action to every action dimension.

## [4.1.0] - 2026-07-27
### Major Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ def _process_action(self, current_agent, action):
f"Invalid action, got {action} but was expecting action from {self.action_space}"
)
if isinstance(current_action_space, spaces.Tuple):
action = ActionTuple(action[0], action[1])
action = ActionTuple(action[0].reshape(1, -1), action[1].reshape(1, -1))
elif isinstance(current_action_space, spaces.MultiDiscrete):
action = ActionTuple(None, action)
action = ActionTuple(None, action.reshape(1, -1))
elif isinstance(current_action_space, spaces.Discrete):
action = ActionTuple(None, np.array(action).reshape(1, 1))
else:
action = ActionTuple(action, None)
action = ActionTuple(action.reshape(1, -1), None)

if not (self._terminations[current_agent] or self._truncations[current_agent]):
current_behavior = _agent_id_to_behavior(current_agent)
Expand Down
28 changes: 28 additions & 0 deletions ml-agents-envs/tests/test_pettingzoo_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,31 @@ def test_reset_seed_reseeds_action_spaces():
second = env.action_space(agent).sample()

assert np.array_equal(first, second)


@pytest.mark.parametrize(
"action_sizes", [(2, 0), (0, 2), (2, 2)], ids=["continuous", "discrete", "hybrid"]
)
def test_step_forwards_every_action_component(action_sizes):
# Every component of a multi-dimensional action must reach the environment,
# not only the first one.
unity_env = SimpleEnvironment(["test_single"], action_sizes=action_sizes)
env = UnityParallelEnv(unity_env)
env.reset()
agent = env.agents[0]
continuous = np.array([0.1, -0.2], dtype=np.float32)
discrete = np.array([0, 1], dtype=np.int32)
if action_sizes == (2, 0):
action = continuous
elif action_sizes == (0, 2):
action = discrete
else:
action = (continuous, discrete)

env.step({agent: action})

sent = unity_env.action["test_single"]
if action_sizes[0] > 0:
np.testing.assert_array_equal(sent.continuous, [continuous])
if action_sizes[1] > 0:
np.testing.assert_array_equal(sent.discrete, [discrete])