Ejemplo n.º 1
0
def make_mujoco_env(env_id, seed, allow_early_resets=True):
    """
    Create a wrapped, monitored gym.Env for MuJoCo.

    :param env_id: (str) the environment ID
    :param seed: (int) the inital seed for RNG
    :param allow_early_resets: (bool) allows early reset of the environment
    :return: (Gym Environment) The mujoco environment
    """
    set_global_seeds(seed + 10000 * mpi_rank_or_zero())
    env = gym.make(env_id)
    env = Monitor(env, os.path.join(logger.get_dir(), '0'), allow_early_resets=allow_early_resets)
    env.seed(seed)
    return env
Ejemplo n.º 2
0
def make_robotics_env(env_id, seed, rank=0, allow_early_resets=True):
    """
    Create a wrapped, monitored gym.Env for MuJoCo.

    :param env_id: (str) the environment ID
    :param seed: (int) the inital seed for RNG
    :param rank: (int) the rank of the environment (for logging)
    :param allow_early_resets: (bool) allows early reset of the environment
    :return: (Gym Environment) The robotic environment
    """
    set_global_seeds(seed)
    env = gym.make(env_id)
    keys = ['observation', 'desired_goal']
    # TODO: remove try-except once most users are running modern Gym
    try:  # for modern Gym (>=0.15.4)
        from gym.wrappers import FilterObservation, FlattenObservation
        env = FlattenObservation(FilterObservation(env, keys))
    except ImportError:  # for older gym (<=0.15.3)
        from gym.wrappers import FlattenDictWrapper  # pytype:disable=import-error
        env = FlattenDictWrapper(env, keys)
    env = Monitor(env,
                  logger.get_dir()
                  and os.path.join(logger.get_dir(), str(rank)),
                  info_keywords=('is_success', ),
                  allow_early_resets=allow_early_resets)
    env.seed(seed)
    return env
Ejemplo n.º 3
0
 def _thunk():
     env = make_atari(env_id)
     env.seed(seed + rank)
     env = Monitor(env,
                   logger.get_dir()
                   and os.path.join(logger.get_dir(), str(rank)),
                   allow_early_resets=allow_early_resets)
     return wrap_deepmind(env, **wrapper_kwargs)
Ejemplo n.º 4
0
 def _init():
     if isinstance(env_id, str):
         env = gym.make(env_id)
         if len(env_kwargs) > 0:
             warnings.warn("No environment class was passed (only an env ID) so `env_kwargs` will be ignored")
     else:
         env = env_id(**env_kwargs)
     if seed is not None:
         env.seed(seed + rank)
         env.action_space.seed(seed + rank)
     # Wrap the env in a Monitor wrapper
     # to have additional training information
     monitor_path = os.path.join(monitor_dir, str(rank)) if monitor_dir is not None else None
     # Create the monitor folder if needed
     if monitor_path is not None:
         os.makedirs(monitor_dir, exist_ok=True)
     env = Monitor(env, filename=monitor_path)
     # Optionally, wrap the environment with the provided wrapper
     if wrapper_class is not None:
         env = wrapper_class(env)
     return env