Example #1
0
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()
Example #2
0
 def test_all_gym_envs(self, spec):
     if spec._env_name.startswith('Defender'):
         pytest.skip(
             'Defender-* envs bundled in atari-py 0.2.x don\'t load')
     if any(name == spec.id for name in _get_unsupported_env_list()):
         pytest.skip('Skip unsupported Bullet environments')
     env = GarageEnv(spec.make())
     step_env_with_gym_quirks(env, spec)
Example #3
0
def test_pickleable(env_ids):
    """Test Bullet environments are pickle-able"""
    for env_id in env_ids:
        # extract id string
        env_id = env_id.replace('- ', '')
        if env_id in _get_unsupported_env_list():
            pytest.skip('Skip unsupported Bullet environments')
        env = BulletEnv(env_name=env_id)
        round_trip = pickle.loads(pickle.dumps(env))
        assert round_trip
        env.close()
Example #4
0
 def test_all_gym_envs_pickleable(self, spec):
     if spec._env_name.startswith('Defender'):
         pytest.skip(
             'Defender-* envs bundled in atari-py 0.2.x don\'t load')
     if any(name == spec.id for name in _get_unsupported_env_list()):
         pytest.skip('Skip unsupported Bullet environments')
     env = GarageEnv(env_name=spec.id)
     step_env_with_gym_quirks(env,
                              spec,
                              n=1,
                              render=True,
                              serialize_env=True)
Example #5
0
def test_pickle_creates_new_server(env_ids):
    """Test pickling a Bullet environment creates a new connection.

    If all pickling create new connections, no repetition of client id
    should be found.
    """
    n_env = 4
    for env_id in env_ids:
        # extract id string
        env_id = env_id.replace('- ', '')
        if env_id in _get_unsupported_env_list():
            pytest.skip('Skip unsupported Bullet environments')
        bullet_env = BulletEnv(env_name=env_id)
        envs = [pickle.loads(pickle.dumps(bullet_env)) for _ in range(n_env)]
        id_set = set()

        if hasattr(bullet_env.env, '_pybullet_client'):
            id_set.add(bullet_env.env._pybullet_client._client)
            for e in envs:
                new_id = e._env._pybullet_client._client
                assert new_id not in id_set
                id_set.add(new_id)
        elif hasattr(bullet_env.env, '_p'):
            if isinstance(bullet_env.env._p, BulletClient):
                id_set.add(bullet_env.env._p._client)
                for e in envs:
                    new_id = e._env._p._client
                    assert new_id not in id_set
                    id_set.add(new_id)
            else:
                # Some environments have _p as the pybullet module, and they
                # don't store client id, so can't check here
                pass

        for env in envs:
            env.close()