Esempio n. 1
0
    def test_env_config(self):

        env = suite_highway.load(environment_name="highway-v0")
        self.assertEqual(env.observation_spec().shape, (35, ))
        self.assertTrue(env.action_spec().is_continuous)
        self.assertEqual(env.action_spec().shape, (2, ))
        env.close()

        # test env with specified config
        env_config = {
            "observation": {
                "type": "Kinematics",
                "vehicles_count": 3,
                "features":
                ["presence", "x", "y", "vx", "vy", "cos_h", "sin_h"],
            },
            "action": {
                "type": "DiscreteMetaAction"
            }
        }

        env = suite_highway.load(environment_name="highway-v0",
                                 env_config=env_config)
        self.assertEqual(env.observation_spec().shape, (21, ))
        self.assertTrue(env.action_spec().is_discrete)
        self.assertEqual(env.action_spec().numel, 1)

        actions = env.action_spec().sample().cpu().numpy()
        for _ in range(10):
            time_step = env.step(actions)

        self._env = env
Esempio n. 2
0
    def test_last_step(self, max_episode_steps):
        env_config = {
            "observation": {
                "type": "Kinematics",
                "vehicles_count": 3,
                "features":
                ["presence", "x", "y", "vx", "vy", "cos_h", "sin_h"],
            },
            "action": {
                "type": "DiscreteMetaAction"
            },
            "duration": max_episode_steps
        }

        self._env = suite_highway.load(environment_name="highway-v0",
                                       env_config=env_config)

        for i in range(max_episode_steps):
            actions = self._env.action_spec().sample().cpu().numpy()
            time_step = self._env.step(actions)
            if time_step.step_type == 2:
                break

        if time_step.env_info['crashed'].item() is True:
            assert time_step.discount == 0.0

        if i == max_episode_steps - 1 and not time_step.env_info[
                'crashed'].item():
            assert time_step.discount == 1.0
Esempio n. 3
0
 def test_env_info(self):
     self._env = suite_highway.load(environment_name="highway-v0")
     actions = self._env.action_spec().sample()
     time_step = self._env.step(actions.cpu().numpy())
     env_info = time_step.env_info
     for field in env_info:
         self.assertEqual(env_info[field].size, 1)
     self.assertFalse('action' in time_step.env_info.keys())
Esempio n. 4
0
    def test_thread_env(self):
        self._env = thread_environment.ThreadEnvironment(
            lambda: suite_highway.load(environment_name='highway-v0'))
        self.assertIsInstance(self._env, alf_environment.AlfEnvironment)
        self.assertEqual(torch.float32, self._env.observation_spec().dtype)

        actions = self._env.action_spec().sample()
        for _ in range(10):
            time_step = self._env.step(actions)
Esempio n. 5
0
    def test_unwrapped_env(self):
        self._env = suite_highway.load(environment_name='highway-v0')
        self.assertIsInstance(self._env, alf_environment.AlfEnvironment)
        self.assertEqual(torch.float32, self._env.observation_spec().dtype)

        actions = self._env.action_spec().sample()
        for _ in range(10):
            # unwrapped env (not thread_env or parallel_env) needs to convert
            # from tensor to array
            time_step = self._env.step(actions.cpu().numpy())
Esempio n. 6
0
 def ctor(env_id=None):
     return suite_highway.load(environment_name='highway-v0')