def set_fit_props(name, points, config, remove): from os import chdir, popen from os.path import basename, dirname import json from lib.utils import (fit_dir, config_dir, point_dir, dir_point, authorization_request) if remove: if points: print('Warning: points specification not compatible with --remove ' 'option.') return elif config != 'test': print('Warning: config specification not compatible with --remove ' 'option.') return chdir(fit_dir(name)) try: with open('sims.json', 'r') as file: sims = json.load(file) except FileNotFoundError: sims = [] # SIMS UPDATE if not remove: c_dir = config_dir(config) for Point in points: p_dir = c_dir + '/' + point_dir(Point) if p_dir not in sims: sims += [p_dir] with open('sims.json', 'w') as file: json.dump(sims, file, indent=4) # SIMS REMOTION else: new_sims = sims.copy() for sim in sims: Point = dir_point(basename(sim)) config = basename(dirname(sim)) what = f"to remove sim from fit '{name}'" extra = f"\033[38;5;80m config: '{config}'\033[0m" auth = authorization_request(Point=Point, what_to_do=what, extra_message=extra) if auth == 'quit': print('Nothing done for last sim.') return elif auth == 'yes': new_sims.remove(sim) with open('sims.json', 'w') as file: json.dump(new_sims, file, indent=4) print('Sim removed') else: print('Nothing removed.')
def up_launch(points_old, config, both, make, force): from os import getcwd, chdir from shutil import copyfile from lib.utils import (find_running, authorization_request, point_dir, launch_script_path, make_script_path, launch_script_name, make_script_name) proj_dir = getcwd() points_run, _ = find_running() points_run = [x[0] for x in points_run if x[1] == config] for p in points_old: if p not in points_run: if not config == 'test' and not force: what_to_do = "to update launch/make scripts" authorized = authorization_request(what_to_do, p) else: authorized = True if authorized != 'quit' and authorized: chdir('output/' + config + '/' + point_dir(p)) if both or make: make_script_n = make_script_name(p) copyfile(make_script_path(), make_script_n) if both or not make: launch_script_n = launch_script_name(p) copyfile(launch_script_path(), launch_script_n) print('Update complete for (λ, β) = ' + str(p)) chdir(proj_dir) elif authorized == 'quit': return
def up_launch(lambdas_old, config, both, make, force): from os import getcwd, chdir from shutil import copyfile from lib.utils import find_running, authorization_request proj_dir = getcwd() lambdas_run, _ = find_running() lambdas_run = [x[0] for x in lambdas_run if x[1] == config] for l in lambdas_old: if l not in lambdas_run: if not config == 'test' and not force: what_to_do = "to update launch/make scripts" authorized = authorization_request(what_to_do, l) else: authorized = True if authorized: chdir('output/' + config + '/Lambda' + str(l)) if both or make: make_script_name = 'make_' + str(l) + '.py' copyfile('../../../lib/make_script.py', make_script_name) if both or not make: launch_script_name = 'launch_' + str(l) + '.py' copyfile('../../../lib/launch_script.py', launch_script_name) chdir(proj_dir)
def remote(lambdas_old, lambdas_new, config, upload, download, force, rshow): from os import popen import json from lib.utils import find_running, authorization_request lambdas_run, _ = find_running() lambdas_run = [x[0] for x in lambdas_run if x[1] == config] lambdas_av = [l for l in lambdas_old if l not in lambdas_run] if download: action = 'download' lambdas_av += lambdas_new lambdas_not_av = [l for l in lambdas_old if l in lambdas_run] if upload: action = 'upload' lambdas_not_av += lambdas_new if len(lambdas_not_av) > 0: print("Following λ not available for " + action + ": ", lambdas_not_av) if len(lambdas_av) > 0: print() with open('config.json', 'r') as config_file: proj_configs = json.load(config_file) rclone_remote = proj_configs['rclone_remote'] remote_path = proj_configs['rclone_path'] if not rshow: # in upload è solo lambdas_old, mentre in download c'è anche new for l in lambdas_av: if not config == 'test' and not force and l not in lambdas_new: what_to_do = 'to ' + action + ' the sim folder' authorized = authorization_request(what_to_do, l) if authorized == 'quit': break else: authorized = True if authorized: local_dir = 'output/' + config + '/Lambda' + str(l) remote_dir = (rclone_remote + ':' + remote_path + '/CDT_2D/' + config + '/Lambda' + str(l)) if upload: print("(λ = " + str(l) + ") uploading...") source = local_dir dest = remote_dir elif download: print("(λ = " + str(l) + ") downloading...") source = remote_dir dest = local_dir popen('rclone copy ' + source + ' ' + dest).read() else: from lib.data import show dirs = popen('rclone lsd ' + rclone_remote + ':' + remote_path + '/CDT_2D/' + config).read().split('\n') lambdas = [float(x.split('Lambda')[1]) for x in dirs[:-1]] show(lambdas, config)
def clear_data(points, config='test', force=False): """Remove data for a given value of point Parameters ---------- Point : float the parameter of the simulation whose data you want to remove """ from os import scandir from shutil import rmtree from lib.utils import (find_all_availables, find_running, authorization_request, config_dir, point_str, point_dir) points_run, _ = find_running() points_run = [x[0] for x in points_run if x[1] == config] points_req_run = [x for x in points if x in points_run] points_clearable = [x for x in points if x not in points_run] if len(points_req_run) > 0: print("Simulations for following λ are running: ", points_req_run, '\n so they are not clearable') if len(points_req_run) > 0 and len(points_clearable) > 0: print() if len(points_clearable) == 0: print("No λ found in the requested range.") for Point in points_clearable: try: if not config == 'test' and not force: what_to_do = "to remove simulation folder" authorized = authorization_request(what_to_do, Point) else: authorized = 'yes' if authorized == 'yes': rmtree(config_dir(config) + "/" + point_dir(Point)) if force: print("(λ = ", Point[0], ", β = ", Point[1], ") ", sep='', end='') print("Simulation folder removed.") elif authorized == 'quit': print(f'Nothing done for last point {Point}.') return except FileNotFoundError: all_points = find_all_availables() raise ValueError("A folder with the given point doesn't exist"+ "\n\t\t\t all_points: " + str(all_points)) if all([not 'Beta' in str(x) for x in scandir(config_dir(config))]): return True else: return False
def reset_fit(names, delete): from os.path import isdir from os import chdir, mkdir from shutil import rmtree from re import fullmatch import json from lib.utils import (authorization_request, fit_dir, find_fits, project_folder) pattern_names = [] pure_names = [] all_names = list(find_fits().keys()) for name in names: if name[0] == '§': pattern_names += [c for c in all_names if fullmatch(name[1:], c)] else: pure_names += [name] names = list(set(pure_names + pattern_names)) print(f'Chosen fits are:\n {names}') for name in names: fit = fit_dir(name) if delete: action = 'delete' action_p = action + 'd' else: action = 'reset' action_p = action what_to_do = 'to ' + action + ' the fit \'' + name + '\'' authorized = authorization_request(what_to_do) if authorized == 'yes': rmtree(fit) if action == 'reset': mkdir(fit) elif action == 'delete': with open(project_folder() + '/output/fits.json', 'r') as file: fits = json.load(file) del fits[name] with open(project_folder() + '/output/fits.json', 'w') as file: json.dump(fits, file, indent=4) print(f'Fit {name} has been {action_p}.') elif authorized == 'quit': print('Nothing done on last fit.') return else: print('Nothing done.')
def therm(lambdas_old, config, is_therm, force): import json from lib.utils import find_running, authorization_request lambdas_run, _ = find_running() lambdas_run = [x[0] for x in lambdas_run if x[1] == config] lambdas_av = [l for l in lambdas_old if l not in lambdas_run] lambdas_not_av = [l for l in lambdas_old if l in lambdas_run] if len(lambdas_not_av) > 0: print("Simulations for following λ were already running: ", lambdas_not_av) if len(lambdas_av) > 0: print() for Lambda in lambdas_av: if not config == 'test' and not force: what_to_do = "to set thermalization flag `" + str(is_therm) + "`" authorized = authorization_request(what_to_do, Lambda) else: authorized = 'yes' if authorized == 'yes': filename = ('output/' + config + '/Lambda' + str(Lambda) + '/state.json') with open(filename, 'r') as state_file: state = json.load(state_file) state['is_thermalized'] = eval(is_therm) if state['is_thermalized']: state['therm_from'] = state['iter_done'] elif 'therm_from' in state.keys(): state.pop('therm_from') if state['is_thermalized']: neg = '' else: neg = 'un' print('Thermalization ' + neg + 'setted for λ = ' + str(Lambda)) if state['is_thermalized']: print('Iteration before therm: ' + str(state['iter_done'])) with open(filename, 'w') as state_file: json.dump(state, state_file, indent=4) elif authorized == 'quit': print('Nothing done for last Point.') return
def recovery_history(force=False): """ assume di essere chiamata nella cartella corretta @todo: aggiungere check, se fallisce risponde che è nel posto sbagliato e non fa nulla """ from os import scandir from re import split import json with open('state.json', 'r') as state_file: state = json.load(state_file) succesful = state['last_run_succesful'] run_num = state['run_done'] iter_done = state['iter_done'] checkpoints = [x.name for x in scandir("checkpoint") \ if split('_|\.|run', x.name)[1] == str(run_num)] checkpoints.sort() recovery = False if not succesful: if checkpoints[-1][-4:] == '.tmp': recovery = True elif force: from lib.utils import authorization_request print("ATTENTION: You are trying to recovery a succesful simulation!") recovery = authorization_request('to do it') if recovery: from numpy import loadtxt, savetxt vol_file = loadtxt('history/volumes.txt', dtype=int) pro_file = loadtxt('history/profiles.txt', dtype=int) vol_file = vol_file[vol_file[:, 0] < iter_done] pro_file = pro_file[pro_file[:, 0] < iter_done] savetxt('history/volumes.txt', vol_file, fmt='%d', header='iteration[0] - volume[1]\n') savetxt('history/profiles.txt', pro_file, fmt='%d', header='iteration[0] - profile[1:]\n')
def reset_conf(name): from os.path import isdir from os import chdir, mkdir from shutil import rmtree from lib.utils import authorization_request, config_dir config = config_dir(name) # if delete: # action = 'delete' # else: action = 'reset' what_to_do = 'to ' + action + ' the configuration \'' + name + '\'' authorized = authorization_request(what_to_do) if authorized == 'yes': rmtree(config) mkdir(config) print(f'Configuration {name} has been reset.') else: print('Nothing done.')
def clear_data(lambdas, config='test', force=False): """Remove data for a given value of lambda Parameters ---------- Lambda : float the parameter of the simulation whose data you want to remove """ from shutil import rmtree from lib.utils import find_all_availables, find_running, authorization_request lambdas_run, _ = find_running() lambdas_run = [x[0] for x in lambdas_run if x[1] == config] lambdas_req_run = [x for x in lambdas if x in lambdas_run] lambdas_clearable = [x for x in lambdas if x not in lambdas_run] if len(lambdas_req_run) > 0: print("Simulations for following λ are running: ", lambdas_req_run, '\n so they are not clearable') if len(lambdas_req_run) > 0 and len(lambdas_clearable) > 0: print() if len(lambdas_clearable) == 0: print("No λ found in the requested range.") for Lambda in lambdas_clearable: try: if not config == 'test' and not force: what_to_do = "to remove simulation folder" authorized = authorization_request(what_to_do, Lambda) else: authorized = True if authorized: rmtree("output/" + config + "/Lambda" + str(Lambda)) if force: print("(λ = " + str(Lambda) + ") ", end='') print("Simulation folder removed.") except FileNotFoundError: all_lambdas = find_all_availables() raise ValueError("A folder with the given lambda doesn't exist" + "\n\t\t\t all_lambdas: " + str(all_lambdas))
def recovery(lambdas_old, lambdas_new, config, force, very_forced): from os import getcwd, chdir from lib.tools import recovery_history from lib.utils import authorization_request if len(lambdas_new) > 0: print("Following λ not found: ", lambdas_news) if len(lambdas_old) > 0: print() proj_dir = getcwd() for Lambda in lambdas_old: if not config == 'test' and not force: what_to_do = "to recovery simulation data" authorized = authorization_request(what_to_do, Lambda) else: authorized = True if authorized: chdir('output/' + config + '/Lambda' + str(Lambda)) recovery_history(very_forced) chdir(proj_dir)
def reset_conf(name, delete=False): from os.path import isdir from os import chdir, mkdir from shutil import rmtree from lib.utils import authorization_request chdir('output') if isdir(name): if delete: action = 'delete' else: action = 'reset' what_to_do = 'to ' + action + ' the configuration \'' + name + '\'' authorized = authorization_request(what_to_do) if authorized: rmtree(name) if not delete: mkdir(name) else: print('The requested configuration does not exist.\n' + 'If you want to create it, please use the specific command.')
def recovery(points_old, points_new, config, force, very_forced): from os import getcwd, chdir from lib.tools import recovery_history from lib.utils import authorization_request, point_dir if len(points_new) > 0: print("Following (λ, β) not found: ", points_new) if len(points_old) > 0: print() proj_dir = getcwd() for Point in points_old: if not config == 'test' and not force: what_to_do = "to recovery simulation data" authorized = authorization_request(what_to_do, Point) else: authorized = True if authorized: chdir('output/' + config + point_dir(Point)) recovery_history(very_forced) chdir(proj_dir)
def refit_compute(args): from os import chdir from os.path import isfile from time import time from datetime import datetime import json import numpy as np import matplotlib.pyplot as plt from lib.utils import point_dir, authorization_request from lib.analysis.fit import fit_decay2 Point, points_configs, c_dir, i, force, plot, exclude_torelons = args if points_configs: c_dir = points_configs[Point] p_dir = c_dir + '/' + point_dir(Point) chdir(p_dir) if isfile(p_dir + '/max_volume_reached'): print(f'\033[38;5;41m(λ, β) = {Point}\033[0m skipped because ' '\033[38;5;80mmax_volume_reached\033[0m is present.') # print(f"\033[38;5;80m config: '{config}'\033[0m") return 'continue' try: with open('measures.json', 'r') as file: measures = json.load(file) except FileNotFoundError: print(f'\033[1mCRITICAL:\033[0m no measures.json file in sim' f'\033[38;5;41m(λ, β) = {Point}\033[0m') return 'continue' if not force: what = 'to refit correlation lengths' auth = authorization_request(what_to_do=what, Point=Point) else: auth = 'yes' # print("☙ \033[38;5;41m(λ, β) = " + str(Point) + "\033[0m") if auth == 'yes': # Compute torelons lengths try: t_mean, t_std = measures['torelon-decay'] torelons_decay_mean = np.array(t_mean) torelons_decay_std = np.array(t_std) print('\nTORELONS:') p_fit, par, cov, χ2 = fit_decay2(torelons_decay_mean, torelons_decay_std) if all([x is not None for x in [p_fit, par]]): x = np.linspace(0, len(torelons_decay_mean) - 1, 1001) y = p_fit plt.plot(x, y, 'tab:green', label='fit') plt.plot(torelons_decay_mean, 'tab:blue', label='bootstrap mean') plt.plot(torelons_decay_mean + torelons_decay_std, 'tab:red') plt.plot(torelons_decay_mean - torelons_decay_std, 'tab:red', label='bootstrap std') plt.title('TORELON:\n ') # f'Number of points: {len(indices_cut)}') plt.legend() plt.savefig('torelon.pdf') if plot and not force: plt.show() torelons_fit = {'par': None if par is None else par.tolist(), 'cov': None if cov is None else cov.tolist(), 'chi2': χ2[0], 'dof': χ2[1]} except KeyError: torelons_fit = None plt.clf() # Compute profiles lengths try: p_mean, p_std = measures['profiles_corr'] profiles_corr_mean = np.array(p_mean) profiles_corr_std = np.array(p_std) print('\nPROFILES:') p_fit, par, cov, χ2 = fit_decay2(profiles_corr_mean, profiles_corr_std) if all([x is not None for x in [p_fit, par]]): # if False and par is not None: x = np.linspace(0, len(profiles_corr_mean) - 1, 1001) y = p_fit plt.plot(x, y, 'tab:green', label='fit') plt.plot(profiles_corr_mean, 'tab:blue', label='bootstrap mean') plt.plot(profiles_corr_mean + profiles_corr_std, 'tab:red') plt.plot(profiles_corr_mean - profiles_corr_std, 'tab:red', label='bootstrap std') plt.title('PROFILE CORR.:\n ') # f'Number of points: {len(indices_cut)}') plt.legend() plt.savefig('profile.pdf') if plot and not force: plt.show() profiles_fit = {'par': None if par is None else par.tolist(), 'cov': None if cov is None else cov.tolist(), 'chi2': χ2[0], 'dof': χ2[1]} except KeyError: profiles_fit = None # Save results if torelons_fit and None not in torelons_fit.values(): measures['torelon-decay-fit2'] = torelons_fit if profiles_fit and None not in profiles_fit.values(): measures['profiles-corr-fit2'] = profiles_fit measures['time2'] = datetime.fromtimestamp(time() ).strftime('%d-%m-%Y %H:%M:%S') with open('measures.json', 'w') as file: json.dump(measures, file, indent=4) elif auth == 'quit' or auth == 'eof': print('Observables have not been recomputed.') return 'return' else: print('Observables have not been recomputed.')
def sim_obs(points, config, plot, fit, exclude_torelons, exclude_bootstrap, fit_name, force): from os import chdir from os.path import isfile, basename, dirname, realpath from time import time from datetime import datetime import json from pprint import pprint from lib.utils import (config_dir, point_dir, dir_point, fit_dir, authorization_request, eng_not) from lib.analysis.fit import (set_cut, set_block, eval_volume, eval_top_susc, eval_action, eval_action_density, compute_torelons, compute_profiles_corr) (Point, points_configs, c_dir, i, force, plot, fit, exclude_torelons, exclude_bootstrap) = args if points_configs: c_dir = points_configs[Point] p_dir = c_dir + '/' + point_dir(Point) chdir(p_dir) vol = None if isfile(p_dir + '/max_volume_reached'): print(f'\033[38;5;41m(λ, β) = {Point}\033[0m skipped because ' '\033[38;5;80mmax_volume_reached\033[0m is present.') # print(f"\033[38;5;80m config: '{config}'\033[0m") return 'continue' try: with open('state.json', 'r') as file: state = json.load(file) except FileNotFoundError: print(f'\033[1mCRITICAL:\033[0m no state.json file in sim' f'\033[38;5;41m(λ, β) = {Point}\033[0m') return 'continue' try: with open('measures.json', 'r') as file: measures = json.load(file) if 'cut' in measures.keys() and 'block' in measures.keys(): cb_exist = True else: cb_exist = False except FileNotFoundError: measures = {} cb_exist = False if not force: what = 'to select cut & block' extra = ('\033[92m(existing value present for both)\033[0m' if cb_exist else None) auth = authorization_request(what_to_do=what, Point=Point, extra_message=extra) else: print("\033[38;5;41m(λ, β) = " + str(Point) + "\033[0m ") auth = 'yes' if auth == 'quit' or auth == 'eof': print('Nothing done on the last sim.') return 'return' elif auth == 'yes': try: measures['cut'] = state['linear-history-cut'] cut = state['linear-history-cut'] with open('measures.json', 'w') as file: json.dump(measures, file, indent=4) print("\033[38;5;80m'linear-history-cut'\033[0m " "has been used as cut") except KeyError: cut = set_cut(p_dir, i, force) if cut: measures['cut'] = cut with open('measures.json', 'w') as file: json.dump(measures, file, indent=4) try : cut = measures['cut'] except KeyError: pass if cut: print(f'cut = {eng_not(cut)} ({cut})', end=' ') block = set_block(p_dir, i, force) if block: measures['block'] = block with open('measures.json', 'w') as file: json.dump(measures, file, indent=4) try: block = measures['block'] except KeyError: pass print(f'block = {eng_not(block)} ({block})', end=' ') if not cut or not block: print('\nNothing modified on last sim.') return 'return' vol = eval_volume(p_dir) if not force: what = 'to compute/recompute observables' auth = authorization_request(what_to_do=what) else: auth = 'yes' # print("☙ \033[38;5;41m(λ, β) = " + str(Point) + "\033[0m") if auth == 'yes': try: with open('measures.json', 'r') as file: measures = json.load(file) except FileNotFoundError: measures = {} if force: if not 'cut' in measures.keys(): print('cut not set') return 'continue' if not 'block' in measures.keys(): print('block not set') return 'continue' measures['volume'] = vol if vol else eval_volume(p_dir) # measures['action'] = eval_action(p_dir) # measures['action-density'] = eval_action_density(p_dir) # measures['top-susc'] = eval_top_susc(p_dir, force=force) # if not exclude_torelons and not exclude_bootstrap: # torelons_output = compute_torelons(p_dir, plot, fit, force=force) # if torelons_output: # measures['torelon-decay'] = torelons_output[:2] # if None not in torelons_output[2].values(): # measures['torelon-decay-fit'] = torelons_output[2] if not exclude_bootstrap: profiles_output = compute_profiles_corr(p_dir, plot, fit, force=force) measures['profiles_corr'] = profiles_output[:2] if None not in profiles_output[2].values(): measures['profiles_corr_fit'] = profiles_output[2] measures['time'] = datetime.fromtimestamp(time() ).strftime('%d-%m-%Y %H:%M:%S') with open('measures.json', 'w') as file: json.dump(measures, file, indent=4) elif auth == 'quit' or auth == 'eof': print('Observables have not been recomputed.') return 'return' else: print('Observables have not been recomputed.')
def launch(points_old, points_new, config, linear_history, end_time, end_steps, force, time_lengths, adj, max_volume, move22, move24, move_gauge, fake_run, debug, queue, arch, file): """Output analysis for CDT_2D simulation. attempts_str = str(attempts) Parameters ---------- points_old : type Description of parameter `points_old`. points_new : type Description of parameter `points_new`. config : type Description of parameter `config`. linear_history : type Description of parameter `linear_history`. time : type Description of parameter `time`. steps : type Description of parameter `steps`. force : type Description of parameter `force`. time_lengths : type Description of parameter `time_lengths`. fake_run : type Description of parameter `fake_run`. debug : type Description of parameter `debug`. Raises ------ Exception descrizione dell'eccezione lanciata """ from os import mkdir, chdir, getcwd, scandir from os.path import isfile, isdir from shutil import copyfile from re import split, sub from platform import node import json from lib.utils import (find_running, point_dir, point_str, moves_weights, authorization_request, end_parser, launch_script_name, make_script_name, config_dir, project_folder) from lib.platforms import launch_run # set moves' weights move22, move24, move_gauge = moves_weights(move22, move24, move_gauge) points_run, _ = find_running() points_run = [x[0] for x in points_run if x[1] == config] points_old_auth = [] # old ones which will get the authorization to rerun points_req_run = [] # those requested which are already running for Point in points_old: if Point not in points_run: if not config == 'test' and not force: what_to_do = "to rerun simulation" authorized = authorization_request(what_to_do, Point) else: authorized = 'yes' if authorized == 'yes': points_old_auth += [Point] elif authorized == 'quit': print('No simulation launched.') return else: points_req_run += [Point] points = points_old_auth + points_new if len(points_new) > 0: print("New simulations will be launched for following (λ, β): ", points_new) if len(points_old_auth) > 0: print("Old simulations will be rerunned for following (λ, β): ", points_old_auth) if len(points_req_run) > 0: print("Simulations for following (λ, β) were already running: ", points_req_run) if len(points) > 0: print() arg_strs = {} for Point in points: chdir(config_dir(config)) dir_name = point_dir(Point) launch_script_n = launch_script_name(Point) make_script_n = make_script_name(Point) if Point in points_old: if not isdir(dir_name + "/history/adjacencies"): mkdir(dir_name + "/history/adjacencies") with open(dir_name + "/state.json", "r+") as state_file: state = json.load(state_file) if state['is_thermalized']: print('((λ, β) = ' + str(Point) + ') Ha già finito!') # @todo da migliorare continue if state['last_run_succesful']: run_num = state['run_done'] + 1 else: print('((λ, β) = ' + str(Point) + ') Problem in the last run') continue if state['is_thermalized'] and linear_history == '0': linear_history = '1M' # I'm putting the default because this case is present only for # backward compatibility, and before the timelength was stuck to 80 try: time_length = state['timelength'] except KeyError: time_length = time_lengths[Point] checkpoints = [ x.name for x in scandir(dir_name + "/checkpoint") if (split('_|\.|run', x.name)[1] == str(run_num - 1) and x.name[-4:] != '.tmp') ] # nell'ordinamento devo sostituire i '.' con le '~', o in generale # un carattere che venga dopo '_', altrimenti 'run1.1_...' viene # prima di 'run1_...' checkpoints.sort(key=lambda s: s.replace('.', '~')) last_check = checkpoints[-1] else: mkdir(dir_name) mkdir(dir_name + "/checkpoint") mkdir(dir_name + "/history") mkdir(dir_name + "/history/adjacencies") mkdir(dir_name + "/bin") make_template = project_folder() + '/lib/scripts/make_script.py' launch_template = project_folder( ) + '/lib/scripts/launch_script.py' copyfile(make_template, dir_name + '/' + make_script_n) copyfile(launch_template, dir_name + '/' + launch_script_n) if fake_run: print('Created simulation directory for: (Lambda= ' + str(Point[0]) + ', Beta= ' + str(Point[1]) + ')') run_num = 1 last_check = None time_length = time_lengths[Point] # devo farlo qui perché prima non sono sicuro che dir_name esista # ('mkdir(dir_name)') chdir(dir_name) if isfile('max_volume_reached'): print(f'Point {Point} won\'t be relaunched because it reached ' 'maximum volume available in the previous run.') continue if int(run_num) > 1: from lib.tools import recovery_history recovery_history() if linear_history != '0' and not state['linear-history']: state['linear-history-cut'] = state['iter_done'] if state['linear-history']: if linear_history == '0': print('\033[38;5;69mWarning:\033[0m') print(f"Point {Point} has been already run with " f"linear_history {state['linear-history']}, so this " f"value will be used.") elif linear_history != state['linear-history']: print('\033[38;5;69mWarning:\033[0m') print(f"Point {Point} has been already run with " f"linear_history {state['linear-history']}, so this " f"will be used instead of: {linear_history}.") linear_history = state['linear-history'] # ensure state_file existence or update it if int(run_num) == 1: state = { 'Lambda': Point[0], 'Beta': Point[1], 'run_done': 0, 'is_thermalized': False, 'last_checkpoint': None, 'iter_done': 0, 'timelength': time_length } with open('state.json', 'w') as state_file: json.dump(state, state_file, indent=4) # END CONDITION MANIPULATION # ricongiungo le due variabili perché è ancora facile # distinguerle dall'ultimo carattere if end_steps != '0': end_condition = end_steps else: end_condition = end_time # needed for thermalization loop end_partial, end_condition, end_type = end_parser(end_condition) if linear_history != '0': # i.e. `if linear_history:` if end_type == 'time': end_partial = str(end_condition) + 's' else: end_partial = end_condition # set debug_flag for c++ (in c++ style) debug_flag = str(debug).lower() # set adj_flag for c++ (in c++ style) adj_flag = str(adj).lower() # max_volume max_volume = int(max_volume[0] if type(max_volume) == list else max_volume) # is necessary to recompile each run because on the grid the launch node # could be different from run_node exe_name = "CDT_2D-" + point_str(Point) #+ "_run" + str(run_num) arguments = [ project_folder(), run_num, Point[0], Point[1], time_length, end_condition, debug_flag, last_check, linear_history, adj_flag, move22, move24, max_volume, end_partial, end_type, exe_name ] arg_str = '' for x in arguments: arg_str += ' ' + str(x) arg_strs[Point] = arg_str if fake_run: print() print(*(["bin/" + exe_name] + arguments[:8])) if not fake_run: from lib.platforms import launch_run points = list(arg_strs.keys()) launch_run(points, arg_strs, config, queue, arch, file)
def launch(lambdas_old, lambdas_new, config, linear_history, time, steps, force, time_length): """Output analysis for CDT_2D simulation. attempts_str = str(attempts) Descrizione... Parameters ---------- p1 : tipo descrizione del primo parametro p1 p2 : tipo descrizione del secondo parametro p2 p3 : tipo, optional descrizione del terzo parametro opzionale p3 Returns ------- tipo descrizione del tipo di ritorno Raises ------ Exception descrizione dell'eccezione lanciata """ from os import mkdir, chdir, system, getcwd, scandir from shutil import copyfile from re import split from platform import node import json from subprocess import Popen from lib.utils import find_running from lib.utils import authorization_request lambdas_run, sim_info = find_running() lambdas_run = [x[0] for x in lambdas_run if x[1] == config] lambdas_old_auth = [] lambdas_req_run = [] for Lambda in lambdas_old: if Lambda not in lambdas_run: if not config == 'test' and not force: what_to_do = "to rerun simulation" authorized = authorization_request(what_to_do, Lambda) else: authorized = True if authorized: lambdas_old_auth += [Lambda] else: lambdas_req_run += [Lambda] lambdas = lambdas_old_auth + lambdas_new if len(lambdas_new) > 0: print("New simulations will be launched for following λ: ", lambdas_new) if len(lambdas_old_auth) > 0: print("Old simulations will be rerunned for following λ: ", lambdas_old_auth) if len(lambdas_req_run) > 0: print("Simulations for following λ were already running: ", lambdas_req_run) if len(lambdas) > 0: print() project_folder = getcwd() for Lambda in lambdas: chdir(project_folder + '/output/' + config) dir_name = "Lambda" + str(Lambda) launch_script_name = 'launch_' + str(Lambda) + '.py' make_script_name = 'make_' + str(Lambda) + '.py' if Lambda in lambdas_old: with open(dir_name + "/state.json", "r+") as state_file: state = json.load(state_file) if state['is_thermalized']: print('(λ = ' + str(Lambda) + ') Ha già finito idiota!') # @todo da migliorare continue if state['last_run_succesful']: run_num = state['run_done'] + 1 else: print('(λ = ' + str(Lambda) + ') Problem in the last run') continue checkpoints = [x.name for x in scandir(dir_name + "/checkpoint") \ if (split('_|\.|run', x.name)[1] == str(run_num - 1) and x.name[-4:] != '.tmp')] # nell'ordinamento devo sostituire i '.' con le '~', o in generale # un carattere che venga dopo '_', altrimenti 'run1.1_...' viene # prima di 'run1_...' checkpoints.sort(key=lambda s: s.replace('.', '~')) last_check = checkpoints[-1] else: mkdir(dir_name) mkdir(dir_name + "/checkpoint") mkdir(dir_name + "/history") mkdir(dir_name + "/bin") copyfile('../../lib/launch_script.py', dir_name + '/' + launch_script_name) copyfile('../../lib/make_script.py', dir_name + '/' + make_script_name) run_num = 1 last_check = None # devo farlo qui perché prima non sono sicuro che dir_name esista # ('mkdir(dir_name)') chdir(dir_name) if run_num > 1: from lib.tools import recovery_history recovery_history() # ricongiungo le due variabili perché è ancora facile # distinguerle dall'ultimo carattere if steps != '0': end_condition = steps else: end_condition = time if type(time_length) == list: time_length = time_length[0] debug_flag = 'false' arguments = [ run_num, Lambda, time_length, end_condition, debug_flag, last_check, linear_history ] arg_str = '' for x in arguments: arg_str += ' ' + str(x) if (node() == 'Paperopoli'): make_script = Popen( ["python3", make_script_name, str(run_num), str(Lambda)]) make_script.wait() system('nohup python3 $PWD/' + launch_script_name + arg_str + ' &') elif (node() == 'fis-delia.unipi.it'): make_script = Popen( ["python36", make_script_name, str(run_num), str(Lambda)]) make_script.wait() system('nohup python36 $PWD/' + launch_script_name + arg_str + ' &') elif (node() == 'gridui3.pi.infn.it'): print('support for grid still missing') # make_script = Popen(["python3", make_script_name, str(run_num), # str(Lambda)]) # make_script.wait() # system('bsub -q local -o stdout.txt -e stderr.txt -J ' + \ # dir_name + ' $PWD/' + launch_script_name + arg_str) elif (node()[0:4] == 'r000'): print('support for marconi still missing') else: raise NameError('Node not recognized (known nodes in data.py)')