Skip to content

Fix nan_random_v0 ignoring observation action masks - #275

Open
Doribelove wants to merge 1 commit into
Farama-Foundation:mainfrom
Doribelove:codex/nan-random-action-mask
Open

Fix nan_random_v0 ignoring observation action masks#275
Doribelove wants to merge 1 commit into
Farama-Foundation:mainfrom
Doribelove:codex/nan-random-action-mask

Conversation

@Doribelove

Copy link
Copy Markdown

nan_random_v0 checks for "action mask" in the observation but then reads obs["action_mask"]. Observations using the standard underscore key therefore fall through to unmasked sampling. A NaN replacement can be illegal even when the observation identifies legal actions.

Change the guard to "action_mask", restoring the existing masked-sampling branch described in the wrapper documentation. Add two deterministic AEC regression cases with a single legal action; the seeded unmasked action space selects an illegal action in both cases. This addresses the NaN replacement path, which the existing normal-action API tests do not exercise.

For an end-to-end reproduction with PettingZoo's Connect Four:

import numpy as np
from pettingzoo.classic import connect_four_v3
from supersuit import nan_random_v0

env = nan_random_v0(connect_four_v3.env())
env.reset(seed=0)
for _ in range(6):
    env.step(5)  # Fill column 5 without ending the game.
env.action_space(env.agent_selection).seed(0)
env.step(np.nan)
print(env.terminations)
env.close()

Before the fix, unmasked sampling selects the full column and terminates the game with an illegal-move penalty. After the fix, a legal column receives a piece and both termination flags remain false.

Validation on base adf4114d0b437ba4607bd329ad32e34667c0a10b, using Python 3.12.14, NumPy 2.5.3, Gymnasium 1.3.0, and PettingZoo 1.27.0:

  • New regressions against the original implementation: 2 failed; with the fix: 2 passed.
  • AEC/Gym mock and unwrapped tests, parallel wrapper tests, generated-agent tests, and the new regressions: 77 passed, 39 skipped.
  • Existing non-Atari NaN-wrapper API tests: 120 passed.
  • Pinned pre-commit hooks on both changed files, git diff --check, and wheel/sdist builds passed.

The two new regressions are included in the 77-test result. The full suite, Atari ROM tests, and the complete CI platform/Python matrix were not run locally.

AI assistance: Codex prepared the implementation, tests, and this description, and executed the reported local validation.

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.

1 participant