benelot / pybullet-gym

Open-source implementations of OpenAI Gym MuJoCo environments for use with the OpenAI Gym Reinforcement Learning Research Platform.
https://pybullet.org/
Other
831 stars 124 forks source link

Issues Rendering Environments After Training #19

Closed MaxLikesMath closed 5 years ago

MaxLikesMath commented 5 years ago

So, when I run a simple script such as `import gym import numpy as np import pybulletgym.envs import gym.envs

env = gym.make('HumanoidPyBulletEnv-v0') env.render(mode='human') done = False state = env.reset() for step in range(1000): if done: state = env.reset() action = env.action_space.sample() print(state.shape) state, reward, done, info = env.step(action) print(info) env.render(mode='human')`

The environment renders and displays just fine, however when I train an agent then test it, the environment won't render. It doesn't crash, it just won't display for some odd reason. The function I use to display the agent is as follows `def test(episodes=10): for episode in range(episodes): state = env.reset() # Reset environment and record the starting state env.render(mode = 'human') done = False

    while not done:
        action = select_action(state)
        # Step through environment using chosen action
        state, reward, done, _ = env.step(action.detach().numpy())
        env.render(mode='human')`

Thanks!

benelot commented 5 years ago

I will check if I can reproduce this on my machine.

MaxLikesMath commented 5 years ago

I just did a bit of a work around. It ran fine when I used my saved model in another script where the environment was rendered during every iteration. It seemed to be caused by be not rendering it for training then trying to render it for testing in the same script.

benelot commented 5 years ago

Oh yeah, that is a limitation of pybulley itself which only defines once per physics server (and thus once per script if you have only one server started) if graphics objects are created for rendering or not. So your workaround is all I can do for you. If you would like to get the feature, post the issue to the bullet3 repository, which provides the pybullet library. Thanks for reporting!