Fix: parallel_api_test accepts action spaces of shapes other than Discrete#1313
Open
duncan-hintz wants to merge 1 commit intoFarama-Foundation:masterfrom
Open
Fix: parallel_api_test accepts action spaces of shapes other than Discrete#1313duncan-hintz wants to merge 1 commit intoFarama-Foundation:masterfrom
duncan-hintz wants to merge 1 commit intoFarama-Foundation:masterfrom
Conversation
parallel_api_test in parallel_test.py to account for action-masked spaces that are not Discrete. New implementation uses the existing sample function from Gymnasium.spaces that takes a mask as a parameter. Previous implementation fails for MultiDiscrete and Dict spaces (and perhaps others) as seen in issue Farama-Foundation#1298. New implementation will not work for Box spaces, as these are unsupported for masking by Gymnasium.
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.
Description
The test function parallel_api_test failed and threw an error when testing an environment that had an action space other than Discrete when action masked. This is due to the flattening of the action mask to sample from. This resulted in a single numerical sample consistent with the action mask, which is correct for Discrete but fails for actions spaces such as MultiDiscrete which expect an input as a tuple, e.g. [107, 26] instead of [133]. Motivated by a testing of a custom env that uses a MultiDiscrete action space. Similar issue was found in #1298 where a user reported failing a test due to sampling a Dict space. They ask if there is a proper way to action mask other than the examples, but I believe they masked correctly and the test failed due to this flattening.
New implementation uses the existing sample function from Gymnasium.spaces that takes a mask as a parameter. This will make it easier for users to simply reference the Gymnasium sampling and action-masking examples when creating new environments.
New implementation will not work for Box spaces, as these are unsupported for masking by Gymnasium.
Fixes #1298
Type of change
Screenshots
Before:


After:
Checklist:
pre-commitchecks withpre-commit run --all-files(seeCONTRIBUTING.mdinstructions to set it up)pytest -vand no errors are present.pytest -vhas generated that are related to my code to the best of my knowledge.