Skip to content

[BugFix] Check agent presence before updating action mask in PettingZoo#3703

Open
nshoman wants to merge 1 commit intopytorch:mainfrom
nshoman:fix/pz_mask
Open

[BugFix] Check agent presence before updating action mask in PettingZoo#3703
nshoman wants to merge 1 commit intopytorch:mainfrom
nshoman:fix/pz_mask

Conversation

@nshoman
Copy link
Copy Markdown

@nshoman nshoman commented May 5, 2026

Description

This PR fixes a case an error in the PettingZoo adapter where, in cases of a ParallelEnv, with action masking and done_on_any=False, a KeyError can occur. This happens because there is no check on active agents before values are pulled from the observation dictionary. PettingZoo expects that the observation dictionary only contains entries for active agents.

Motivation and Context

PettingZoo expects that agents are removed from observations if inactive, so the torchrl should handle that situation. It's worth noting that I implemented a simple check before trying to index the dictionary, but another viable fix would be repositioning the existing check if agent in agents_acting: to an earlier location in the execution path as well.

This is a PR to address #3702.

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature). - I don't think a new test is required for this minimal change.
  • I have updated the documentation accordingly.

check to see if the agent is present in the observation and info dicts before accessing the keys
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 5, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3703

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures

As of commit b4f3e2e with merge base 8038188 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 5, 2026

Hi @nshoman!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added Environments Adds or modifies an environment wrapper Environments/pettingzoo BugFix labels May 5, 2026
Copy link
Copy Markdown
Contributor

@theap06 theap06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vmoens
Copy link
Copy Markdown
Collaborator

vmoens commented May 8, 2026

@nshoman thanks for contributing. Can you sign the CLA, I can't merge without it

@nshoman
Copy link
Copy Markdown
Author

nshoman commented May 8, 2026

@nshoman thanks for contributing. Can you sign the CLA, I can't merge without it

Sorry for the delay! I'll ping you once I've done so; my employer has to sign off on it, so it might take a few days.

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

Labels

BugFix Environments/pettingzoo Environments Adds or modifies an environment wrapper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants