Skip to content

Fix PettingZoo wrappers dropping multi-dimensional action components - #6342

Open
RaphaelFakhri wants to merge 1 commit into
Unity-Technologies:developfrom
RaphaelFakhri:fix-pettingzoo-multi-dim-actions
Open

RaphaelFakhri wants to merge 1 commit into
Unity-Technologies:developfrom
RaphaelFakhri:fix-pettingzoo-multi-dim-actions

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Proposed change(s)

UnityPettingzooBaseEnv._process_action builds an ActionTuple from the 1-D action array for Box, MultiDiscrete and Tuple action spaces, then copies action.continuous[0] and action.discrete[0] into the agent's row of the batched action. For a 1-D array, [0] is the first scalar, so NumPy broadcasts it to every action dimension. For example, a continuous action [0.1, -0.2] reaches Unity as [0.1, 0.1], and a multi-discrete action [0, 1] reaches Unity as [0, 0]. Only behaviors with exactly one continuous action or one discrete branch work correctly.

This change reshapes those actions to (1, n) before building the ActionTuple, as the Discrete branch already does with reshape(1, 1). The [0] indexing then selects the whole action row.

The new test steps UnityParallelEnv with a two-dimensional continuous, multi-discrete and hybrid action and checks that the environment receives every component. The existing PettingZoo tests use a single continuous action, so they don't cover this case.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable): not applicable, no API or configuration change
  • Updated the migration guide (if applicable): not applicable

Other comments

Without the source change, the three new test cases fail (3 failed, 7 passed in test_pettingzoo_wrapper.py). With it, test_pettingzoo_wrapper.py, test_gym.py and test_steps.py pass (28 passed). black, flake8 and mypy at the pre-commit versions report no issues on the changed files.

_process_action built ActionTuple from 1-D arrays for Box, MultiDiscrete
and Tuple spaces and then copied element [0] into the agent's row, so the
first component was broadcast to every action dimension. Reshape these
actions to (1, n), as the Discrete branch already does.
@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner November 3, 2026 15:47
@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PettingZoo wrappers send only the first action component to every action dimension

2 participants