Exemplo n.º 1
0
def create_doom(env_id,
                client_id,
                envWrap=True,
                record=False,
                outdir=None,
                noLifeReward=False,
                acRepeat=0,
                **_):
    from ppaquette_gym_doom import wrappers
    if 'labyrinth' in env_id.lower():
        if 'single' in env_id.lower():
            env_id = 'ppaquette/LabyrinthSingle-v0'
        elif 'fix' in env_id.lower():
            env_id = 'ppaquette/LabyrinthManyFixed-v0'
        else:
            env_id = 'ppaquette/LabyrinthMany-v0'
    elif 'very' in env_id.lower():
        env_id = 'ppaquette/DoomMyWayHomeFixed15-v0'
    elif 'sparse' in env_id.lower():
        env_id = 'ppaquette/DoomMyWayHomeFixed-v0'
    elif 'fix' in env_id.lower():
        if '1' in env_id or '2' in env_id:
            env_id = 'ppaquette/DoomMyWayHomeFixed' + str(env_id[-2:]) + '-v0'
        elif 'new' in env_id.lower():
            env_id = 'ppaquette/DoomMyWayHomeFixedNew-v0'
        else:
            env_id = 'ppaquette/DoomMyWayHomeFixed-v0'
    else:
        env_id = 'ppaquette/DoomMyWayHome-v0'

    # VizDoom workaround: Simultaneously launching multiple vizdoom processes
    # makes program stuck, so use the global lock in multi-threading/processing
    client_id = int(client_id)
    time.sleep(client_id * 10)
    env = gym.make(env_id)
    modewrapper = wrappers.SetPlayingMode('algo')
    obwrapper = wrappers.SetResolution('160x120')
    acwrapper = wrappers.ToDiscrete('minimal')
    env = modewrapper(obwrapper(acwrapper(env)))
    # env = env_wrapper.MakeEnvDynamic(env)  # to add stochasticity

    if record and outdir is not None:
        env = gym.wrappers.Monitor(env, outdir, force=True)

    if envWrap:
        fshape = (42, 42)
        frame_skip = acRepeat if acRepeat > 0 else 4
        env.seed(None)
        if noLifeReward:
            env = env_wrapper.NoNegativeRewardEnv(env)
        env = env_wrapper.BufferedObsEnv(env, skip=frame_skip, shape=fshape)
        env = env_wrapper.SkipEnv(env, skip=frame_skip)
    elif noLifeReward:
        env = env_wrapper.NoNegativeRewardEnv(env)

    env = Vectorize(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    return env
Exemplo n.º 2
0
    def __init__(self, level='ppaquette/DoomMyWayHome-v0'):
        time.sleep(np.random.randint(100))
        env = gym.make(level)

        modewrapper = wrappers.SetPlayingMode('algo')
        obwrapper = wrappers.SetResolution('160x120')
        acwrapper = wrappers.ToDiscrete('minimal')
        env = modewrapper(obwrapper(acwrapper(env)))

        frame_skip = options.get('environment/frame_skip', None)
        if frame_skip is not None:
            skip_wrapper = SkipWrapper(frame_skip)
            env = skip_wrapper(env)

        self._record = options.get('environment/record', False)
        if self._record:
            out_dir = options.get('environment/out_dir',
                                  '/tmp/' + level.split('/')[-1])
            if not os.path.exists(out_dir):
                os.makedirs(out_dir)
            env = gym.wrappers.Monitor(env, out_dir, force=True)

        self._no_op_max = options.get('environment/no_op_max', 0)
        self._reset_action = env.action_space.sample() \
            if options.get('environment/stochastic_reset', False) else 0

        env.seed(random.randrange(1000000))
        self._show_ui = options.get('show_ui', False)

        limit = options.get(
            'environment/limit',
            env.spec.tags.get('wrapper_config.TimeLimit.max_episode_steps'))
        if limit is not None:
            env._max_episode_steps = limit

        shape = options.get('environment/shape', (42, 42))
        self._shape = shape[:2]
        self._channels = 0 if len(shape) == 2 else shape[-1]

        self.action_size = self._get_action_size(env)
        if self.action_size != options.algorithm.output.action_size:
            print(
                'Algorithm expects different action size (%d) from gym (%d). \n'
                'Please set correct action size in you configuration yaml.' %
                (options.algorithm.output.action_size, self.action_size))
            sys.exit(-1)

        self.env = NoNegativeRewardEnv(env)
        self._obs_buffer = deque(maxlen=2)

        self.observation_space = Box(0.0, 255.0, shape)
        self.observation_space.high[...] = 1.0

        self._scale = (1.0 / 255.0)
        self.reset()
Exemplo n.º 3
0
def create_doom(record=False, outdir=None):
    from ppaquette_gym_doom import wrappers
    env = gym.make('ppaquette/DoomMyWayHome-v0')
    modewrapper = wrappers.SetPlayingMode('algo')
    obwrapper = wrappers.SetResolution('160x120')
    acwrapper = wrappers.ToDiscrete('minimal')
    env = modewrapper(obwrapper(acwrapper(env)))

    if record:
        env = gym.wrappers.Monitor(env, outdir, force=True)
    fshape = (42, 42)

    env.seed(None)
    #env = env_wrapper.NoNegativeRewardEnv(env)
    env = BufferedObsEnv(env, skip=1, shape=fshape)
    return env