Beispiel #1
0
def run_spec(spec, lab_mode):
    '''Run a spec in lab_mode'''
    os.environ['lab_mode'] = lab_mode
    if lab_mode in TRAIN_MODES:
        spec_util.save(spec)  # first save the new spec
        if lab_mode == 'dev':
            spec = spec_util.override_dev_spec(spec)
        if lab_mode == 'search':
            spec_util.tick(spec, 'experiment')
            Experiment(spec).run()
        else:
            spec_util.tick(spec, 'trial')
            Trial(spec).run()
    elif lab_mode in EVAL_MODES:
        spec = spec_util.override_enjoy_spec(spec)
        Session(spec).run()
    else:
        raise ValueError(f'Unrecognizable lab_mode not of {TRAIN_MODES} or {EVAL_MODES}')
Beispiel #2
0
def run_old_mode(spec_file, spec_name, lab_mode):
    '''Run using existing data with `enjoy, eval`. The eval mode is also what train mode's online eval runs in a subprocess via bash command'''
    # reconstruct spec and info_space from existing data
    lab_mode, prename = lab_mode.split('@')
    predir, _, _, _, _, _ = util.prepath_split(spec_file)
    prepath = f'{predir}/{prename}'
    spec, info_space = util.prepath_to_spec_info_space(prepath)
    # see InfoSpace def for more on these
    info_space.ckpt = 'eval'
    info_space.eval_model_prepath = prepath

    # no info_space.tick() as they are reconstructed
    if lab_mode == 'enjoy':
        spec = spec_util.override_enjoy_spec(spec)
        Session(spec, info_space).run()
    elif lab_mode == 'eval':
        spec = spec_util.override_eval_spec(spec)
        Session(spec, info_space).run()
        util.clear_periodic_ckpt(prepath)  # cleanup after itself
        analysis.analyze_eval_trial(spec, info_space, predir)
    else:
        raise ValueError('Unrecognizable lab_mode not of `enjoy, eval`')
Beispiel #3
0
def run_old_mode(spec_file, spec_name, lab_mode):
    '''Run using existing data with `enjoy, eval`. The eval mode is also what train mode's online eval runs in a subprocess via bash command'''
    # reconstruct spec and info_space from existing data
    lab_mode, prename = lab_mode.split('@')
    predir, _, _, _, _, _ = util.prepath_split(spec_file)
    prepath = f'{predir}/{prename}'
    spec, info_space = util.prepath_to_spec_info_space(prepath)
    # see InfoSpace def for more on these
    info_space.ckpt = 'eval'
    info_space.eval_model_prepath = prepath

    # no info_space.tick() as they are reconstructed
    if lab_mode == 'enjoy':
        spec = spec_util.override_enjoy_spec(spec)
        Session(spec, info_space).run()
    elif lab_mode == 'eval':
        # example eval command:
        # python run_lab.py data/dqn_cartpole_2018_12_19_224811/dqn_cartpole_t0_spec.json dqn_cartpole eval@dqn_cartpole_t0_s1_ckpt-epi10-totalt1000
        spec = spec_util.override_eval_spec(spec)
        Session(spec, info_space).run()
        util.clear_periodic_ckpt(prepath)  # cleanup after itself
        retro_analysis.analyze_eval_trial(spec, info_space, predir)
    else:
        raise ValueError(f'Unrecognizable lab_mode not of {EVAL_MODES}')