def define_batch_env2(config_envs, env_processes): """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. env_processes: Whether to step environment in external processes. Returns: In-graph environments object. """ with tf.variable_scope('environments'): if env_processes: envs = [] j = 0 for env in config_envs: envs.append(tools.wrappers.ExternalProcess2(env, j)) j = j + 1 # envs = [ # tools.wrappers.ExternalProcess(constructor) # for _ in range(num_agents)] else: envs = [constructor() for _ in range(num_agents)] batch_env = tools.BatchEnv(envs, blocking=not env_processes) batch_env = tools.InGraphBatchEnv(batch_env) return batch_env
def _define_batch_env(constructor, num_agents, env_processes, blocking): if env_processes: envs = [ tools.wrappers.ExternalProcess(constructor) for _ in range(num_agents)] else: envs = [constructor() for _ in range(num_agents)] batch_env = tools.BatchEnv(envs, blocking=blocking) batch_env = tools.InGraphBatchEnv(batch_env) return batch_env
def _create_test_batch_env(self, durations): envs = [] for duration in durations: env = tools.MockEnvironment(observ_shape=(2, 3), action_shape=(3, ), min_duration=duration, max_duration=duration) env = tools.wrappers.ConvertTo32Bit(env) envs.append(env) batch_env = tools.BatchEnv(envs, blocking=True) batch_env = tools.InGraphBatchEnv(batch_env) return batch_env
def define_batch_env(constructor, num_agents, env_processes, outdir=None): """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. env_processes: Whether to step environment in external processes. Returns: In-graph environments object. """ with tf.variable_scope('environments'): if env_processes: if num_agents > 1 and outdir is not None: envs = [] envs = [ tools.wrappers.ExternalProcess(constructor) for _ in range(num_agents - 1) ] video_env = constructor() import gym video_env = gym.wrappers.Monitor( video_env, outdir, video_callable=capped_cubic_video_schedule, force=True) envs.append(tools.wrappers.ExternalProcess(lambda: video_env)) else: envs = [ tools.wrappers.ExternalProcess(constructor) for _ in range(num_agents) ] else: envs = [constructor() for _ in range(num_agents)] batch_env = tools.BatchEnv(envs, blocking=not env_processes) batch_env = tools.InGraphBatchEnv(batch_env) return batch_env