Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)
https://gymnasium.farama.org
MIT License
6.94k stars 773 forks source link

[Bug Report] MultiDiscrete spaces' __eq__ method needs to check shape. #1044

Closed DenBuzz closed 4 months ago

DenBuzz commented 5 months ago

Describe the bug

__eq__ method for MultiDiscrete space needs to check shape. Currently, comparing two MultiDiscrete spaces with different shaped nvecs will throw errors instead of returning False.

Code example

from gymnasium.spaces import MultiDiscrete

a = MultiDiscrete([2, 3, 4])
b = MultiDiscrete([2, 3, 4])

print(a == b)  # True

a = MultiDiscrete([2, 3, 4])
b = MultiDiscrete([4, 2, 2])

print(a == b)  # False

a = MultiDiscrete([2, 3, 4])
b = MultiDiscrete([2, 3, 2, 4])

print(a == b)  # Error


### System info

Installed via pip
gymnasium version: 0.28.1  (Although I believe this issue is still present in the latest version)

### Additional context

_No response_

### Checklist

- [X] I have checked that there is no similar [issue](https://github.com/Farama-Foundation/Gymnasium/issues) in the repo
Kallinteris-Andreas commented 5 months ago

does this also happen for gymnasium==1.0.0a1 and MAIN git ?

DenBuzz commented 5 months ago

Yes, can confirm it crashes in 1.0.0a1 and the current MAIN.

pseudo-rnd-thoughts commented 5 months ago

Wow, thanks for finding that I would have expected that nvec equivalent would address this but I can see how this would fail

Could you make a PR to solve this?