Ejemplo n.º 1
0
def model_vector_env(env: EnvType) -> BaseEnv:
    """Returns a VectorizedEnv wrapper around the given environment.

    To obtain worker configs, one can call get_global_worker().

    Args:
        env (EnvType): The input environment (of any supported environment
            type) to be convert to a _VectorizedModelGymEnv (wrapped as
            an RLlib BaseEnv).

    Returns:
        BaseEnv: The BaseEnv converted input `env`.
    """
    worker = get_global_worker()
    worker_index = worker.worker_index
    if worker_index:
        env = _VectorizedModelGymEnv(
            make_env=worker.make_sub_env_fn,
            existing_envs=[env],
            num_envs=worker.num_envs,
            observation_space=env.observation_space,
            action_space=env.action_space,
        )
    return convert_to_base_env(
        env,
        make_env=worker.make_sub_env_fn,
        num_envs=worker.num_envs,
        remote_envs=False,
        remote_env_batch_wait_ms=0,
    )
Ejemplo n.º 2
0
 def test_nested_tuple_async(self):
     self.do_test_nested_tuple(lambda _: convert_to_base_env(NestedTupleEnv()))
Ejemplo n.º 3
0
 def test_nested_dict_async(self):
     self.do_test_nested_dict(lambda _: convert_to_base_env(NestedDictEnv()))
Ejemplo n.º 4
0
 def test_check_correct_env(self):
     env = self._make_base_env()
     check_env(env)
     env = gym.make("CartPole-v0")
     env = convert_to_base_env(env)
     check_env(env)