def compute(run_func, parameter_combinations, sample_size, save_path, skipbadruns=False): """ Calls the 'run_func' for several 'parameter_combiantions' and 'sample_size's and provides a unique ID for each run to store the data at the 'save_path' + ID Parameters ---------- run_func : function The function the executes the model for a given set of parameters. The first P paramters need to fit to the parameter_combinations. The last parameter of run_func has to be named filename If all went well run_func needs to return '1', otherwise another number parameter_combinations : list A list of tuples of each parameter combination to compute sample_size : int The size of samples of each parameter combiantion save_path : string The path to the folder where to store the computed results skipbadruns : bool (Default: False) If you don't want this function to check for bad runs that shall be recalculated, than set to "True". Possible reason: speed. """ # add "/" to save_path if it does not end already with a "/" save_path += "/" if not save_path.endswith("/") else "" def master(): if not os.path.exists(save_path): os.makedirs(save_path) elif skipbadruns: badruns = [] else: badruns = find_bad_runs(save_path) # preprocessing - Obtaining the data tocalc = [] for s in range(sample_size): for p in parameter_combinations: if not os.path.exists(save_path + _get_ID(p, s)) or\ _get_ID(p, s)[: -4] in badruns: tocalc.append((p, s)) lentocalc = len(tocalc) totallen = len(parameter_combinations) * sample_size print ("%i%% already computed" % (100 - (float(lentocalc) * 100 / totallen))) print str(lentocalc) + " of " + str(totallen) +\ " single computations left" n_nodes = mpi.size - 1 if n_nodes > 0: jobs_per_node = int(lentocalc / n_nodes) else: jobs_per_node = lentocalc n_nodes = 1 print "Splitting calculations to {} nodes.".format(n_nodes) for i in range(n_nodes): mpi.submit_call("slave", (tocalc[i*jobs_per_node: (i+1)*jobs_per_node], i), module=__name__) if lentocalc > (jobs_per_node * n_nodes): mpi.submit_call("slave", (tocalc[(i+1)*jobs_per_node:], i), module=__name__) global slave # slave into the globe scope to work with mpi def slave(slavecalcs, sid): lentocalc = len(slavecalcs) for i, (p, s) in enumerate(slavecalcs): _progress_report(i, lentocalc, "computation {} ... ".format(sid)) exit_status = run_func(*p, filename=save_path + _get_ID(p, s)) if exit_status != 1: # Checking for expected execution # TODO: proper logging print "!!! " + _get_ID(p, s) + " returned with: " \ + str(exit_status) mpi.run(verbose=0, master_func=master)
mpi.submit_call("loop", (par1, pars2), id=index) for i in xrange(nstep): print i a = mpi.get_result(id=i) if i == 0: a_alpha_max_thresh_geo = a else: a_alpha_max_thresh_geo = np.vstack([a_alpha_max_thresh_geo, a]) print a_alpha_max_thresh_geo np.save('/save/a_alpha_max_thresh_geo_c_max=0.2', a_alpha_max_thresh_geo) nstep = mpi.size # steps of parameter variation print nstep tmax = 600 # length of time series for diff. eq. solution n_tm = 100 # length of initial condition vector # boundaries b_a = 0.21 b_m = 0.31 b_l = 0.59 # model parameters main.c_max = 0.2 mpi.run()
def compute(run_func, parameter_combinations, sample_size, save_path, skipbadruns=False): """ Calls the 'run_func' for several 'parameter_combiantions' and 'sample_size's and provides a unique ID for each run to store the data at the 'save_path' + ID Parameters ---------- run_func : function The function the executes the model for a given set of parameters. The first P paramters need to fit to the parameter_combinations. The last parameter of run_func has to be named filename If all went well run_func needs to return '1', otherwise another number parameter_combinations : list A list of tuples of each parameter combination to compute sample_size : int The size of samples of each parameter combiantion save_path : string The path to the folder where to store the computed results skipbadruns : bool (Default: False) If you don't want this function to check for bad runs that shall be recalculated, than set to "True". Possible reason: speed. """ # add "/" to save_path if it does not end already with a "/" save_path += "/" if not save_path.endswith("/") else "" def master(): if not os.path.exists(save_path): os.makedirs(save_path) elif skipbadruns: badruns = [] else: badruns = find_bad_runs(save_path) # preprocessing - Obtaining the data tocalc = [] for s in range(sample_size): for p in parameter_combinations: if not os.path.exists(save_path + _get_ID(p, s)) or\ _get_ID(p, s)[: -4] in badruns: tocalc.append((p, s)) lentocalc = len(tocalc) totallen = len(parameter_combinations) * sample_size print("%i%% already computed" % (100 - (float(lentocalc) * 100 / totallen))) print str(lentocalc) + " of " + str(totallen) +\ " single computations left" n_nodes = mpi.size - 1 if n_nodes > 0: jobs_per_node = int(lentocalc / n_nodes) else: jobs_per_node = lentocalc n_nodes = 1 print "Splitting calculations to {} nodes.".format(n_nodes) for i in range(n_nodes): mpi.submit_call( "slave", (tocalc[i * jobs_per_node:(i + 1) * jobs_per_node], i), module=__name__) if lentocalc > (jobs_per_node * n_nodes): mpi.submit_call("slave", (tocalc[(i + 1) * jobs_per_node:], i), module=__name__) global slave # slave into the globe scope to work with mpi def slave(slavecalcs, sid): lentocalc = len(slavecalcs) for i, (p, s) in enumerate(slavecalcs): _progress_report(i, lentocalc, "computation {} ... ".format(sid)) exit_status = run_func(*p, filename=save_path + _get_ID(p, s)) if exit_status != 1: # Checking for expected execution # TODO: proper logging print "!!! " + _get_ID(p, s) + " returned with: " \ + str(exit_status) mpi.run(verbose=0, master_func=master)