def _thunk(): if callable(env_id): env = env_id() elif 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 = make_atari(env_id) env.seed(seed + rank) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: env = bench.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 = wrap_deepmind(env) return env
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: raise 'Atari not supported' env.seed(seed + rank) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = bench.Monitor( env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) # 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(): random_seed(seed) if 'diabcombolockhallway' == env_id: env = DiabolicalLockMaze(horizon=horizon, seed=seed, noise=noise) elif 'maze' == env_id: env = build_env_maze(horizon=100, size=20) elif 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) if not 'combolock' in env_id: env.seed(seed + rank) env = OriginalReturnWrapper(env) #aggregate episode return 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) return env
def _thunk(): if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dm_control2gym.make(domain_name=domain, task_name=task) elif env_id in ['duckietown']: from a2c_ppo_acktr.duckietown.env import launch_env from a2c_ppo_acktr.duckietown.wrappers import NormalizeWrapper, ImgWrapper,\ DtRewardWrapper, ActionWrapper, ResizeWrapper from a2c_ppo_acktr.duckietown.teacher import PurePursuitExpert env = launch_env() env = ResizeWrapper(env) env = NormalizeWrapper(env) env = ImgWrapper(env) env = ActionWrapper(env) env = DtRewardWrapper(env) elif env_id in retro_envs: env = make_retro(game=env_id) #env = SuperMarioKartDiscretizer(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 = make_atari(env_id, max_episode_steps=max_steps) env.seed(seed + rank) #TODO: Figure out what todo here if is_atari: env = TimeLimitMask(env) if log_dir is not None: env = bench.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 = wrap_deepmind(env) elif env_id in retro_envs: if len(env.observation_space.shape) == 3: env = wrap_deepmind_retro(env, frame_stack=0) elif len(env.observation_space.shape) == 3: if env_id not in ['duckietown'] and env_id not in retro_envs: 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 if env_id not in ['duckietown']: 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]) if time: env = TimeFeatureWrapper(env) return env
def _thunk(): if "mario" in env_id: env = gym_super_mario_bros.make('SuperMarioBros-v0') env = JoypadSpace(env, SIMPLE_MOVEMENT) elif 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 = make_atari(env_id) env.seed(seed + rank) if log_dir is not None: env = bench.Monitor(env, os.path.join(log_dir, str(rank))) if is_atari: env = wrap_deepmind(env, clip_rewards=False) # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if "mario" in env_id: env = wrap_deepmind(env, clip_rewards=False, episode_life=False) env = WrapPyTorchMario(env) elif len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = WrapPyTorch(env) return env
def _thunk(): if env_id.startswith("Pomme"): env = envs.pommerman.make_env(env_id) elif 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 = make_atari(env_id) env.seed(seed + rank) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(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: env = wrap_deepmind(env) # 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) return env
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 = make_atari(env_id) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = env if is_atari: if len(env.observation_space.shape) == 3: env = wrap_deepmind(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(): # I think this is not needed # random_seed(seed) if env_id.startswith("dm"): import dm_control2gym _, domain, task = env_id.split('-') env = dm_control2gym.make(domain_name=domain, task_name=task) else: # My code for reacher env: if env_id == 'reacher': # from gym_unity.envs.unity_env import UnityEnv # from p2_continuous_control.unity_env import UnityEnv # env = UnityEnv('p2_continuous_control/Reacher_Linux/Reacher.x86_64') env = make_reacher() 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) env = OriginalReturnWrapper(env) 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) return env
def _thunk(): if env_id == 'StockGame': env = StockGame('603399', '2017-01-01', '2017-07-10', 100000.0) elif 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 = make_atari(env_id) env.seed(seed + rank) obs_shape = env.observation_space.shape if add_timestep and len(obs_shape) == 1 \ and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: env = bench.Monitor(env, os.path.join(log_dir, str(rank))) if is_atari: env = wrap_deepmind(env) # 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 = WrapPyTorch(env) return env
def _thunk(): random_seed(seed) 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 log_dir is not None: # env = Monitor(env=env, filename=os.path.join(log_dir, str(rank)), allow_early_resets=True) env = bench.Monitor(env=env, filename=os.path.join(log_dir, str(rank)), allow_early_resets=True) if is_atari: env = wrap_deepmind(env, episode_life=episode_life, clip_rewards=False, frame_stack=False, scale=False) if not episode_life and 'FIRE' in env.unwrapped.get_action_meanings( ): env = LifeFireEnv(env) obs_shape = env.observation_space.shape if len(obs_shape) == 3: env = TransposeImage(env) env = FrameStack(env, stack_size) return env
def _thunk(): if callable(env_id): env = env_id() elif 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 = gym.make(env_id) env = gym.wrappers.AtariPreprocessing(env) env.seed(seed + rank) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: # env = gym.wrappers.Monitor(env, os.path.join(log_dir, str(rank)), force=True) pass if is_atari: if len(env.observation_space.shape) == 3: # TODO: implement same preprocessing as in deepmind # env = wrap_deepmind(env) pass return env
def _thunk(): random_seed(seed) 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) env = OriginalReturnWrapper(env) 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) return env
def _thunk(): if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dm_control2gym.make(domain_name=domain, task_name=task) elif 'Mini' in env_id: import gym_minigrid env = gym_minigrid.envs.dynamicobstacles.DynamicObstaclesEnv( size=5, n_obstacles=1) # env = gym_minigrid.envs.multiroom.MultiRoomEnv( # minNumRooms=2, maxNumRooms=2, maxRoomSize=4 # ) # import pdb; pdb.set_trace() # env = gym.make(env_id) # env = gym_minigrid.wrappers.NoOpAsync(env, costs=[2, 1]) env = gym_minigrid.wrappers.NoOpAsync(env, costs=[2, 1], which_obs='first') is_atari = hasattr(gym.envs, 'atari') and isinstance( env.unwrapped, gym.envs.atari.atari_env.AtariEnv) if is_atari: env = make_atari(env_id) is_minigrid = 'minigrid' in env_id.lower() env.seed(seed + rank) if is_minigrid: from gym_minigrid.wrappers import ImgObsWrapper, RGBImgObsWrapper, RGBImgPartialObsWrapper, FlatObsWrapper # env = RGBImgPartialObsWrapper( # env, tile_size=2) # env = ImgObsWrapper(env) env = FlatObsWrapper(env) # env.observation_space = env.observation_space['image'] if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = bench.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 = wrap_deepmind(env) elif is_minigrid: pass 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 make_dm2gym_env_obs(env_name="cheetah_run", num_repeat_action=1): """ Invoke POMDP tasks """ env_name_tuple = DM_TASKS[env_name.lower()] domain_name, task_name = env_name_tuple[0], env_name_tuple[1] env = dm_control2gym.make(domain_name=domain_name, task_name=task_name) env = PixelObservationWrapper(env=env) env = wrap_deepmind(env=env, num_repeat_action=num_repeat_action) return env
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) # ss('sss') env = env.env is_atari = hasattr(gym.envs, 'atari') and isinstance( env.unwrapped, gym.envs.atari.atari_env.AtariEnv) # print(hasattr(gym.envs, 'atari')) # print(gym.envs) # print(getattr(gym.envs, 'atari')) # print('- - '*20) # print(env.unwrapped) # print(gym.envs.atari.atari_env.AtariEnv) # # print(gym.envs.atari.atari_env.AtariEnv) # print(isinstance( # env.unwrapped, gym.envs.atari.atari_env.AtariEnv)) # print(is_atari) # ss('sss') # if is_atari: # # env = make_atari(env_id) # ss('make atari') env.seed(seed + rank) # obs_shape = env.observation_space.shape # print(str(env.__class__.__name__)) # ss('name') if str(env.__class__.__name__).find('TimeLimit') >= 0: # print('hiosdfoi '* 30) env = TimeLimitMask(env) # if log_dir is not None: # env = bench.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 = wrap_deepmind(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 # print(obs_shape) # ss('is atari') if len(obs_shape) == 3 and obs_shape[2] in [1, 3]: env = TransposeImage(env, op=[2, 0, 1]) return env
def _thunk(): if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dm_control2gym.make(domain_name=domain, task_name=task) elif 'academy' in env_id or '11' in env_id: # gfootball environments #env = football_env.create_environment( # env_name=env_id, stacked=('stacked' in state), # with_checkpoints=('with_checkpoints' in reward_experiment), # logdir=log_dir, # enable_goal_videos=dump_scores and (seed == 0), # enable_full_episode_videos=dump_full_episodes and (seed == 0), # render=render and (seed == 0), # dump_frequency=50 if render and seed == 0 else 0, # representation='extracted') env = football_env.create_environment( env_name=env_id, stacked=('stacked' in state), rewards=reward_experiment, logdir=log_dir, render=render and (seed == 0), dump_frequency=50 if render and seed == 0 else 0) env = EpisodeRewardScoreWrapper( env, number_of_left_players_agent_controls=1, number_of_right_players_agent_controls=0) 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) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if is_atari: if len(env.observation_space.shape) == 3: env = wrap_deepmind(env, frame_stack=True) elif len(env.observation_space.shape ) == 3 and 'academy' not in env_id and '11' not in env_id: 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(): 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) if obs_keys is not None: env = gym.wrappers.FlattenDictWrapper(env, dict_keys=obs_keys) 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) obs_shape = env.observation_space.shape # if str(env.__class__.__name__).find('TimeLimit') >= 0: # env = TimeLimitMask(env) if log_dir is not None: if save_video: env = bench.Monitor(env, os.path.join(log_dir + '/eval/monitor', str(rank)), allow_early_resets=allow_early_resets) env = gym.wrappers.Monitor(env, os.path.join( log_dir + '/eval/video', str(rank)), force=True) else: env = bench.Monitor(env, os.path.join(log_dir + '/monitor', str(rank)), allow_early_resets=allow_early_resets) if is_atari: if len(env.observation_space.shape) == 3: env = wrap_deepmind(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, domain_name, task_name, log_dir=None): from dm_control import suite import dm_control2gym BaseTask.__init__(self) self.name = domain_name + '_' + task_name self.env = dm_control2gym.make(domain_name, task_name) self.action_dim = self.env.action_space.shape[0] self.state_dim = self.env.observation_space.shape[0] self.env = self.set_monitor(self.env, log_dir)
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 = make_atari(env_id) env.configure(config) envSeed = seed + rank if seed is not None else None # environment.render_axis = ax env.thisSeed = envSeed env.nenv = envNum if envNum > 1: env.phase = 'train' else: env.phase = 'test' if ax: env.render_axis = ax if test_case >= 0: env.test_case = test_case env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) # if log_dir is not None: env = bench.Monitor(env, None, allow_early_resets=allow_early_resets) print(env) if isinstance(env.observation_space, Box): if is_atari: if len(env.observation_space.shape) == 3: env = wrap_deepmind(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(): if env_id.startswith("Sawyer"): env = robosuite.make( env_id, has_renderer=False, has_offscreen_renderer=False, ignore_done=False, horizon=1000, #200, use_camera_obs=False, gripper_visualization=False, reward_shaping=True, control_freq=100 #10, # 100 ) env = GymGymWrapper(env) elif 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 = make_atari(env_id) env.seed(seed + rank) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = bench.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 = wrap_deepmind(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(): 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 = make_atari(env_id) env.seed(seed + rank) if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) # minigrid keep_classes = ['agent', 'goal', 'wall', 'empty'] if 'key' in env_id.lower(): keep_classes.extend(['door', 'key']) if env_id.startswith('MiniGrid'): env = mgwr.FullyObsWrapper(env) env = mgwr.ImgObsWrapper(env) env = mgwr.FullyObsOneHotWrapper(env, drop_color=1, keep_classes=keep_classes, flatten=False) if log_dir is not None: env = bench.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 = wrap_deepmind(env) elif len(env.observation_space.shape) == 3: if env_id.startswith('CarRacing'): env = WarpFrame(env, width=96, height=96, grayscale=True) env = ScaledFloatFrame(env) else: raise NotImplementedError # If the input has shape (W,H,3), wrap for PyTorch convolutions obs_shape = env.observation_space.shape if len(obs_shape) == 3: env = TransposeImage(env, op=[2, 0, 1]) return env
def _thunk(): if env_id.startswith("dm"): _, domain, task = env_id.split('.') env = dm_control2gym.make(domain_name=domain, task_name=task) elif env_id == "tetris_single": env = TetrisSingleEnv(obs_type=obs_type, mode=mode) 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) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) # if log_dir is not None: # env = bench.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 = wrap_deepmind(env) elif env_id.startswith("tetris"): # env = wrap_deepmind(env, episode_life=False, clip_rewards=False, frame_stack=False, scale=False) # env = NoopResetEnv(env, noop_max=30) env = MaxAndSkipEnv(env, skip=skip_frames) # pass if obs_type == "image": env = WarpFrame(env, 224, 224) 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(): if env_id.find("doorenv") > -1: env = gym.make(env_id, **env_kwargs) # env._max_episode_steps = 512 if env_kwargs['unity']: env.env.init(rank) elif env_id.find('Fetch') > -1: env = gym.make(env_id, reward_type="sparse") env = gym.wrappers.FlattenDictWrapper( env, dict_keys=['observation', 'desired_goal']) else: 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) env._max_episode_steps = 512 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) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find('TimeLimit') >= 0: env = TimeLimitMask(env) if log_dir is not None: env = bench.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 = wrap_deepmind(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(): 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) if 'gameoflife' in env_id.lower(): #print("ENV RANK: ", rank) power_puzzle = False #if args.power_puzzle: # power_puzzle = True if rank == 0: render = render_gui else:render = False env.configure(map_width=map_width, render=render) #env.setMapSize(map_width, print_map=print_map, render_gui=render, empty_start=not args.random_terrain, max_step=max_step, rank=rank, simple_reward=simple_reward, power_puzzle=power_puzzle) 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) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: env = MicropolisMonitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) #print(log_dir) # #print(type(env)) #print(dir(env)) #raise Exception if is_atari: env = wrap_deepmind(env) # 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) return env
def _thunk(): #print("Make envs", params) 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, **TspParams.current().ENVIRONMENT_KWARGS) is_atari = (hasattr(gym.envs, 'atari') and isinstance( env.unwrapped, gym.envs.atari.atari_env.AtariEnv)) if is_atari: env = make_atari(env_id) is_minigrid = "MiniGrid" in env_id if set_time_limit is not None: env = TimeLimit(env, set_time_limit) env.seed(seed + rank) obs_shape = env.observation_space.shape if str(env.__class__.__name__).find( 'TimeLimit') >= 0 or set_time_limit is not None: env = TimeLimitMask(env) if log_dir is not None: env = bench.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 = wrap_deepmind(env) elif is_minigrid: pass 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(): 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_env(args): if args.env_type == 'dmc': import dm_control2gym env = dm_control2gym.make( domain_name=args.domain_name, task_name=args.task_name, task_kwargs={'random': args.seed}, visualize_reward=True) elif args.env_type == 'mjc': from pointmass import point_mass env = gym.make(args.env_name) elif args.env_type == 'ant': import ant_env_mujoco env = gym.make(args.env_name) else: assert 'unknown env type: %s' % args.env_type return env
def __init__(self, domain_name, task_name, max_steps=sys.maxsize, log_dir=None): from dm_control import suite import dm_control2gym BasicTask.__init__(self, max_steps) self.name = domain_name + '_' + task_name self.env = dm_control2gym.make(domain_name, task_name) self.action_dim = self.env.action_space.shape[0] self.state_dim = self.env.observation_space.shape[0] if log_dir is not None: mkdir(log_dir) self.env = Monitor(self.env, '%s/%s' % (log_dir, uuid.uuid1()))
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) if 'micropolis' in env_id.lower(): print("ENV RANK: ", rank) if rank == 0: env.setMapSize(map_width, print_map=print_map, parallel_gui=parallel_py2gui, render_gui=render_gui, empty_start=True, noreward=noreward, max_step=max_step, rank=rank) else: env.setMapSize(map_width, rank=rank) 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) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: env = bench.Monitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=allow_early_resets) if is_atari: env = wrap_deepmind(env) # 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) return env
def _thunk(): print("CUSTOM GYM:", custom_gym) if custom_gym is not None and custom_gym != "": module = importlib.import_module(custom_gym, package=None) print("imported env '{}'".format((custom_gym))) 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 = make_atari(env_id) if not is_atari and scale_img: env = WarpFrame(env, color_img) if duckietown: env = DuckietownRewardWrapper(env) if dt_discrete: env = DuckietownDiscreteWrapper(env) env = Normalize(env) env.seed(seed + rank) obs_shape = env.observation_space.shape if add_timestep and len( obs_shape) == 1 and str(env).find('TimeLimit') > -1: env = AddTimestep(env) if log_dir is not None: env = bench.Monitor(env, os.path.join(log_dir, str(rank)), allow_early_resets=True) if is_atari: env = wrap_deepmind(env) # 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 = WrapPyTorch(env) return env