Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError cannot import name ‘rendering‘ from ‘gym.envs.classic_control‘ #600

Closed
GuoPingPan opened this issue Mar 4, 2023 · 4 comments
Labels
bug Something isn't working env Questions about RL environment

Comments

@GuoPingPan
Copy link

When I using ding to deploy the agent with gym-hybrid env,I got the error

ImportError cannot import name ‘rendering‘ from ‘gym.envs.classic_control‘

my code is

from ding.bonus import PPOF

def hybrid_moving_deploy():
    agent = PPOF(env='hybrid_moving', exp_name='./hybrid_moving_demo')
    agent.deploy(enable_save_replay=True)

if __name__ == "__main__":
    hybrid_moving_deploy()

I found the problem is that ding requires gym=0.25.1 which doesn't include rendering, but in gym_hybrid_env.py, it use env.render

def step(self, action: Dict) -> BaseEnvTimestep:
        if self._act_scale:
            if self._env_id == 'HardMove-v0':
                action = [
                    action['action_type'], [affine_transform(i, min_val=-1, max_val=1) for i in action['action_args']]
                ]
            else:
                # acceleration_value.
                action['action_args'][0] = affine_transform(action['action_args'][0], min_val=0, max_val=1)
                # rotation_value. Following line can be omitted, because in the affine_transform function,
                # we have already done the clip(-1,1) operation
                action['action_args'][1] = affine_transform(action['action_args'][1], min_val=-1, max_val=1)
                action = [action['action_type'], action['action_args']]
        if self._save_replay:
            self._frames.append(self._env.render(mode='rgb_array'))
        obs, rew, done, info = self._env.step(action)
        self._eval_episode_return += rew
        if done:
            info['eval_episode_return'] = self._eval_episode_return
            if self._save_replay:
                if self._env_id == 'HardMove-v0':
                    self._env_id = f'hardmove_n{self._cfg.num_actuators}'
                path = os.path.join(
                    self._replay_path, '{}_episode_{}.gif'.format(self._env_id, self._save_replay_count)
                )
                self.display_frames_as_gif(self._frames, path)
                self._frames = []
                self._save_replay_count += 1

Notice:
my python version is 3.9, and I install ding by git clone and pip install -e .
I found conda install only support python3.7, but also wrong.

I just want to get the video result of gym-hybrid, how should I do?
And if I can keep using python3.9 is the best.

@PaParaZz1
Copy link
Member

What is the gym version in your environment? For some compatibility problem, you need to train gym-hybrid with gym==0.25.1 and visualize replay videos with gym==0.22.0.

@PaParaZz1 PaParaZz1 added bug Something isn't working env Questions about RL environment labels Mar 5, 2023
@GuoPingPan
Copy link
Author

What is the gym version in your environment? For some compatibility problem, you need to train gym-hybrid with gym==0.25.1 and visualize replay videos with gym==0.22.0.

How to realize this process?
I found that the reason for the error mentioned mentioned

But I don't know the quickly and right way to deal with it.

If you can provide an official way to deal with the confict between the training gym version and the visualize one, I will be very appreciate it.

What's more, I think you also can put the solution in the FAQ or somewhere(like the README.md for the gym-hybrid env) to help more users.

@PaParaZz1
Copy link
Member

OK, we will prepare a detailed demo for the visualization of gym-hybrid in one week.

@GuoPingPan
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working env Questions about RL environment
Projects
None yet
Development

No branches or pull requests

2 participants