Ejemplo n.º 1
0
def tick(spec, unit):
    '''
    Method to tick lab unit (experiment, trial, session) in meta spec to advance their indices
    Reset lower lab indices to -1 so that they tick to 0
    spec_util.tick(spec, 'session')
    session = Session(spec)
    '''
    meta_spec = spec['meta']
    if unit == 'experiment':
        meta_spec['experiment_ts'] = util.get_ts()
        meta_spec['experiment'] += 1
        meta_spec['trial'] = -1
        meta_spec['session'] = -1
    elif unit == 'trial':
        if meta_spec['experiment'] == -1:
            meta_spec['experiment'] += 1
        meta_spec['trial'] += 1
        meta_spec['session'] = -1
    elif unit == 'session':
        if meta_spec['experiment'] == -1:
            meta_spec['experiment'] += 1
        if meta_spec['trial'] == -1:
            meta_spec['trial'] += 1
        meta_spec['session'] += 1
    else:
        raise ValueError(f'Unrecognized lab unit to tick: {unit}')
    # set prepath since it is determined at this point
    meta_spec['prepath'] = prepath = util.get_prepath(spec, unit)
    for folder in ('graph', 'info', 'log', 'model'):
        folder_prepath = util.insert_folder(prepath, folder)
        folder_predir = os.path.dirname(f'{ROOT_DIR}/{folder_prepath}')
        os.makedirs(folder_predir, exist_ok=True)
        assert os.path.exists(folder_predir)
        meta_spec[f'{folder}_prepath'] = folder_prepath
    return spec
Ejemplo n.º 2
0
def get_eval_spec(spec_file, prename):
    '''Get spec for eval mode'''
    predir, _, _, _, _, _ = util.prepath_split(spec_file)
    prepath = f'{predir}/{prename}'
    spec = util.prepath_to_spec(prepath)
    spec['meta']['ckpt'] = 'eval'
    spec['meta']['eval_model_prepath'] = util.insert_folder(prepath, 'model')
    return spec
Ejemplo n.º 3
0
 def __init__(self, spec):
     super().__init__(spec)
     try_register_env(spec)  # register if it's a custom gym env
     seed = ps.get(spec, 'meta.random_seed')
     #         if self.is_venv:  # make vector environment
     #             self.u_env = make_gym_venv(self.name, self.num_envs, seed, self.frame_op, self.frame_op_len, self.reward_scale, self.normalize_state)
     #         else:
     #             self.u_env = make_gym_env(self.name, seed, self.frame_op, self.frame_op_len, self.reward_scale, self.normalize_state)
     #         self._set_attr_from_u_env(self.u_env)
     self.max_t = self.max_t or self.u_env.spec.max_episode_steps
     assert self.max_t is not None
     logger.info(util.self_desc(self))
     if util.to_record_video():
         video_prepath = util.insert_folder(
             util.get_prepath(spec, unit='session'), 'video')
         self.u_env = gym.wrappers.Monitor(self.u_env,
                                           video_prepath,
                                           force=True)
         logger.info(f'Recorded videos will be saved in {video_prepath}')
Ejemplo n.º 4
0
def test_insert_folder():
    assert util.insert_folder('data/dqn_pong_2018_12_02_082510/dqn_pong_t0_s0', 'model') == 'data/dqn_pong_2018_12_02_082510/model/dqn_pong_t0_s0'