示例#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
示例#2
0
 def __init__(self, last_coor=None):
     '''
     Initialize the coor, the global point in info space that will advance according to experiment progress.
     The coor starts with null first since the coor may not start at the origin.
     '''
     self.coor = last_coor or {k: None for k in COOR_AXES}
     self.covered_space = []
     # used to id experiment sharing the same spec name
     self.experiment_ts = util.get_ts()
示例#3
0
文件: monitor.py 项目: tttor/SLM-Lab
 def __init__(self, last_coor=None):
     '''
     Initialize the coor, the global point in info space that will advance according to experiment progress.
     The coor starts with null first since the coor may not start at the origin.
     TODO In general, when we parallelize to use multiple coor on a info space, keep a covered space and multiple coors to advance without conflicts.
     TODO logic to resume from given last_coor
     '''
     self.coor = last_coor or {k: None for k in COOR_AXES}
     self.covered_space = []
     # used to id experiment sharing the same spec name
     self.experiment_ts = util.get_ts()
示例#4
0
 def __init__(self, last_coor=None):
     '''
     Initialize the coor, the global point in info space that will advance according to experiment progress.
     The coor starts with null first since the coor may not start at the origin.
     TODO In general, when we parallelize to use multiple coor on a info space, keep a covered space and multiple coors to advance without conflicts.
     TODO logic to resume from given last_coor
     '''
     self.coor = last_coor or {k: None for k in COOR_AXES}
     self.covered_space = []
     # used to id experiment sharing the same spec name
     self.experiment_ts = util.get_ts()
示例#5
0
 def __init__(self, last_coor=None):
     '''
     Initialize the coor, the global point in info space that will advance according to experiment progress.
     The coor starts with null first since the coor may not start at the origin.
     '''
     self.coor = last_coor or {k: None for k in COOR_AXES}
     self.covered_space = []
     # used to id experiment sharing the same spec name
     self.experiment_ts = util.get_ts()
     # ckpt gets appened to extend prepath using util.get_prepath for saving models, e.g. ckpt_str = ckpt-epi10-totalt1000
     # ckpt = 'eval' is special for eval mode, so data files will save with `ckpt-eval`; no models will be saved, but to load models with normal ckpt it will find them using eval_model_prepath
     # e.g. 'epi24-totalt1000', 'eval', 'best'
     self.ckpt = None
     # e.g. 'data/dqn_cartpole_2018_12_19_085843/dqn_cartpole_t0_s0_ckpt-epi24-totalt1000'
     self.eval_model_prepath = None
示例#6
0
def extend_meta_spec(spec):
    '''Extend meta spec with information for lab functions'''
    extended_meta_spec = {
        # reset lab indices to -1 so that they tick to 0
        'experiment': -1,
        'trial': -1,
        'session': -1,
        'cuda_offset': int(os.environ.get('CUDA_OFFSET', 0)),
        'experiment_ts': util.get_ts(),
        'prepath': None,
        # ckpt extends prepath, e.g. ckpt_str = ckpt-epi10-totalt1000
        'ckpt': None,
        'git_sha': util.get_git_sha(),
        'random_seed': None,
        'eval_model_prepath': None,
    }
    spec['meta'].update(extended_meta_spec)
    return spec
示例#7
0
    def tick(self, axis):
        '''
        Advance the coor to the next point in axis (control unit class).
        If the axis value has been reset, update to 0, else increment. For all axes lower than the specified axis, reset to None.
        Note this will not skip coor in space, even though the covered space may not be rectangular.
        @example

        info_space.tick('session')
        session = Session(spec, info_space)
        '''
        assert axis in self.coor
        if axis == 'experiment':
            self.experiment_ts = util.get_ts()
        new_coor = self.coor.copy()
        if new_coor[axis] is None:
            new_coor[axis] = 0
        else:
            new_coor[axis] += 1
        new_coor = self.reset_lower_axes(new_coor, axis)
        self.covered_space.append(self.coor)
        self.coor = new_coor
        return self.coor
示例#8
0
    def tick(self, axis):
        '''
        Advance the coor to the next point in axis (control unit class).
        If the axis value has been reset, update to 0, else increment. For all axes lower than the specified axis, reset to None.
        Note this will not skip coor in space, even though the covered space may not be rectangular.
        @example

        info_space.tick('session')
        session = Session(spec, info_space)
        '''
        assert axis in self.coor
        if axis == 'experiment':
            self.experiment_ts = util.get_ts()
        new_coor = self.coor.copy()
        if new_coor[axis] is None:
            new_coor[axis] = 0
        else:
            new_coor[axis] += 1
        new_coor = self.reset_lower_axes(new_coor, axis)
        self.covered_space.append(self.coor)
        self.coor = new_coor
        return self.coor
示例#9
0
def test_get_ts():
    ts = util.get_ts()
    assert _.is_string(ts)
    assert util.RE_FILE_TS.match(ts)
示例#10
0
def test_get_ts():
    ts = util.get_ts()
    assert ps.is_string(ts)
    assert util.RE_FILE_TS.match(ts)