def make_env_by_id(env_id, seed, rank, episode_life=True): """Used for regular gym environments and Atari Envs""" def _init(): if env_id.startswith("dm"): import dm_control2gym _, domain, task = env_id.split('-') env = dm_control2gym.make(domain_name=domain, task_name=task) else: env = gym.make(env_id) is_atari = hasattr(gym.envs, 'atari') and isinstance( env.unwrapped, gym.envs.atari.atari_env.AtariEnv) if is_atari: env = make_atari(env_id) env.seed(seed + rank) if is_atari: env = wrap_deepmind(env, episode_life=episode_life, clip_rewards=False, frame_stack=False, scale=False) obs_shape = env.observation_space.shape if len(obs_shape) == 3: env = TransposeImage(env) env = FrameStack(env, 4) env = ReturnAndObsWrapper(env) return env set_global_seeds(seed) return _init
def make_env(env_fn, seed, rank): """ Utility function for multiprocessed env. :param env_id: (str) the environment ID :param num_env: (int) the number of environment you wish to have in subprocesses :param seed: (int) the inital seed for RNG """ def _init(): env = env_fn() env.seed(seed + rank) env = ReturnAndObsWrapper(env) return env set_global_seeds(seed) return _init