robosuite icon indicating copy to clipboard operation
robosuite copied to clipboard

[Error] GymWrapper and gym.utils.env_checker.check_env

Open RayYoh opened this issue 2 years ago • 1 comments

My code:

import numpy as np
import gym
from gym.utils.env_checker import check_env

import robosuite as suite
from robosuite.wrappers import GymWrapper
from robosuite import load_controller_config
gym.logger.set_level(40) # Block warning

if __name__ == "__main__":

    # load OSC controller to use for all environments
    controller = load_controller_config(default_controller="JOINT_VELOCITY")

    # these arguments are the same for all envs
    config = {
        "controller_configs": controller,
        "horizon": 500,
        "control_freq": 20,   # control should happen fast enough so that simulation looks smooth
        "reward_shaping": True,    # use dense rewards
        "reward_scale": 1.0,
        "use_camera_obs": False,
        "ignore_done": False,
        "hard_reset": False,
        "has_offscreen_renderer": False,
        "has_renderer": True,
    }
    # create environment instance
    env = suite.make(
        "Lift", # try with other tasks like "Stack" and "Door"
        robots="Panda",  # try with other robots like "Sawyer" and "Jaco"
        **config,
    )
    env = GymWrapper(env)
    check_env(env)
    print(env.name)
    # reset the environment
    obs = env.reset()
    print(env.action_space)
    print(env.observation_space.high)
    print(env.reward_range)
    for i_episode in range(20):
        observation = env.reset()
        for t in range(500):
            env.render()
            action = env.action_space.sample()
            observation, reward, done, info = env.step(action)
            print(reward)
            if done:
                print("Episode finished after {} timesteps".format(t + 1))
                break

When I run this script, I get an error that 'The observation returned by the reset() method does not match the given observation space`. In addition, the observation space is [-inf, inf], and how can I normalize it?

RayYoh avatar May 19 '22 06:05 RayYoh

Hello, I was able to solve this by changing the data type of the observation space immediately after initializing the environment as follows: env = GymWrapper(env) env.observation_space.dtype = np.float64

agb24 avatar Sep 04 '22 20:09 agb24