def _thunk(): if env_id.startswith("dm"): _, 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 = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=4) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = Monitor( env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) if is_atari: if len(env.observation_space.shape) == 3: env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=84, height=84) env = ClipRewardEnv(env) elif len(env.observation_space.shape) == 3: # env = EpisodicLifeEnv(env) # if 'FIRE' in env.unwrapped.get_action_meanings(): # env = FireResetEnv(env) env = WarpFrame(env, width=64, height=64) # raise NotImplementedError( # "CNN models work only for atari,\n" # "please use a custom wrapper for a custom pixel input env.\n" # "See wrap_deepmind for an example.") # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = TransposeImage(env, op=[2, 0, 1]) return env
def make_experiment_env(params, train): clear = MortalKombat2.\ make_mortal_kombat2_env(difficulties=params["difficulties"], arenas=params["arenas"], left_players=params["left_players"], right_players=params["right_players"], controllable_players=params["controllable_players"], actions=params["actions"], state_versions=params["state_versions"]) env = FrameskipWrapper(clear, skip=params["frameskip"]) if params["max_episode_length"]: env = MaxEpLenWrapper(env, max_len=params["params"] // params["frameskip"]) env = WarpFrame(env, 48, 48) if train: env = Monitor(env, info_keywords=("P1_rounds", "P2_rounds", "P1_health", "P2_health", "steps", "difficulty", "arena", "P1", "P2", "state_version")) return env else: return clear, env, env
def _thunk(): if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dmc2gym.make(domain_name=domain, task_name=task) env = ClipAction(env) elif env_id.startswith("rrc"): _, ac_type, ac_wrapper = env_id.split('.') ts_relative, sa_relative = False, False scaled_ac, task_space = False, False if ac_wrapper.split('-')[0] == 'task': task_space = True ts_relative = ac_wrapper.split('-')[-1] == 'rel' elif ac_wrapper.split('-')[0] == 'scaled': scaled_ac = True sa_relative = ac_wrapper.split('-')[-1] == 'rel' env = rrc_utils.build_env_fn( action_type=ac_type, initializer=None, scaled_ac=scaled_ac, task_space=task_space, sa_relative=sa_relative, ts_relative=ts_relative, goal_relative=True, rew_fn='step')() 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 = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=4) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = Monitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) if is_atari: if len(env.observation_space.shape) == 3: env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=84, height=84) env = ClipRewardEnv(env) elif len(env.observation_space.shape) == 3: raise NotImplementedError( "CNN models work only for atari,\n" "please use a custom wrapper for a custom pixel input env.\n" "See wrap_deepmind for an example.") # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = TransposeImage(env, op=[2, 0, 1]) return env
def _thunk(): print(f"Using {env_id} environment") if env_id == "Warehouse": env = Warehouse(parameters) elif env_id == 'Sumo': # todo currently just using loop_network scene params = {'scene': "loop_network", 'libsumo': True} env = LoopNetwork(seed, params) else: if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dmc2gym.make(domain_name=domain, task_name=task) env = ClipAction(env) 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 = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=4) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if env_id not in ["Warehouse", "Sumo"]: if log_dir is not None: env = Monitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) if is_atari: if len(env.observation_space.shape) == 3: env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=84, height=84) env = ClipRewardEnv(env) elif len(env.observation_space.shape) == 3: raise NotImplementedError( "CNN models work only for atari,\n" "please use a custom wrapper for a custom pixel input env.\n" "See wrap_deepmind for an example.") # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = TransposeImage(env, op=[2, 0, 1]) return env
def thunk(): env = gym.make(gym_id) env = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=4) env = gym.wrappers.RecordEpisodeStatistics(env) if args.capture_video: if idx == 0: env = Monitor(env, f"videos/{experiment_name}") env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=84, height=84) env = ClipRewardEnv(env) env.seed(seed) env.action_space.seed(seed) env.observation_space.seed(seed) return env
def _thunk(): if env_id == "dummy_env": env = DummyEnv() elif env_id == "dummy_multi_head_env": env = DummyMultiHeadEnv() elif env_id == "platform": env = PlatformWrapper() 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 = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=4) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = Monitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) if is_atari: if len(env.observation_space.shape) == 3: env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=84, height=84) env = ClipRewardEnv(env) elif len(env.observation_space.shape) == 3: raise NotImplementedError( "CNN models work only for atari,\n" "please use a custom wrapper for a custom pixel input env.\n" "See wrap_deepmind for an example.") # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = TransposeImage(env, op=[2, 0, 1]) return env
def __init__( self, env: gym.Env, frame_skip: int = 4, screen_size: int = 84, terminal_on_life_loss: bool = True, clip_reward: bool = True, ): env = MaxAndSkipEnv(env, skip=frame_skip) if terminal_on_life_loss: env = EpisodicLifeEnv(env) if "FIRE" in env.unwrapped.get_action_meanings(): env = FireResetEnv(env) env = WarpFrame(env, width=screen_size, height=screen_size) if clip_reward: env = ClipRewardEnv(env) super(AtariWrapper, self).__init__(env)