Support Dict observation spaces in black_death - #269
Open
Lauqz wants to merge 2 commits into
Open
Conversation
black_death_v3 asserted that every observation space is a Box, because it
needs a zero observation to substitute for agents that have died. That
rules out environments whose agents observe several things at once, for
example a camera image plus a proprioceptive vector.
The check now recurses into Dict, so a space is accepted exactly when
every leaf is a Box, and the zero observation is built with the same
recursion so it keeps the structure of the space.
Box behaviour is unchanged. Also fixes a typo in the assertion message
("sapces").
Lauqz
force-pushed
the
black-death-dict-obs
branch
from
July 26, 2026 15:12
fad297e to
e5ad69c
Compare
Run black over the new Dict-observation black_death test so the pre-commit job passes. flake8 allowed the long line (SuperSuit sets max-line-length=456) but black enforces its own 88-column wrap. No behaviour change.
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
black_death_v3asserts every agent's observation space is aBox:It needs that because it substitutes a zero observation for dead agents and
builds it with
np.zeros_like(space.low).That rules out any environment where an agent observes more than one thing at
once, which is common in robotics: a camera image plus a position vector, say.
Those environments cannot use black death at all unless they flatten first,
which defeats having a structured observation in the first place.
This adds
Dictsupport. The check recurses intoDictso a space is acceptedwhen every leaf is a
Box, and the zero observation is built with the samerecursion so it keeps the shape of the space instead of collapsing it.
Boxisunchanged and nested
Dicts work.Also fixed the typo in the assertion message,
sapcestospaces.I hit this on a vision-based multi-agent setup (PettingZoo + SuperSuit + SB3 over
AirSim/UE4) where each drone sees an RGB frame and its own 3D position.
Testing
Three tests in
test/parallel_env_test.py: reset and step withDictobservations, an agent missing from the step output getting a correctly shaped
and correctly keyed zero observation instead of an error, and a
Dictholding aMultiBinarystill raising.Full suite against
mainas a baseline:mainDifference is only the three new tests.
I also ran just the
black_deathandframe_stacktests fromtest/pettingzoo_api_test.py, which are parametrized over atari, butterfly,classic, mpe and sisl. Identical 123 passed, 51 skipped on
mainand with thischange, so nothing changes for existing environments.