我正在尝试在
cleanrl
环境上运行 Pendulum-v1
。我通过转到 here 并将默认值 env-id
更改为 parser.add_argument("--env-id", type=str, default="Pendulum-v1",help="the id of the environment")
来做到这一点
但是,我不断收到错误 -
NotImplementedError: Box([-1. -1. -8.], [1. 1. 8.], (3,), <class 'numpy.float32'>) observation space is not supported
因此,我将这个错误调试到从
SB3
导入的ReplayBuffer中。这是问题函数 -
def get_obs_shape(
observation_space: spaces.Space,
) -> Union[Tuple[int, ...], Dict[str, Tuple[int, ...]]]:
"""
Get the shape of the observation (useful for the buffers).
:param observation_space:
:return:
"""
if isinstance(observation_space, spaces.Box):
return observation_space.shape
elif isinstance(observation_space, spaces.Discrete):
# Observation is an int
return (1,)
elif isinstance(observation_space, spaces.MultiDiscrete):
# Number of discrete features
return (int(len(observation_space.nvec)),)
elif isinstance(observation_space, spaces.MultiBinary):
# Number of binary features
return observation_space.shape
elif isinstance(observation_space, spaces.Dict):
return {key: get_obs_shape(subspace) for (key, subspace) in observation_space.spaces.items()} # type: ignore[misc]
else:
raise NotImplementedError(f"{observation_space} observation space is not supported")
我尝试打印
observation_space
形状,这就是我得到的 -
Box([-1. -1. -8.], [1. 1. 8.], (3,), float32)
。知道为什么 SB3 不接受我的观察形状吗?
我觉得问题可能出在gymnasium或者gym套餐的版本上。我只是发现gymnasium==0.29.0 和gym==0.24 中的spaces.Box() 类型不相同。也许您将 sb3 与gymnasium一起使用,但您的 Pendulum-v1 环境正在使用gym。