def make_env_func(env_config): print('Creating env!!!') cfg = default_cfg(env=spec.name) cfg.pixel_format = 'HWC' # tensorflow models expect HWC by default if 'skip_frames' in env_config: cfg.env_frameskip = env_config['skip_frames'] if 'res_w' in env_config: cfg.res_w = env_config['res_w'] if 'res_h' in env_config: cfg.res_h = env_config['res_h'] if 'wide_aspect_ratio' in env_config: cfg.wide_aspect_ratio = env_config['wide_aspect_ratio'] env = make_doom_env(spec.name, env_config=env_config, cfg=cfg, **kwargs) # we lock the global mutex here, otherwise Doom instances may crash on first reset when too many of them are reset simultaneously lock = FileLock(DOOM_LOCK_PATH) attempt = 0 while True: attempt += 1 try: with lock.acquire(timeout=10): print('Env created, resetting...') env.reset() print('Env reset completed! Config:', env_config) break except Timeout: print('Another instance of this application currently holds the lock, attempt:', attempt) return env
def test_doom_two_color(self): from envs.doom.doom_utils import make_doom_env test_env_performance( lambda env_config: make_doom_env('doom_two_colors_easy', cfg=default_doom_cfg()), 'doom', verbose=False, )
def test_doom_two_color(self): test_env_performance( lambda env_config: make_doom_env('doom_two_colors_easy', cfg=default_doom_cfg()), 'doom', verbose=False, )
def make_standard_dm(env_config): from envs.doom.doom_utils import make_doom_env from envs.tests.test_envs import default_doom_cfg cfg = default_doom_cfg() cfg.env_frameskip = 2 env = make_doom_env('doom_deathmatch_full', cfg=cfg, env_config=env_config) env.skip_frames = cfg.env_frameskip return env
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--env', type=str, default=None, required=True) parser.add_argument('--demo_path', type=str, default=None, required=True) args = parser.parse_args() spec = doom_env_by_name(args.env) cfg = default_cfg(env=args.env) if spec.num_agents <= 1: env = make_doom_env(args.env, cfg=cfg, custom_resolution='1280x720') else: env = make_doom_env_impl( spec, cfg=cfg, custom_resolution='1280x720', player_id=0, num_agents=spec.num_agents, max_num_players=spec.num_agents, num_bots=spec.num_bots, ) mode = 'replay' env.unwrapped.mode = mode env.unwrapped.initialize() game = env.unwrapped.game game.replay_episode(args.demo_path) frames_dir = args.demo_path + '_frames' if os.path.exists(frames_dir): shutil.rmtree(frames_dir) os.makedirs(frames_dir) frame_id = 0 while not game.is_episode_finished(): # Use advance_action instead of make_action. game.advance_action() img = env.render(mode='rgb_array') frame_name = f'{frame_id:05d}.png' img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) if img is not None: cv2.imwrite(join(frames_dir, frame_name), img) frame_id += 1 r = game.get_last_reward() log.debug('Reward %.3f at frame %d', r, frame_id) game.close()
def create_env(env, **kwargs): """Expected names are: doom_battle, atari_montezuma, etc.""" if env.startswith('doom_'): from envs.doom.doom_utils import make_doom_env env = make_doom_env(env, **kwargs) elif env.startswith('MiniGrid'): from envs.minigrid.minigrid_utils import make_minigrid_env env = make_minigrid_env(env, **kwargs) elif env.startswith('atari_'): from envs.atari.atari_utils import make_atari_env return make_atari_env(env, **kwargs) elif env.startswith('dmlab_'): from envs.dmlab.dmlab_utils import make_dmlab_env return make_dmlab_env(env, **kwargs) else: raise Exception('Unsupported env {0}'.format(env)) return env
def make_env_bots_hybrid_actions(env_config, **kwargs): from envs.doom.doom_utils import make_doom_env return make_doom_env('doom_deathmatch_bots', cfg=default_doom_cfg(), env_config=env_config, **kwargs)
def make_env_singleplayer(env_config): from envs.doom.doom_utils import make_doom_env return make_doom_env('doom_benchmark', cfg=default_doom_cfg(), env_config=env_config)
def make_standard_dm(env_config): cfg = default_doom_cfg() cfg.env_frameskip = 2 env = make_doom_env('doom_freedm', cfg=cfg, env_config=env_config) env.skip_frames = cfg.env_frameskip return env
def make_env_bots_hybrid_actions(env_config, **kwargs): return make_doom_env('doom_deathmatch_bots', cfg=default_doom_cfg(), env_config=env_config, **kwargs)
def make_env_singleplayer(env_config): return make_doom_env('doom_benchmark', cfg=default_doom_cfg(), env_config=env_config)