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.93k stars 770 forks source link

spaces.Dict: Make `sorted(spaces.items())` optional #1072

Open carlocagnetta opened 4 months ago

carlocagnetta commented 4 months ago

Sorting the dictionary's entries it's probably not always wanted, but unfortunately there is no way around it other than overwriting self.spaces after initializing a spaces.Dict. It would be handy to make this optional, maybe with default parameter for backwards compatibility if needed.

https://github.com/Farama-Foundation/Gymnasium/blame/0607994d37a8079945ed0e0416ff750a3ad2e26f/gymnasium/spaces/dict.py#L73

carlocagnetta commented 4 months ago

@MischaPanch even by resetting self.spaces after initializing the dict space, it will again brake the order when using any ObsWrapper, for example FrameStackObservation

pseudo-rnd-thoughts commented 4 months ago

@carlocagnetta Interesting suggestions, similarly I don't like needing to sort the dictionary data as it is a product of technical debt when python dictionaries weren't insertion sorted. I agree, that adding an argument would solve this issue.

Could you make a PR for it?