def _define_batch_env(environment_spec, num_agents):
    """Create environments and apply all desired wrappers."""

    with tf.variable_scope("environments"):
        envs = [environment_spec.env_lambda() for _ in range(num_agents)]
        env = gym_env.T2TGymEnv(envs)
        env = py_func_batch_env.PyFuncBatchEnv(env)
        return env
Esempio n. 2
0
def define_batch_env(constructor, num_agents, xvfb=False):
    """Create environments and apply all desired wrappers."""
    with tf.variable_scope("environments"):
        envs = [
            ExternalProcessEnv(constructor, xvfb) for _ in range(num_agents)
        ]
        env = batch_env.BatchEnv(envs, blocking=False)
        env = py_func_batch_env.PyFuncBatchEnv(env)
        return env
Esempio n. 3
0
def define_batch_env(constructor, num_agents, xvfb=False):
    """Create environments and apply all desired wrappers.

  Args:
    constructor: Constructor of an OpenAI gym environment.
    num_agents: Number of environments to combine in the batch.
    xvfb: Frame buffer.
    env_processes: Whether to step environment in external processes.

  Returns:
    In-graph environments object.
  """
    with tf.variable_scope("environments"):
        envs = [
            ExternalProcessEnv(constructor, xvfb) for _ in range(num_agents)
        ]
        env = batch_env.BatchEnv(envs, blocking=False)
        env = py_func_batch_env.PyFuncBatchEnv(env)
        return env
Esempio n. 4
0
def batch_env_factory(environment_spec,
                      num_agents,
                      initial_frame_chooser=None):
    """Factory of batch envs."""
    # TODO(konradczechowski): this is temporary function handling both old and
    # new pipelines, refactor this when we move to the new pipeline.
    if environment_spec.simulated_env:
        cur_batch_env = _define_simulated_batch_env(environment_spec,
                                                    num_agents,
                                                    initial_frame_chooser)
    else:
        if "batch_env" in environment_spec:
            msg = "Environment_spec should contain only 1 of (env_lambda, batch_env)."
            assert "env_lambda" not in environment_spec, msg
            batch_env = environment_spec.batch_env
            assert batch_env.batch_size == num_agents
        else:
            batch_env = _define_batch_env(environment_spec, num_agents)
        cur_batch_env = py_func_batch_env.PyFuncBatchEnv(batch_env)
    return cur_batch_env