Skip to content

Support Dict observation spaces in black_death - #269

Open
Lauqz wants to merge 2 commits into
Farama-Foundation:mainfrom
Lauqz:black-death-dict-obs
Open

Support Dict observation spaces in black_death#269
Lauqz wants to merge 2 commits into
Farama-Foundation:mainfrom
Lauqz:black-death-dict-obs

Conversation

@Lauqz

@Lauqz Lauqz commented Jul 26, 2026

Copy link
Copy Markdown

Description

black_death_v3 asserts every agent's observation space is a Box:

observation sapces for black death must be Box spaces, is Dict(...)

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 Dict support. The check recurses into Dict so a space is accepted
when every leaf is a Box, and the zero observation is built with the same
recursion so it keeps the shape of the space instead of collapsing it. Box is
unchanged and nested Dicts work.

Also fixed the typo in the assertion message, sapces to spaces.

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 with Dict
observations, an agent missing from the step output getting a correctly shaped
and correctly keyed zero observation instead of an error, and a Dict holding a
MultiBinary still raising.

Full suite against main as a baseline:

result
main 117 passed, 46 skipped
this branch 120 passed, 46 skipped

Difference is only the three new tests.

I also ran just the black_death and frame_stack tests from
test/pettingzoo_api_test.py, which are parametrized over atari, butterfly,
classic, mpe and sisl. Identical 123 passed, 51 skipped on main and with this
change, so nothing changes for existing environments.

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
Lauqz force-pushed the black-death-dict-obs branch from fad297e to e5ad69c Compare July 26, 2026 15:12
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.
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