Repository navigation
Fix PettingZoo wrappers dropping multi-dimensional action components - #6342
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
_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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change(s)
UnityPettingzooBaseEnv._process_actionbuilds anActionTuplefrom the 1-D action array forBox,MultiDiscreteandTupleaction spaces, then copiesaction.continuous[0]andaction.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 theActionTuple, as theDiscretebranch already does withreshape(1, 1). The[0]indexing then selects the whole action row.The new test steps
UnityParallelEnvwith 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.)
[0]index. Migrate gym to gymnasium #6309 adopted thefloat32dtype change from Update unity_pettingzoo_base_env.py #6136, and the[0]indexing is still present. Removing[0]alone breaks theDiscretepath, which passes a(1, 1)array.Types of change(s)
Checklist
Other comments
Without the source change, the three new test cases fail (
3 failed, 7 passedintest_pettingzoo_wrapper.py). With it,test_pettingzoo_wrapper.py,test_gym.pyandtest_steps.pypass (28 passed).black,flake8andmypyat the pre-commit versions report no issues on the changed files.