예제 #1
0
def make_env(config):
    config = config.copy()
    if '_' not in config['name']:
        config['name'] = f"_{config['name']}"
    suite, task = config['name'].split('_', 1)
    if suite == 'dmc':
        env = DeepMindControl(task, config.get('size', (64, 64)))
        env = wrappers.FrameSkip(env, config['frame_skip'])
        env = wrappers.NormalizeActions(env)
        config['max_episode_steps'] = 1000
        if config.get('frame_stack', 1) > 1:
            env = wrappers.FrameStack(env, config['frame_stack'], np_obs=False)
    elif suite == 'atari':
        env = Atari(task,
                    config['frame_skip'], (64, 64),
                    grayscale=False,
                    life_done=True,
                    sticky_actions=True)
        config['max_episode_steps'] = 108000
    elif 'procgen' in config['name'].lower():
        env = procgen.make_procgen_env(config)
        config['max_episode_steps'] = env.spec.max_episode_steps or 1000
    else:
        raise NotImplementedError(suite)
    env = wrappers.post_wrap(env, config)

    return env
예제 #2
0
def make_env(config):
    config = config.copy()
    _, name = config['name'].split('_', 1)
    name = name[0].capitalize() + name[1:]
    # version = 0 if config.get('sticky_actions', True) else 4
    version = 4
    name = f'{name}NoFrameskip-v{version}'
    config['max_episode_steps'] = max_episode_steps = 4500 * 4
    env = make_atari(name, max_episode_steps=max_episode_steps)
    env = wrap_deepmind(env,
                        reward_clip=config.get('reward_clip', True),
                        frame_stack=config.get('frame_stack', 4))
    env = post_wrap(env, config)
    return env
예제 #3
0
파일: cls.py 프로젝트: xlnwel/d2rl
def make_env(config):
    config = config.copy()
    env_name = config['name'].lower()
    if env_name.startswith('smac2'):
        from env import smac2
        env = smac2.make_smac_env(config)
        # smac2 resembles single agent environments, in which done and reward are team-based
        env = wrappers.EnvStats(env)
        return env
    elif env_name.startswith('smac'):
        from env import smac
        env = smac.make_smac_env(config)
        env = wrappers.MAEnvStats(env)
        return env
    elif env_name.startswith('atari'):
        from env import atari
        env = atari.make_atari_env(config)
    else:
        if env_name.startswith('procgen'):
            from env import procgen
            env = procgen.make_procgen_env(config)
        elif env_name.startswith('dmc'):
            from env import dmc
            env = dmc.make_dmc_env(config)
        else:
            env = gym.make(config['name']).env
            env = wrappers.DummyEnv(env)    # useful for hidding unexpected frame_skip
            config.setdefault('max_episode_steps', env.spec.max_episode_steps)
    if config.get('reward_scale') or config.get('reward_clip'):
        env = wrappers.RewardHack(env, **config)
    frame_stack = config.setdefault('frame_stack', 1)
    if frame_stack > 1:
        np_obs = config.setdefault('np_obs', False)
        env = wrappers.FrameStack(env, frame_stack, np_obs)
    frame_diff = config.setdefault('frame_diff', False)
    assert not (frame_diff and frame_stack > 1), f"Don't support using FrameStack and FrameDiff at the same time"
    if frame_diff:
        gray_scale_residual = config.setdefault('gray_scale_residual', False)
        distance = config.setdefault('distance', 1)
        env = wrappers.FrameDiff(env, gray_scale_residual, distance)
    env = wrappers.post_wrap(env, config)
    
    return env
예제 #4
0
파일: replay_test.py 프로젝트: xlnwel/d2rl
 def mkenv(config):
     env = DummyEnv(**config)
     env = wrappers.post_wrap(env, config)
     return env