def step_bullet_kuka_env(n_steps=1000): """Load, step, and visualize a Bullet Kuka environment. Args: n_steps (int): number of steps to run. """ # Construct the environment env = BulletEnv( gym.make('KukaBulletEnv-v0', renders=True, isDiscrete=True, maxSteps=10000000)) # Reset the environment and launch the viewer env.reset() env.render() # Step randomly until interrupted steps = 0 while steps < n_steps: _, _, done, _ = env.step(env.action_space.sample()) if done: break steps += 1
def test_can_step(env_ids): """Test Bullet environments can step""" for env_id in env_ids: # extract id string env_id = env_id.replace('- ', '') if env_id == 'KukaCamBulletEnv-v0': # Kuka environments calls py_bullet.resetSimulation() in reset() # unconditionally, which globally resets other simulations. So # only one Kuka environment is tested. continue if env_id in _get_unsupported_env_list(): pytest.skip('Skip unsupported Bullet environments') env = BulletEnv(env_name=env_id) ob_space = env.observation_space act_space = env.action_space env.reset() ob = ob_space.sample() assert ob_space.contains(ob) a = act_space.sample() assert act_space.contains(a) # Skip rendering because it causes TravisCI to run out of memory step_env(env, render=False) env.close()
def test_time_limit_env(): """Test BulletEnv emits done signal when time limit expiration occurs. After setting max_episode_steps=50, info['BulletEnv.TimeLimitTerminated'] is expected to be True after 50 steps. """ env = BulletEnv(gym.make('MinitaurBulletEnv-v0')) env.env._max_episode_steps = 50 env.reset() for _ in range(50): _, _, done, info = env.step(env.spec.action_space.sample()) assert not done and info['TimeLimit.truncated'] assert info['BulletEnv.TimeLimitTerminated']
def test_can_step(env_ids): """Test Bullet environments can step""" for env_id in env_ids: # extract id string env_id = env_id.replace('- ', '') if env_id in ('KukaCamBulletEnv-v0', 'KukaDiverseObjectGrasping-v0'): # Kuka environments calls pybullet.resetSimulation() in reset() # unconditionally, which globally resets other simulations. So # only one Kuka environment is tested. continue env = BulletEnv(env_id) ob_space = env.observation_space act_space = env.action_space env.reset() ob = ob_space.sample() assert ob_space.contains(ob) a = act_space.sample() assert act_space.contains(a) # Skip rendering because it causes TravisCI to run out of memory step_env(env, visualize=False) env.close()