Skip to content

fix: clear space caches on reset for generated agents (#229) - #271

Open
teddytennant wants to merge 1 commit into
Farama-Foundation:mainfrom
teddytennant:fix/generated-agents-test-229
Open

fix: clear space caches on reset for generated agents (#229)#271
teddytennant wants to merge 1 commit into
Farama-Foundation:mainfrom
teddytennant:fix/generated-agents-test-229

Conversation

@teddytennant

Copy link
Copy Markdown
Contributor

Problem

test/generated_agents_test.py had three entire PettingZoo API test suites skipped with TODOs (issue #229). The failures looked like out-of-bounds observations, action-space mismatches, and numpy broadcast errors when wrapping PettingZoo generated_agents_* environments.

Root cause

Those example envs regenerate agent types (and therefore observation/action shapes) on every reset(). Several SuperSuit wrappers cache per-agent spaces with @functools.lru_cache and keep long-lived per-agent modifiers:

  • observation_lambda / action_lambda
  • shared_wrapper (frame stack, sticky actions, delay obs, max obs, nan_random, etc.)

After a second reset, the cached space for e.g. type0_0 still had the previous episode shape, while the live observation used the new shape. That produced the reported failures.

Fix

  • Clear observation_space / action_space LRU caches on reset() in the AEC lambda wrappers.
  • In shared_wrapper (AEC and Parallel), drop all per-agent modifiers and clear space caches on reset(), then rebuild modifiers for the new agent set.
  • Unskip generated_agents_test for the wrappers that now pass.
  • Keep AEC frame_skip_v0 out of the enabled suites (documented skip): mid-episode agent birth/death still breaks the PettingZoo dead-agent protocol under AEC frame skip. Parallel frame_skip is tested and passes.

Test plan

  • pytest test/generated_agents_test.py -o addopts=45 passed, 1 skipped
  • pytest test/aec_mock_test.py -o addopts=36 passed
  • pytest test/parallel_env_test.py -o addopts=5 passed

Fixes #229

Procedurally generated agent envs can change observation/action space
shapes across resets. SuperSuit wrappers cached spaces with lru_cache and
reused per-agent modifiers, so after reset the cached space no longer
matched live observations (out-of-bounds, broadcast errors, bad actions).

Clear observation/action space caches (and rebuild shared-wrapper
modifiers) on reset. Re-enable generated_agents_test for wrappers that
now pass PettingZoo API tests. Leave AEC frame_skip skipped with a clear
reason: it still does not fully implement the dead-agent protocol when
agents are created or destroyed mid-episode (parallel frame_skip passes).

Fixes Farama-Foundation#229
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.

Errors in generated_agents_test.py

1 participant