コード例 #1
0
 def test_pickleable(self):
     env = IdentificationEnv(CartpoleEnv, dict(obs_noise=5.))
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert env.mdp_args == round_trip.mdp_args
     assert round_trip.env.obs_noise == env.env.obs_noise
     step_env(round_trip)
コード例 #2
0
ファイル: test_new_api.py プロジェクト: Neo-X/metaworld
def test_all_mt50():
    mt50 = MT50()
    train_env_instances = {
        env_name: env_cls()
        for (env_name, env_cls) in mt50.train_classes.items()
    }
    train_env_rand_vecs = check_tasks_unique(mt50.train_tasks,
                                             mt50._train_classes.keys())
    for task in mt50.train_tasks:
        env = train_env_instances[task.env_name]
        env.set_task(task)
        obs = env.reset()
        assert np.any(obs[-3:] != np.array([0, 0, 0]))
        assert env.observation_space.shape == (39, )
        assert env.random_init == True
        old_obj_init = env.obj_init_pos
        old_target_pos = env._target_pos
        step_env(env, max_path_length=STEPS, render=False)
        assert np.all(np.allclose(old_obj_init, env.obj_init_pos))
        assert np.all(np.allclose(old_target_pos, env._target_pos))
    # only needs to be done for 50 environments once
    check_target_poss_unique(train_env_instances, train_env_rand_vecs)
    for env in train_env_instances.values():
        env.close()
    del train_env_instances

    assert len(mt50.test_classes) == 0
    assert len(mt50.test_tasks) == 0
    train_test_rand_vecs = set()
    for rand_vecs in train_env_rand_vecs.values():
        for rand_vec in rand_vecs:
            train_test_rand_vecs.add(tuple(rand_vec))
    assert len(train_test_rand_vecs) == 50 * 50
コード例 #3
0
    def test_pickleable(self):

        env = Swimmer3DHillEnv(regen_terrain=False)
        round_trip = pickle.loads(pickle.dumps(env))
        assert round_trip
        assert round_trip.difficulty == env.difficulty
        step_env(round_trip)
コード例 #4
0
ファイル: test_bullet_env.py プロジェクト: j-donahue/garage-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()
コード例 #5
0
def test_hidden_goal_envs():

    for env_key, env_cls in ALL_V2_ENVIRONMENTS_GOAL_HIDDEN.items():
        assert "goal-hidden" in env_key
        assert "GoalHidden" in env_cls.__name__
        state_before = np.random.get_state()
        env = env_cls(seed=5)
        env2 = env_cls(seed=5)
        step_env(env, max_path_length=3, iterations=3, render=False)

        first_target = env._target_pos
        env.reset()
        second_target = env._target_pos

        assert (first_target == second_target).all()
        env.reset()
        env2.reset()
        assert (env._target_pos == env2._target_pos).all()
        state_after = np.random.get_state()
        for idx, (state_before_idx,
                  state_after_idx) in enumerate(zip(state_before,
                                                    state_after)):
            if idx == 1:
                assert (state_before_idx == state_after_idx).all()
            else:
                assert state_before_idx == state_after_idx
コード例 #6
0
ファイル: test_point_env.py プロジェクト: seba-1511/metarl
 def test_pickleable(self):
     env = PointEnv()
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     step_env(round_trip)
     env.close()
     round_trip.close()
コード例 #7
0
ファイル: test_new_api.py プロジェクト: Neo-X/metaworld
def test_all_mt10():
    mt10 = MT10()
    train_env_instances = {
        env_name: env_cls()
        for (env_name, env_cls) in mt10.train_classes.items()
    }
    train_env_rand_vecs = check_tasks_unique(mt10.train_tasks,
                                             mt10._train_classes.keys())
    for task in mt10.train_tasks:
        env = train_env_instances[task.env_name]
        env.set_task(task)
        env.reset()
        old_obj_init = env.obj_init_pos
        old_target_pos = env._target_pos
        step_env(env, max_path_length=STEPS, render=False)
        assert np.all(np.allclose(old_obj_init, env.obj_init_pos))
        assert np.all(np.allclose(old_target_pos, env._target_pos))
    for env in train_env_instances.values():
        env.close()
    del train_env_instances

    assert len(mt10.test_classes) == 0
    assert len(mt10.test_tasks) == 0
    train_test_rand_vecs = set()
    for rand_vecs in train_env_rand_vecs.values():
        for rand_vec in rand_vecs:
            train_test_rand_vecs.add(tuple(rand_vec))
    assert len(train_test_rand_vecs) == 10 * 50
