Farama-Foundation / PettingZoo

An API standard for multi-agent reinforcement learning environments, with popular reference environments and related utilities
https://pettingzoo.farama.org
Other
2.45k stars 400 forks source link

[Question] Complex observation_space Configuration Issue with PettingZoo and Tianshou Integration #1211

Open NeoBerekov opened 1 month ago

NeoBerekov commented 1 month ago

Question

I am integrating a complex observation_space within PettingZoo, adhering to Tianshou framework requirements that necessitate nesting dictionaries within observation to pass observations into a PyTorch model. My environment’s observation_space configuration is as follows:

self.observation_spaces = {
    agent: spaces.Dict({
        "observation": spaces.Dict({
            "position": spaces.Tuple((
                spaces.Discrete(map_size[0]),
                spaces.Discrete(map_size[1])
            )),
            "fuel": spaces.Box(low=-0.001, high=5000, shape=(1,), dtype=np.float32),
            "missile": spaces.Box(low=-0.001, high=5000, shape=(1,), dtype=np.float32),
            "map_obs": spaces.Box(low=-0.001, high=5000.0, shape=(8, map_size[0], map_size[1]), dtype=np.float32)
        }),
        "action_mask": spaces.MultiBinary(11)
    })
}

During the api_test in PettingZoo, I encountered the following errors:

The specific failing test code snippet is:

elif isinstance(env.observation_space(agent), gymnasium.spaces.Dict):
    assert (
        env.observation_space(agent)["observation"].dtype
        == prev_observe["observation"].dtype
    )

Given the necessity to nest dictionaries for compatibility with Tianshou, which expects PyTorch model inputs, it appears there is a misalignment with PettingZoo’s testing expectations, which presume NumPy array compatibility. How can I reconcile these requirements? Is this an oversight in the api_test, or should adjustments be made to accommodate such nested dictionary structures? Any guidance on resolving this configuration mismatch would be highly appreciated.

dm-ackerman commented 1 month ago

Are you using the current master branch of PettingZoo? If not, can you try that? I think I changed the behaviour for the nested obs case a while back. If it is still failing with that, can you post code for a minimum env that triggers the api error?

AhmedFakeih commented 2 weeks ago

Same issue here. API fails because dict has no dtype. @NeoBerekov did ignoring that particular test work for you?

jjshoots commented 1 week ago

Seems like it's a reasonable fix to just remove that warning. A PR on that would be very helpful and appreciated. :)

NeoBerekov commented 1 week ago

Same issue here. API fails because dict has no dtype. @NeoBerekov did ignoring that particular test work for you?

I'm not sure what is going on when tianshou running its training proc, but it seems that nothing goes wrong when I just ignore that test.

dm-ackerman commented 6 days ago

Same issue here. API fails because dict has no dtype. @NeoBerekov did ignoring that particular test work for you?

Did you try this with the current master version from git? If so, do you still get the error?