def add_param(results_directory, param, value, param_test=None, value_test=None): for exp_dir in os.listdir(results_directory): print os.path.join(results_directory, exp_dir) if not os.path.isfile(os.path.join(results_directory, exp_dir, "0", "params.json")): print "No param file found : ", exp_dir continue with open(os.path.join(results_directory, exp_dir, "0", "params.json"), "r") as old_params_file: old_params = json.load(old_params_file) if param_test is not None and (get_param_value(old_params, param_test) != value_test): continue new_params = deepcopy(old_params) set_param_value(new_params, param, value) print " ->", os.path.join(results_directory, generate_exp_hash(new_params)) for exp_unit_dir in os.listdir(os.path.join(results_directory, exp_dir)): if os.path.isdir(os.path.join(results_directory, exp_dir, exp_unit_dir)): assert exp_unit_dir.isdigit() with open(os.path.join(results_directory, exp_dir, exp_unit_dir, "params.json"), "r") as old_params_file: assert old_params == json.load(old_params_file) with open(os.path.join(results_directory, exp_dir, exp_unit_dir, "params.json"), "w") as new_params_file: json.dump(new_params, new_params_file) os.rename(os.path.join(results_directory, exp_dir), os.path.join(results_directory, generate_exp_hash(new_params)))
def find_param(results_directory, param, value): for exp_dir in os.listdir(results_directory): with open(os.path.join(results_directory, exp_dir, "0", "params.json"), "r") as params_file: params = json.load(params_file) try: if get_param_value(params, param) == value: print os.path.join(results_directory, exp_dir) # To remove the directories: # shutil.rmtree(os.path.join(results_directory, exp_dir)) except: pass
def add_param(results_directory, param, value, param_test=None, value_test=None): for exp_dir in os.listdir(results_directory): print os.path.join(results_directory, exp_dir) if not os.path.isfile( os.path.join(results_directory, exp_dir, "0", "params.json")): print "No param file found : ", exp_dir continue with open(os.path.join(results_directory, exp_dir, "0", "params.json"), "r") as old_params_file: old_params = json.load(old_params_file) if param_test is not None and (get_param_value(old_params, param_test) != value_test): continue new_params = deepcopy(old_params) set_param_value(new_params, param, value) print " ->", os.path.join(results_directory, generate_exp_hash(new_params)) for exp_unit_dir in os.listdir(os.path.join(results_directory, exp_dir)): if os.path.isdir( os.path.join(results_directory, exp_dir, exp_unit_dir)): assert exp_unit_dir.isdigit() with open( os.path.join(results_directory, exp_dir, exp_unit_dir, "params.json"), "r") as old_params_file: assert old_params == json.load(old_params_file) with open( os.path.join(results_directory, exp_dir, exp_unit_dir, "params.json"), "w") as new_params_file: json.dump(new_params, new_params_file) os.rename( os.path.join(results_directory, exp_dir), os.path.join(results_directory, generate_exp_hash(new_params)))