docstrings about vecenvs

This commit is contained in:
Peter Zhokhov
2018-09-11 12:40:23 -07:00
parent 8614c4ddbf
commit 06bdc2860c
4 changed files with 23 additions and 4 deletions

View File

@@ -26,6 +26,9 @@ class NotSteppingError(Exception):
class VecEnv(ABC):
"""
An abstract asynchronous, vectorized environment.
Used to batch data from multiple copies of an environment, so that
each observation becomes an batch of observations, and expected action is a batch of actions to
be applied per-environment.
"""
def __init__(self, num_envs, observation_space, action_space):

View File

@@ -4,7 +4,18 @@ from . import VecEnv
from .util import copy_obs_dict, dict_to_obs, obs_space_info
class DummyVecEnv(VecEnv):
"""
VecEnv that does runs multiple environments sequentially, that is,
the step and reset commands are send to one environment at a time.
Useful when debugging and when num_env == 1 (in the latter case,
avoids communication overhead)
"""
def __init__(self, env_fns):
"""
Arguments:
env_fns: iterable of callables functions that build environments
"""
self.envs = [fn() for fn in env_fns]
env = self.envs[0]
VecEnv.__init__(self, len(env_fns), env.observation_space, env.action_space)

View File

@@ -19,8 +19,7 @@ _NP_TO_CT = {np.float32: ctypes.c_float,
class ShmemVecEnv(VecEnv):
"""
An AsyncEnv that uses multiprocessing to run multiple
environments in parallel.
Optimized version of SubprocVecEnv that uses shared variables to communicate observations.
"""
def __init__(self, env_fns, spaces=None):

View File

@@ -32,9 +32,15 @@ def worker(remote, parent_remote, env_fn_wrapper):
class SubprocVecEnv(VecEnv):
"""
VecEnv that runs multiple environments in parallel in subproceses and communicates with them via pipes.
Recommended to use when num_envs > 1 and step() can be a bottleneck.
"""
def __init__(self, env_fns, spaces=None):
"""
envs: list of gym environments to run in subprocesses
Arguments:
env_fns: iterable of callables - functions that create environments to run in subprocesses. Need to be cloud-pickleable
"""
self.waiting = False
nenvs = len(env_fns)