コード例 #8
0
 def test_pickleable(self):
     env = AntGatherEnv(n_apples=1)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.n_apples == env.n_apples
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #9
0
 def test_pickleable(self):
     env = SwimmerEnv(ctrl_cost_coeff=1.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.ctrl_cost_coeff == env.ctrl_cost_coeff
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #10
0
 def test_pickleable(self):
     env = CarParkingEnv(random_start_range=2.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.random_start_range == env.random_start_range
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #11
0
 def test_pickleable(self):
     env = GridWorldEnv(desc="8x8")
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.start_state == env.start_state
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #12
0
 def test_all_pickleable(self, domain_name, task_name):
     env = DmControlEnv.from_suite(domain_name, task_name)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     # Skip rendering because it causes TravisCI to run out of memory
     step_env(round_trip, render=False)
     round_trip.close()
     env.close()
コード例 #13
0
 def test_can_step_and_render(self):
     ob_space = self.env.observation_space
     act_space = self.env.action_space
     ob = self.env.reset()
     assert ob_space.contains(ob)
     a = act_space.sample()
     assert act_space.contains(a)
     step_env(self.env, n=10, render=True)
コード例 #14
0
 def test_pickleable(self):
     env = Walker2DEnv(ctrl_cost_coeff=3.)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.ctrl_cost_coeff == env.ctrl_cost_coeff
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #15
0
 def test_pickleable(self):
     inner_env = CartpoleEnv(obs_noise=5.)
     env = SlidingMemEnv(inner_env, n_steps=10)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.n_steps == env.n_steps
     assert round_trip.env.obs_noise == env.env.obs_noise
     step_env(round_trip)
コード例 #16
0
 def test_pickleable(self):
     env = CartpoleSwingupEnv(obs_noise=1.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.obs_noise == env.obs_noise
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #17
0
 def test_pickleable(self):
     env = SimpleHumanoidEnv(alive_bonus=1.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.alive_bonus == env.alive_bonus
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #18
0
ファイル: test_noisy_env.py プロジェクト: Mee321/HAPG_exp
 def test_pickleable(self):
     inner_env = CartpoleEnv(frame_skip=10)
     env = NoisyObservationEnv(inner_env, obs_noise=5.)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.obs_noise == env.obs_noise
     assert round_trip.env.frame_skip == env.env.frame_skip
     step_env(round_trip)
コード例 #19
0
 def test_pickleable(self):
     env = SwimmerMazeEnv(n_bins=2)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip._n_bins == env._n_bins
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #20
0
 def test_pickleable(self):
     env = HalfCheetahHillEnv(regen_terrain=False)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.difficulty == env.difficulty
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #21
0
ファイル: test_noisy_env.py プロジェクト: Mee321/HAPG_exp
 def test_pickleable(self):
     inner_env = CartpoleEnv(frame_skip=10)
     env = DelayedActionEnv(inner_env, action_delay=10)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.action_delay == env.action_delay
     assert round_trip.env.frame_skip == env.env.frame_skip
     step_env(round_trip)
コード例 #22
0
 def test_pickleable(self):
     inner_env = CartpoleEnv(obs_noise=5.)
     env = NormalizedEnv(inner_env, scale_reward=10.)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip._scale_reward == env._scale_reward
     assert round_trip.env.obs_noise == env.env.obs_noise
     step_env(round_trip)
コード例 #23
0
 def test_pickleable(self):
     env = AntEnv(action_noise=1.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.action_noise == env.action_noise
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #24
0
 def test_pickleable(self):
     env = HopperEnv(alive_coeff=2.0)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip.alive_coeff == env.alive_coeff
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #25
0
 def test_pickleable(self):
     inner_env = CartpoleEnv(obs_noise=5.)
     env = OcclusionEnv(inner_env, [1])
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     obs = inner_env.reset()
     assert round_trip.occlude(obs) == env.occlude(obs)
     assert round_trip.env.obs_noise == env.env.obs_noise
     step_env(round_trip)
コード例 #26
0
 def test_can_step_and_render(self, domain_name, task_name):
     env = DmControlEnv(domain_name, task_name)
     ob_space = env.observation_space
     act_space = env.action_space
     ob = env.reset()
     assert ob_space.contains(ob)
     a = act_space.sample()
     assert act_space.contains(a)
     step_env(env, n=10, render=True)
コード例 #27
0
ファイル: test_benchmarks.py プロジェクト: pkol/metaworld
def test_all_mt50():
    mt50_env = MT50()
    tasks = mt50_env.sample_tasks(51)
    for t in tasks:
        mt50_env.set_task(t)
        step_env(mt50_env, max_path_length=3)

    mt50_env.close()
    del mt50_env
コード例 #28
0
 def test_pickleable(self):
     env = IdentificationEnv(PointEnv, dict(goal=(1., 2.)))
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert env.mdp_args == round_trip.mdp_args
     assert np.array_equal(round_trip.env._goal, env.env._goal)
     step_env(round_trip)
     round_trip.close()
     env.close()
コード例 #29
0
 def test_all_pickleable(self, domain_name, task_name):
     env = DMControlEnv.from_suite(domain_name, task_name)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     # Skip rendering because it causes TravisCI to run out of memory
     # Sometimes random actions lead to physics errors
     with env._env.physics.suppress_physics_errors():
         step_env(env, visualize=False)
     round_trip.close()
     env.close()
コード例 #30
0
 def test_pickleable(self):
     inner_env = PointEnv(goal=(1., 2.))
     env = NormalizedEnv(inner_env, scale_reward=10.)
     round_trip = pickle.loads(pickle.dumps(env))
     assert round_trip
     assert round_trip._scale_reward == env._scale_reward
     assert np.array_equal(round_trip.env._goal, env.env._goal)
     step_env(round_trip)
     round_trip.close()
     env.close()