Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NeoBerekov opened this issue May 25, 2024 · 5 comments
Labels
question Further information is requested

Comments

@NeoBerekov
Copy link

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:

  • UserWarning: Observation is not a NumPy array
  • UserWarning: Observation space for each agent probably should be gymnasium.spaces.box or gymnasium.spaces.discrete
  • AttributeError: 'dict' object has no attribute 'dtype'

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.

@NeoBerekov NeoBerekov added the question Further information is requested label May 25, 2024
@dm-ackerman
Copy link
Contributor

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
Copy link

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

@jjshoots
Copy link
Member

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

@NeoBerekov
Copy link
Author

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
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants