stable-baselines3 icon indicating copy to clipboard operation
stable-baselines3 copied to clipboard

MultiBinary not fully supported

Open blumu opened this issue 3 years ago • 1 comments

The documentation says that MultiBinary is supported (at least for some of the RL agents), however it looks like the only supported case is MultiBinary(n) where n is an integer. The general case where n is a list of dimensions is not supported. See gym doc.

If the environments uses spaces of the form MultiBinary([,,]) then an exception occurs at the following line because observation_space.n cannot be converted to an int: https://github.com/DLR-RM/stable-baselines3/blob/b7456392acb921f68a6b9f894350c099726e5a55/stable_baselines3/common/preprocessing.py#L153

blumu avatar Sep 21 '22 00:09 blumu

The following fix may help though I have not fully tested it so it's possible that it breaks somewhere else:

 elif isinstance(observation_space, spaces.MultiBinary):
        # Number of binary features
        if isinstance(observation_space.n, int):
            return (observation_space.n, )
        elif isinstance(observation_space.n, list):
            return tuple(observation_space.n)
        else:
            raise NotSupportedError(f"Unsupported type: {type(observation_space.n)}")

See hacked patch at https://github.com/DLR-RM/stable-baselines3/compare/master...blumu:stable-baselines3:blumu/multibinary

blumu avatar Sep 21 '22 00:09 blumu

Hello,

The documentation says that MultiBinary is supported (at least for some of the RL agents), however it looks like the only supported case is MultiBinary(n) where n is an integer.

This is true.

The general case where n is a list of dimensions is not supported. See gym doc.

The easiest solution would be to use a wrapper to flatten/unflatten the observation, no?

Anyway, the env checker should be updated at least.

araffin avatar Sep 26 '22 13:09 araffin