robotology / gym-ignition

Framework for developing OpenAI Gym robotics environments simulated with Ignition Gazebo
https://robotology.github.io/gym-ignition
GNU Lesser General Public License v3.0
220 stars 26 forks source link

cartpole observation is never contained in observation_space #426

Open vfdev-5 opened 2 years ago

vfdev-5 commented 2 years ago

Description:

OpenAI Gym changed the way to check if observation_space contains the observation, https://github.com/openai/gym/pull/2374 and thus tasks like cartpole_discrete_balancing.py are not working anymore due to float64 vs float32 inconsistent usage:

https://github.com/robotology/gym-ignition/blob/fa14f7f8f667cf84bf226756cea158ec0f5c3d23/python/gym_ignition_environments/tasks/cartpole_discrete_balancing.py#L66-L68

vs

https://github.com/robotology/gym-ignition/blob/fa14f7f8f667cf84bf226756cea158ec0f5c3d23/python/gym_ignition_environments/tasks/cartpole_discrete_balancing.py#L94

Steps to reproduce

import gym
import numpy as np

high = np.array(
    [
        2.4,  # x
        20.0,  # dx
        np.deg2rad(12),  # q
        np.deg2rad(3 * 360),  # dq
    ]
)

# Configure the observation space
obs_high = high.copy() * 1.2
observation_space = gym.spaces.Box(
    low=-obs_high, high=obs_high, dtype=np.float32
)

x, dx, q, dq = [0.0, 0.0, 0.0, 0.0]
observation = np.array([x, dx, q, dq])

assert observation_space.contains(observation)
> AssertionError

Environment