Пример #1
0
MCiters = range(iter_range[0], iter_range[1]+1)
param_iterables = [MCiters]

# get other parameters to sweep over in the reconstruction
param_search = LMR_config.wrapper.param_search
if param_search is not None:
    # sort them by parameter name and combine into a list of iterables
    sort_params = list(param_search.keys())
    sort_params.sort(key=lambda x: x.split('.')[-1])
    param_values = [param_search[key] for key in sort_params]
    param_iterables = param_values + [MCiters]

for iter_and_params in itertools.product(*param_iterables):

    iter_num = iter_and_params[-1]
    cfg_dict = Utils.param_cfg_update('core.curr_iter', iter_num)

    if LMR_config.wrapper.multi_seed is not None:
        try:
            curr_seed = LMR_config.wrapper.multi_seed[iter_num]
            cfg_dict = Utils.param_cfg_update('core.seed', curr_seed,
                                              cfg_dict=cfg_dict)
            print('Setting current iteration seed: {}'.format(curr_seed))
        except IndexError:
            print('ERROR: multi_seed activated but current MC iteration out of'
                  ' range for list of seed values provided in config.')
            raise SystemExit(1)
        
    itr_str = 'r{:d}'.format(iter_num)
    # If parameter space search is being performed then set the current
    # search space values and create a special sub-directory
Пример #2
0
def load_config(yaml_file, verbose=False):
    begin_time = time()

    if not LMR_config.LEGACY_CONFIG:

        try:
            if verbose: print('Loading configuration: {}'.format(yaml_file))
            f = open(yaml_file, 'r')
            yml_dict = yaml.load(f)
            update_result = LMR_config.update_config_class_yaml(
                yml_dict, LMR_config)

            # Check that all yml params match value in LMR_config
            if update_result:
                raise SystemExit(
                    'Extra or mismatching values found in the configuration yaml'
                    ' file.  Please fix or remove them.\n  Residual parameters:\n '
                    '{}'.format(update_result))

        except IOError as e:
            raise SystemExit(
                ('Could not locate {}.  If use of legacy LMR_config usage is '
                 'desired then please change LEGACY_CONFIG to True'
                 'in LMR_wrapper.py.').format(yaml_file))

    # Define main experiment output directory
    iter_range = LMR_config.wrapper.iter_range
    expdir = os.path.join(LMR_config.core.datadir_output, LMR_config.core.nexp)
    arc_dir = os.path.join(LMR_config.core.archive_dir, LMR_config.core.nexp)

    # Check if it exists, if not, create it
    if not os.path.isdir(expdir):
        os.system('mkdir {}'.format(expdir))

    # Monte-Carlo approach: loop over iterations (range of iterations defined in
    # namelist)
    MCiters = range(iter_range[0], iter_range[1] + 1)
    param_iterables = [MCiters]

    # get other parameters to sweep over in the reconstruction
    param_search = LMR_config.wrapper.param_search
    if param_search is not None:
        # sort them by parameter name and combine into a list of iterables
        sort_params = list(param_search.keys())
        sort_params.sort(key=lambda x: x.split('.')[-1])
        param_values = [param_search[key] for key in sort_params]
        param_iterables = param_values + [MCiters]

    for iter_and_params in itertools.product(*param_iterables):

        iter_num = iter_and_params[-1]
        cfg_dict = Utils.param_cfg_update('core.curr_iter', iter_num)

        if LMR_config.wrapper.multi_seed is not None:
            curr_seed = LMR_config.wrapper.multi_seed[iter_num]
            cfg_dict = Utils.param_cfg_update('core.seed',
                                              curr_seed,
                                              cfg_dict=cfg_dict)
            #print ('Setting current iteration seed: {}'.format(curr_seed))

        itr_str = 'r{:d}'.format(iter_num)
        # If parameter space search is being performed then set the current
        # search space values and create a special sub-directory
        if param_search is not None:
            curr_param_values = iter_and_params[:-1]
            cfg_dict, psearch_dir = Utils.psearch_list_cfg_update(
                sort_params, curr_param_values, cfg_dict=cfg_dict)

            working_dir = os.path.join(expdir, psearch_dir, itr_str)
            mc_arc_dir = os.path.join(arc_dir, psearch_dir, itr_str)
        else:
            working_dir = os.path.join(expdir, itr_str)
            mc_arc_dir = os.path.join(arc_dir, itr_str)

        cfg_params = Utils.param_cfg_update('core.datadir_output',
                                            working_dir,
                                            cfg_dict=cfg_dict)

        cfg = LMR_config.Config(**cfg_params)

        proceed = validate_config(cfg)
        if not proceed:
            raise SystemExit()
        else:
            print('OK!')
            pass

    if verbose:
        elapsed_time = time() - begin_time
        print('-----------------------------------------------------')
        print('completed in ' + str(elapsed_time) + ' seconds')
        print('-----------------------------------------------------')

    return cfg
Пример #3
0
    param_iterables = param_values + [MCiters]


print('')
print('=====================================================')
print('Running LMR reconstruction wrapper')
print('=====================================================')

for iter_and_params in itertools.product(*param_iterables):

    iter_num = iter_and_params[-1]
    print('Monte Carlo iteration : ', iter_num)

    if LMR_config.wrapper.multi_seed is not None:
        curr_seed = wrapper_cfg.multi_seed[iter_num]
        cfg_dict = Util2.param_cfg_update('core.seed', curr_seed,
                                          cfg_dict=cfg_dict)
        print(('Setting current iteration seed: {}'.format(curr_seed)))

    itr_str = 'r{:d}'.format(iter_num)
    # If parameter space search is being performed then set the current
    # search space values and create a special sub-directory
    if param_search is not None:
        curr_param_values = iter_and_params[:-1]
        cfg_dict, psearch_dir = Util2.psearch_list_cfg_update(sort_params,
                                                              curr_param_values,
                                                              cfg_dict=cfg_dict)

        working_dir = os.path.join(expdir, psearch_dir, itr_str)
        mc_arc_dir = os.path.join(arc_dir, psearch_dir, itr_str)
    else:
        working_dir = os.path.join(expdir, itr_str)