diff --git a/docs/pyerrors/input/sfcf.html b/docs/pyerrors/input/sfcf.html index e616fffa..78ecdf8f 100644 --- a/docs/pyerrors/input/sfcf.html +++ b/docs/pyerrors/input/sfcf.html @@ -89,350 +89,358 @@ 11 12 Parameters 13 ---------- - 14 quarks: str - 15 Label of the quarks used in the sfcf input file. e.g. "quark quark" - 16 for version 0.0 this does NOT need to be given with the typical " - " - 17 that is present in the output file, - 18 this is done automatically for this version - 19 noffset: int - 20 Offset of the source (only relevant when wavefunctions are used) - 21 wf: int - 22 ID of wave function - 23 wf2: int - 24 ID of the second wavefunction - 25 (only relevant for boundary-to-boundary correlation functions) - 26 im: bool - 27 if True, read imaginary instead of real part - 28 of the correlation function. - 29 corr_type : str - 30 change between bi (boundary - inner) (default) bib (boundary - inner - boundary) and bb (boundary - boundary) - 31 correlator types - 32 names : list - 33 Alternative labeling for replicas/ensembles. - 34 Has to have the appropriate length - 35 ens_name : str - 36 replaces the name of the ensemble - 37 version: str - 38 version of SFCF, with which the measurement was done. - 39 if the compact output option (-c) was specified, - 40 append a "c" to the version (e.g. "1.0c") - 41 if the append output option (-a) was specified, - 42 append an "a" to the version - 43 cfg_separator : str - 44 String that separates the ensemble identifier from the configuration number (default 'n'). - 45 replica: list - 46 list of replica to be read, default is all - 47 files: list - 48 list of files to be read per replica, default is all. - 49 for non-compact output format, hand the folders to be read here. - 50 check_configs: - 51 list of list of supposed configs, eg. [range(1,1000)] - 52 for one replicum with 1000 configs - 53 """ - 54 if kwargs.get('im'): - 55 im = 1 - 56 part = 'imaginary' - 57 else: - 58 im = 0 - 59 part = 'real' - 60 if "replica" in kwargs: - 61 reps = kwargs.get("replica") - 62 if corr_type == 'bb': - 63 b2b = True - 64 single = True - 65 elif corr_type == 'bib': - 66 b2b = True - 67 single = False - 68 else: - 69 b2b = False - 70 single = False - 71 compact = True - 72 appended = False - 73 known_versions = ["0.0", "1.0", "2.0", "1.0c", "2.0c", "1.0a", "2.0a"] - 74 - 75 if version not in known_versions: - 76 raise Exception("This version is not known!") - 77 if (version[-1] == "c"): - 78 appended = False - 79 compact = True - 80 version = version[:-1] - 81 elif (version[-1] == "a"): - 82 appended = True - 83 compact = False - 84 version = version[:-1] - 85 else: - 86 compact = False - 87 appended = False - 88 read = 0 - 89 T = 0 - 90 start = 0 - 91 ls = [] - 92 if "replica" in kwargs: - 93 ls = reps - 94 else: - 95 for (dirpath, dirnames, filenames) in os.walk(path): - 96 if not appended: - 97 ls.extend(dirnames) - 98 else: - 99 ls.extend(filenames) -100 break -101 if not ls: -102 raise Exception('Error, directory not found') -103 # Exclude folders with different names -104 for exc in ls: -105 if not fnmatch.fnmatch(exc, prefix + '*'): -106 ls = list(set(ls) - set([exc])) -107 -108 if not appended: -109 if len(ls) > 1: -110 # New version, to cope with ids, etc. -111 ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) -112 replica = len(ls) -113 else: -114 replica = len([file.split(".")[-1] for file in ls]) // len(set([file.split(".")[-1] for file in ls])) -115 print('Read', part, 'part of', name, 'from', prefix[:-1], -116 ',', replica, 'replica') -117 if 'names' in kwargs: -118 new_names = kwargs.get('names') -119 if len(new_names) != len(set(new_names)): -120 raise Exception("names are not unique!") -121 if len(new_names) != replica: -122 raise Exception('Names does not have the required length', replica) -123 else: -124 new_names = [] -125 if not appended: -126 for entry in ls: -127 try: -128 idx = entry.index('r') -129 except Exception: -130 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -131 -132 if 'ens_name' in kwargs: -133 new_names.append(kwargs.get('ens_name') + '|' + entry[idx:]) -134 else: -135 new_names.append(entry[:idx] + '|' + entry[idx:]) -136 else: -137 -138 for exc in ls: -139 if not fnmatch.fnmatch(exc, prefix + '*.' + name): -140 ls = list(set(ls) - set([exc])) -141 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -142 for entry in ls: -143 myentry = entry[:-len(name) - 1] -144 try: -145 idx = myentry.index('r') -146 except Exception: -147 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -148 -149 if 'ens_name' in kwargs: -150 new_names.append(kwargs.get('ens_name') + '|' + myentry[idx:]) -151 else: -152 new_names.append(myentry[:idx] + '|' + myentry[idx:]) -153 idl = [] -154 if not appended: -155 for i, item in enumerate(ls): -156 sub_ls = [] -157 if "files" in kwargs: -158 sub_ls = kwargs.get("files") -159 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -160 else: -161 for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): -162 if compact: -163 sub_ls.extend(filenames) -164 else: -165 sub_ls.extend(dirnames) -166 break -167 if compact: -168 for exc in sub_ls: -169 if not fnmatch.fnmatch(exc, prefix + '*'): -170 sub_ls = list(set(sub_ls) - set([exc])) -171 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -172 else: -173 for exc in sub_ls: -174 if not fnmatch.fnmatch(exc, 'cfg*'): -175 sub_ls = list(set(sub_ls) - set([exc])) -176 sub_ls.sort(key=lambda x: int(x[3:])) -177 rep_idl = [] -178 no_cfg = len(sub_ls) -179 for cfg in sub_ls: -180 try: -181 if compact: -182 rep_idl.append(int(cfg.split(cfg_separator)[-1])) -183 else: -184 rep_idl.append(int(cfg[3:])) -185 except Exception: -186 raise Exception("Couldn't parse idl from directroy, problem with file " + cfg) -187 rep_idl.sort() -188 # maybe there is a better way to print the idls -189 print(item, ':', no_cfg, ' configurations') -190 idl.append(rep_idl) -191 # here we have found all the files we need to look into. -192 if i == 0: -193 # here, we want to find the place within the file, -194 # where the correlator we need is stored. -195 # to do so, the pattern needed is put together -196 # from the input values -197 if version == "0.0": -198 pattern = "# " + name + " : offset " + str(noffset) + ", wf " + str(wf) -199 # if b2b, a second wf is needed -200 if b2b: -201 pattern += ", wf_2 " + str(wf2) -202 qs = quarks.split(" ") -203 pattern += " : " + qs[0] + " - " + qs[1] -204 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") -205 for k, line in enumerate(file): -206 if read == 1 and not line.strip() and k > start + 1: -207 break -208 if read == 1 and k >= start: -209 T += 1 -210 if pattern in line: -211 read = 1 -212 start = k + 1 -213 print(str(T) + " entries found.") -214 file.close() -215 else: -216 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) -217 if b2b: -218 pattern += '\nwf_2 ' + str(wf2) -219 # and the file is parsed through to find the pattern -220 if compact: -221 file = open(path + '/' + item + '/' + sub_ls[0], "r") -222 else: -223 # for non-compactified versions of the files -224 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") -225 -226 content = file.read() -227 match = re.search(pattern, content) -228 if match: -229 start_read = content.count('\n', 0, match.start()) + 5 + b2b -230 end_match = re.search(r'\n\s*\n', content[match.start():]) -231 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b -232 assert T > 0 -233 print(T, 'entries, starting to read in line', start_read) -234 file.close() -235 else: -236 file.close() -237 raise Exception('Correlator with pattern\n' + pattern + '\nnot found.') -238 -239 # we found where the correlator -240 # that is to be read is in the files -241 # after preparing the datastructure -242 # the correlators get parsed into... -243 deltas = [] -244 for j in range(T): -245 deltas.append([]) + 14 path : str + 15 Path to the sfcf files. + 16 prefix : str + 17 Prefix of the sfcf files. + 18 name : str + 19 Name of the correlation function to read. + 20 quarks : str + 21 Label of the quarks used in the sfcf input file. e.g. "quark quark" + 22 for version 0.0 this does NOT need to be given with the typical " - " + 23 that is present in the output file, + 24 this is done automatically for this version + 25 corr_type : str + 26 Type of correlation function to read. Can be + 27 - 'bi' for boundary-inner + 28 - 'bb' for boundary-boundary + 29 - 'bib' for boundary-inner-boundary + 30 noffset : int + 31 Offset of the source (only relevant when wavefunctions are used) + 32 wf : int + 33 ID of wave function + 34 wf2 : int + 35 ID of the second wavefunction + 36 (only relevant for boundary-to-boundary correlation functions) + 37 im : bool + 38 if True, read imaginary instead of real part + 39 of the correlation function. + 40 names : list + 41 Alternative labeling for replicas/ensembles. + 42 Has to have the appropriate length + 43 ens_name : str + 44 replaces the name of the ensemble + 45 version: str + 46 version of SFCF, with which the measurement was done. + 47 if the compact output option (-c) was specified, + 48 append a "c" to the version (e.g. "1.0c") + 49 if the append output option (-a) was specified, + 50 append an "a" to the version + 51 cfg_separator : str + 52 String that separates the ensemble identifier from the configuration number (default 'n'). + 53 replica: list + 54 list of replica to be read, default is all + 55 files: list + 56 list of files to be read per replica, default is all. + 57 for non-compact output format, hand the folders to be read here. + 58 check_configs: + 59 list of list of supposed configs, eg. [range(1,1000)] + 60 for one replicum with 1000 configs + 61 """ + 62 if kwargs.get('im'): + 63 im = 1 + 64 part = 'imaginary' + 65 else: + 66 im = 0 + 67 part = 'real' + 68 if "replica" in kwargs: + 69 reps = kwargs.get("replica") + 70 if corr_type == 'bb': + 71 b2b = True + 72 single = True + 73 elif corr_type == 'bib': + 74 b2b = True + 75 single = False + 76 else: + 77 b2b = False + 78 single = False + 79 compact = True + 80 appended = False + 81 known_versions = ["0.0", "1.0", "2.0", "1.0c", "2.0c", "1.0a", "2.0a"] + 82 + 83 if version not in known_versions: + 84 raise Exception("This version is not known!") + 85 if (version[-1] == "c"): + 86 appended = False + 87 compact = True + 88 version = version[:-1] + 89 elif (version[-1] == "a"): + 90 appended = True + 91 compact = False + 92 version = version[:-1] + 93 else: + 94 compact = False + 95 appended = False + 96 read = 0 + 97 T = 0 + 98 start = 0 + 99 ls = [] +100 if "replica" in kwargs: +101 ls = reps +102 else: +103 for (dirpath, dirnames, filenames) in os.walk(path): +104 if not appended: +105 ls.extend(dirnames) +106 else: +107 ls.extend(filenames) +108 break +109 if not ls: +110 raise Exception('Error, directory not found') +111 # Exclude folders with different names +112 for exc in ls: +113 if not fnmatch.fnmatch(exc, prefix + '*'): +114 ls = list(set(ls) - set([exc])) +115 +116 if not appended: +117 if len(ls) > 1: +118 # New version, to cope with ids, etc. +119 ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) +120 replica = len(ls) +121 else: +122 replica = len([file.split(".")[-1] for file in ls]) // len(set([file.split(".")[-1] for file in ls])) +123 print('Read', part, 'part of', name, 'from', prefix[:-1], +124 ',', replica, 'replica') +125 if 'names' in kwargs: +126 new_names = kwargs.get('names') +127 if len(new_names) != len(set(new_names)): +128 raise Exception("names are not unique!") +129 if len(new_names) != replica: +130 raise Exception('Names does not have the required length', replica) +131 else: +132 new_names = [] +133 if not appended: +134 for entry in ls: +135 try: +136 idx = entry.index('r') +137 except Exception: +138 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +139 +140 if 'ens_name' in kwargs: +141 new_names.append(kwargs.get('ens_name') + '|' + entry[idx:]) +142 else: +143 new_names.append(entry[:idx] + '|' + entry[idx:]) +144 else: +145 +146 for exc in ls: +147 if not fnmatch.fnmatch(exc, prefix + '*.' + name): +148 ls = list(set(ls) - set([exc])) +149 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +150 for entry in ls: +151 myentry = entry[:-len(name) - 1] +152 try: +153 idx = myentry.index('r') +154 except Exception: +155 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +156 +157 if 'ens_name' in kwargs: +158 new_names.append(kwargs.get('ens_name') + '|' + myentry[idx:]) +159 else: +160 new_names.append(myentry[:idx] + '|' + myentry[idx:]) +161 idl = [] +162 if not appended: +163 for i, item in enumerate(ls): +164 sub_ls = [] +165 if "files" in kwargs: +166 sub_ls = kwargs.get("files") +167 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +168 else: +169 for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): +170 if compact: +171 sub_ls.extend(filenames) +172 else: +173 sub_ls.extend(dirnames) +174 break +175 if compact: +176 for exc in sub_ls: +177 if not fnmatch.fnmatch(exc, prefix + '*'): +178 sub_ls = list(set(sub_ls) - set([exc])) +179 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +180 else: +181 for exc in sub_ls: +182 if not fnmatch.fnmatch(exc, 'cfg*'): +183 sub_ls = list(set(sub_ls) - set([exc])) +184 sub_ls.sort(key=lambda x: int(x[3:])) +185 rep_idl = [] +186 no_cfg = len(sub_ls) +187 for cfg in sub_ls: +188 try: +189 if compact: +190 rep_idl.append(int(cfg.split(cfg_separator)[-1])) +191 else: +192 rep_idl.append(int(cfg[3:])) +193 except Exception: +194 raise Exception("Couldn't parse idl from directroy, problem with file " + cfg) +195 rep_idl.sort() +196 # maybe there is a better way to print the idls +197 print(item, ':', no_cfg, ' configurations') +198 idl.append(rep_idl) +199 # here we have found all the files we need to look into. +200 if i == 0: +201 # here, we want to find the place within the file, +202 # where the correlator we need is stored. +203 # to do so, the pattern needed is put together +204 # from the input values +205 if version == "0.0": +206 pattern = "# " + name + " : offset " + str(noffset) + ", wf " + str(wf) +207 # if b2b, a second wf is needed +208 if b2b: +209 pattern += ", wf_2 " + str(wf2) +210 qs = quarks.split(" ") +211 pattern += " : " + qs[0] + " - " + qs[1] +212 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") +213 for k, line in enumerate(file): +214 if read == 1 and not line.strip() and k > start + 1: +215 break +216 if read == 1 and k >= start: +217 T += 1 +218 if pattern in line: +219 read = 1 +220 start = k + 1 +221 print(str(T) + " entries found.") +222 file.close() +223 else: +224 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) +225 if b2b: +226 pattern += '\nwf_2 ' + str(wf2) +227 # and the file is parsed through to find the pattern +228 if compact: +229 file = open(path + '/' + item + '/' + sub_ls[0], "r") +230 else: +231 # for non-compactified versions of the files +232 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") +233 +234 content = file.read() +235 match = re.search(pattern, content) +236 if match: +237 start_read = content.count('\n', 0, match.start()) + 5 + b2b +238 end_match = re.search(r'\n\s*\n', content[match.start():]) +239 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b +240 assert T > 0 +241 print(T, 'entries, starting to read in line', start_read) +242 file.close() +243 else: +244 file.close() +245 raise Exception('Correlator with pattern\n' + pattern + '\nnot found.') 246 -247 for t in range(T): -248 deltas[t].append(np.zeros(no_cfg)) -249 if compact: -250 for cfg in range(no_cfg): -251 with open(path + '/' + item + '/' + sub_ls[cfg]) as fp: -252 lines = fp.readlines() -253 # check, if the correlator is in fact -254 # printed completely -255 if (start_read + T > len(lines)): -256 raise Exception("EOF before end of correlator data! Maybe " + path + '/' + item + '/' + sub_ls[cfg] + " is corrupted?") -257 # and start to read the correlator. -258 # the range here is chosen like this, -259 # since this allows for implementing -260 # a security check for every read correlator later... -261 for k in range(start_read - 6, start_read + T): -262 if k == start_read - 5 - b2b: -263 if lines[k].strip() != 'name ' + name: -264 raise Exception('Wrong format', sub_ls[cfg]) -265 if (k >= start_read and k < start_read + T): -266 floats = list(map(float, lines[k].split())) -267 deltas[k - start_read][i][cfg] = floats[-2:][im] -268 else: -269 for cnfg, subitem in enumerate(sub_ls): -270 with open(path + '/' + item + '/' + subitem + '/' + name) as fp: -271 # since the non-compatified files -272 # are typically not so long, -273 # we can iterate over the whole file. -274 # here one can also implement the chekc from above. -275 for k, line in enumerate(fp): -276 if (k >= start_read and k < start_read + T): -277 floats = list(map(float, line.split())) -278 if version == "0.0": -279 deltas[k - start][i][cnfg] = floats[im - single] -280 else: -281 deltas[k - start_read][i][cnfg] = floats[1 + im - single] -282 -283 else: -284 if "files" in kwargs: -285 ls = kwargs.get("files") -286 else: -287 for exc in ls: -288 if not fnmatch.fnmatch(exc, prefix + '*.' + name): -289 ls = list(set(ls) - set([exc])) -290 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -291 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) -292 if b2b: -293 pattern += '\nwf_2 ' + str(wf2) -294 for rep, file in enumerate(ls): -295 rep_idl = [] -296 with open(path + '/' + file, 'r') as fp: -297 content = fp.readlines() -298 data_starts = [] -299 for linenumber, line in enumerate(content): -300 if "[run]" in line: -301 data_starts.append(linenumber) -302 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: -303 raise Exception("Irregularities in file structure found, not all runs have the same output length") -304 chunk = content[:data_starts[1]] -305 for linenumber, line in enumerate(chunk): -306 if line.startswith("gauge_name"): -307 gauge_line = linenumber -308 elif line.startswith("[correlator]"): -309 corr_line = linenumber -310 found_pat = "" -311 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: -312 found_pat += li -313 if re.search(pattern, found_pat): -314 start_read = corr_line + 7 + b2b -315 break -316 endline = corr_line + 6 + b2b -317 while not chunk[endline] == "\n": -318 endline += 1 -319 T = endline - start_read -320 if rep == 0: -321 deltas = [] -322 for t in range(T): -323 deltas.append([]) -324 for t in range(T): -325 deltas[t].append(np.zeros(len(data_starts))) -326 # all other chunks should follow the same structure -327 for cnfg in range(len(data_starts)): -328 start = data_starts[cnfg] -329 stop = start + data_starts[1] -330 chunk = content[start:stop] -331 try: -332 rep_idl.append(int(chunk[gauge_line].split(cfg_separator)[-1])) -333 except Exception: -334 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) -335 -336 found_pat = "" -337 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: -338 found_pat += li -339 if re.search(pattern, found_pat): -340 for t, line in enumerate(chunk[start_read:start_read + T]): -341 floats = list(map(float, line.split())) -342 deltas[t][rep][cnfg] = floats[im + 1 - single] -343 idl.append(rep_idl) -344 -345 if "check_configs" in kwargs: -346 print("Checking for missing configs...") -347 che = kwargs.get("check_configs") -348 if not (len(che) == len(idl)): -349 raise Exception("check_configs has to be the same length as replica!") -350 for r in range(len(idl)): -351 print("checking " + new_names[r]) -352 utils.check_idl(idl[r], che[r]) -353 print("Done") -354 result = [] -355 for t in range(T): -356 result.append(Obs(deltas[t], new_names, idl=idl)) -357 return result +247 # we found where the correlator +248 # that is to be read is in the files +249 # after preparing the datastructure +250 # the correlators get parsed into... +251 deltas = [] +252 for j in range(T): +253 deltas.append([]) +254 +255 for t in range(T): +256 deltas[t].append(np.zeros(no_cfg)) +257 if compact: +258 for cfg in range(no_cfg): +259 with open(path + '/' + item + '/' + sub_ls[cfg]) as fp: +260 lines = fp.readlines() +261 # check, if the correlator is in fact +262 # printed completely +263 if (start_read + T > len(lines)): +264 raise Exception("EOF before end of correlator data! Maybe " + path + '/' + item + '/' + sub_ls[cfg] + " is corrupted?") +265 # and start to read the correlator. +266 # the range here is chosen like this, +267 # since this allows for implementing +268 # a security check for every read correlator later... +269 for k in range(start_read - 6, start_read + T): +270 if k == start_read - 5 - b2b: +271 if lines[k].strip() != 'name ' + name: +272 raise Exception('Wrong format', sub_ls[cfg]) +273 if (k >= start_read and k < start_read + T): +274 floats = list(map(float, lines[k].split())) +275 deltas[k - start_read][i][cfg] = floats[-2:][im] +276 else: +277 for cnfg, subitem in enumerate(sub_ls): +278 with open(path + '/' + item + '/' + subitem + '/' + name) as fp: +279 # since the non-compatified files +280 # are typically not so long, +281 # we can iterate over the whole file. +282 # here one can also implement the chekc from above. +283 for k, line in enumerate(fp): +284 if (k >= start_read and k < start_read + T): +285 floats = list(map(float, line.split())) +286 if version == "0.0": +287 deltas[k - start][i][cnfg] = floats[im - single] +288 else: +289 deltas[k - start_read][i][cnfg] = floats[1 + im - single] +290 +291 else: +292 if "files" in kwargs: +293 ls = kwargs.get("files") +294 else: +295 for exc in ls: +296 if not fnmatch.fnmatch(exc, prefix + '*.' + name): +297 ls = list(set(ls) - set([exc])) +298 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +299 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) +300 if b2b: +301 pattern += '\nwf_2 ' + str(wf2) +302 for rep, file in enumerate(ls): +303 rep_idl = [] +304 with open(path + '/' + file, 'r') as fp: +305 content = fp.readlines() +306 data_starts = [] +307 for linenumber, line in enumerate(content): +308 if "[run]" in line: +309 data_starts.append(linenumber) +310 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: +311 raise Exception("Irregularities in file structure found, not all runs have the same output length") +312 chunk = content[:data_starts[1]] +313 for linenumber, line in enumerate(chunk): +314 if line.startswith("gauge_name"): +315 gauge_line = linenumber +316 elif line.startswith("[correlator]"): +317 corr_line = linenumber +318 found_pat = "" +319 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: +320 found_pat += li +321 if re.search(pattern, found_pat): +322 start_read = corr_line + 7 + b2b +323 break +324 endline = corr_line + 6 + b2b +325 while not chunk[endline] == "\n": +326 endline += 1 +327 T = endline - start_read +328 if rep == 0: +329 deltas = [] +330 for t in range(T): +331 deltas.append([]) +332 for t in range(T): +333 deltas[t].append(np.zeros(len(data_starts))) +334 # all other chunks should follow the same structure +335 for cnfg in range(len(data_starts)): +336 start = data_starts[cnfg] +337 stop = start + data_starts[1] +338 chunk = content[start:stop] +339 try: +340 rep_idl.append(int(chunk[gauge_line].split(cfg_separator)[-1])) +341 except Exception: +342 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) +343 +344 found_pat = "" +345 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: +346 found_pat += li +347 if re.search(pattern, found_pat): +348 for t, line in enumerate(chunk[start_read:start_read + T]): +349 floats = list(map(float, line.split())) +350 deltas[t][rep][cnfg] = floats[im + 1 - single] +351 idl.append(rep_idl) +352 +353 if "check_configs" in kwargs: +354 print("Checking for missing configs...") +355 che = kwargs.get("check_configs") +356 if not (len(che) == len(idl)): +357 raise Exception("check_configs has to be the same length as replica!") +358 for r in range(len(idl)): +359 print("checking " + new_names[r]) +360 utils.check_idl(idl[r], che[r]) +361 print("Done") +362 result = [] +363 for t in range(T): +364 result.append(Obs(deltas[t], new_names, idl=idl)) +365 return result @@ -453,350 +461,358 @@ 12 13 Parameters 14 ---------- - 15 quarks: str - 16 Label of the quarks used in the sfcf input file. e.g. "quark quark" - 17 for version 0.0 this does NOT need to be given with the typical " - " - 18 that is present in the output file, - 19 this is done automatically for this version - 20 noffset: int - 21 Offset of the source (only relevant when wavefunctions are used) - 22 wf: int - 23 ID of wave function - 24 wf2: int - 25 ID of the second wavefunction - 26 (only relevant for boundary-to-boundary correlation functions) - 27 im: bool - 28 if True, read imaginary instead of real part - 29 of the correlation function. - 30 corr_type : str - 31 change between bi (boundary - inner) (default) bib (boundary - inner - boundary) and bb (boundary - boundary) - 32 correlator types - 33 names : list - 34 Alternative labeling for replicas/ensembles. - 35 Has to have the appropriate length - 36 ens_name : str - 37 replaces the name of the ensemble - 38 version: str - 39 version of SFCF, with which the measurement was done. - 40 if the compact output option (-c) was specified, - 41 append a "c" to the version (e.g. "1.0c") - 42 if the append output option (-a) was specified, - 43 append an "a" to the version - 44 cfg_separator : str - 45 String that separates the ensemble identifier from the configuration number (default 'n'). - 46 replica: list - 47 list of replica to be read, default is all - 48 files: list - 49 list of files to be read per replica, default is all. - 50 for non-compact output format, hand the folders to be read here. - 51 check_configs: - 52 list of list of supposed configs, eg. [range(1,1000)] - 53 for one replicum with 1000 configs - 54 """ - 55 if kwargs.get('im'): - 56 im = 1 - 57 part = 'imaginary' - 58 else: - 59 im = 0 - 60 part = 'real' - 61 if "replica" in kwargs: - 62 reps = kwargs.get("replica") - 63 if corr_type == 'bb': - 64 b2b = True - 65 single = True - 66 elif corr_type == 'bib': - 67 b2b = True - 68 single = False - 69 else: - 70 b2b = False - 71 single = False - 72 compact = True - 73 appended = False - 74 known_versions = ["0.0", "1.0", "2.0", "1.0c", "2.0c", "1.0a", "2.0a"] - 75 - 76 if version not in known_versions: - 77 raise Exception("This version is not known!") - 78 if (version[-1] == "c"): - 79 appended = False - 80 compact = True - 81 version = version[:-1] - 82 elif (version[-1] == "a"): - 83 appended = True - 84 compact = False - 85 version = version[:-1] - 86 else: - 87 compact = False - 88 appended = False - 89 read = 0 - 90 T = 0 - 91 start = 0 - 92 ls = [] - 93 if "replica" in kwargs: - 94 ls = reps - 95 else: - 96 for (dirpath, dirnames, filenames) in os.walk(path): - 97 if not appended: - 98 ls.extend(dirnames) - 99 else: -100 ls.extend(filenames) -101 break -102 if not ls: -103 raise Exception('Error, directory not found') -104 # Exclude folders with different names -105 for exc in ls: -106 if not fnmatch.fnmatch(exc, prefix + '*'): -107 ls = list(set(ls) - set([exc])) -108 -109 if not appended: -110 if len(ls) > 1: -111 # New version, to cope with ids, etc. -112 ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) -113 replica = len(ls) -114 else: -115 replica = len([file.split(".")[-1] for file in ls]) // len(set([file.split(".")[-1] for file in ls])) -116 print('Read', part, 'part of', name, 'from', prefix[:-1], -117 ',', replica, 'replica') -118 if 'names' in kwargs: -119 new_names = kwargs.get('names') -120 if len(new_names) != len(set(new_names)): -121 raise Exception("names are not unique!") -122 if len(new_names) != replica: -123 raise Exception('Names does not have the required length', replica) -124 else: -125 new_names = [] -126 if not appended: -127 for entry in ls: -128 try: -129 idx = entry.index('r') -130 except Exception: -131 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -132 -133 if 'ens_name' in kwargs: -134 new_names.append(kwargs.get('ens_name') + '|' + entry[idx:]) -135 else: -136 new_names.append(entry[:idx] + '|' + entry[idx:]) -137 else: -138 -139 for exc in ls: -140 if not fnmatch.fnmatch(exc, prefix + '*.' + name): -141 ls = list(set(ls) - set([exc])) -142 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -143 for entry in ls: -144 myentry = entry[:-len(name) - 1] -145 try: -146 idx = myentry.index('r') -147 except Exception: -148 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -149 -150 if 'ens_name' in kwargs: -151 new_names.append(kwargs.get('ens_name') + '|' + myentry[idx:]) -152 else: -153 new_names.append(myentry[:idx] + '|' + myentry[idx:]) -154 idl = [] -155 if not appended: -156 for i, item in enumerate(ls): -157 sub_ls = [] -158 if "files" in kwargs: -159 sub_ls = kwargs.get("files") -160 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -161 else: -162 for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): -163 if compact: -164 sub_ls.extend(filenames) -165 else: -166 sub_ls.extend(dirnames) -167 break -168 if compact: -169 for exc in sub_ls: -170 if not fnmatch.fnmatch(exc, prefix + '*'): -171 sub_ls = list(set(sub_ls) - set([exc])) -172 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -173 else: -174 for exc in sub_ls: -175 if not fnmatch.fnmatch(exc, 'cfg*'): -176 sub_ls = list(set(sub_ls) - set([exc])) -177 sub_ls.sort(key=lambda x: int(x[3:])) -178 rep_idl = [] -179 no_cfg = len(sub_ls) -180 for cfg in sub_ls: -181 try: -182 if compact: -183 rep_idl.append(int(cfg.split(cfg_separator)[-1])) -184 else: -185 rep_idl.append(int(cfg[3:])) -186 except Exception: -187 raise Exception("Couldn't parse idl from directroy, problem with file " + cfg) -188 rep_idl.sort() -189 # maybe there is a better way to print the idls -190 print(item, ':', no_cfg, ' configurations') -191 idl.append(rep_idl) -192 # here we have found all the files we need to look into. -193 if i == 0: -194 # here, we want to find the place within the file, -195 # where the correlator we need is stored. -196 # to do so, the pattern needed is put together -197 # from the input values -198 if version == "0.0": -199 pattern = "# " + name + " : offset " + str(noffset) + ", wf " + str(wf) -200 # if b2b, a second wf is needed -201 if b2b: -202 pattern += ", wf_2 " + str(wf2) -203 qs = quarks.split(" ") -204 pattern += " : " + qs[0] + " - " + qs[1] -205 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") -206 for k, line in enumerate(file): -207 if read == 1 and not line.strip() and k > start + 1: -208 break -209 if read == 1 and k >= start: -210 T += 1 -211 if pattern in line: -212 read = 1 -213 start = k + 1 -214 print(str(T) + " entries found.") -215 file.close() -216 else: -217 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) -218 if b2b: -219 pattern += '\nwf_2 ' + str(wf2) -220 # and the file is parsed through to find the pattern -221 if compact: -222 file = open(path + '/' + item + '/' + sub_ls[0], "r") -223 else: -224 # for non-compactified versions of the files -225 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") -226 -227 content = file.read() -228 match = re.search(pattern, content) -229 if match: -230 start_read = content.count('\n', 0, match.start()) + 5 + b2b -231 end_match = re.search(r'\n\s*\n', content[match.start():]) -232 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b -233 assert T > 0 -234 print(T, 'entries, starting to read in line', start_read) -235 file.close() -236 else: -237 file.close() -238 raise Exception('Correlator with pattern\n' + pattern + '\nnot found.') -239 -240 # we found where the correlator -241 # that is to be read is in the files -242 # after preparing the datastructure -243 # the correlators get parsed into... -244 deltas = [] -245 for j in range(T): -246 deltas.append([]) + 15 path : str + 16 Path to the sfcf files. + 17 prefix : str + 18 Prefix of the sfcf files. + 19 name : str + 20 Name of the correlation function to read. + 21 quarks : str + 22 Label of the quarks used in the sfcf input file. e.g. "quark quark" + 23 for version 0.0 this does NOT need to be given with the typical " - " + 24 that is present in the output file, + 25 this is done automatically for this version + 26 corr_type : str + 27 Type of correlation function to read. Can be + 28 - 'bi' for boundary-inner + 29 - 'bb' for boundary-boundary + 30 - 'bib' for boundary-inner-boundary + 31 noffset : int + 32 Offset of the source (only relevant when wavefunctions are used) + 33 wf : int + 34 ID of wave function + 35 wf2 : int + 36 ID of the second wavefunction + 37 (only relevant for boundary-to-boundary correlation functions) + 38 im : bool + 39 if True, read imaginary instead of real part + 40 of the correlation function. + 41 names : list + 42 Alternative labeling for replicas/ensembles. + 43 Has to have the appropriate length + 44 ens_name : str + 45 replaces the name of the ensemble + 46 version: str + 47 version of SFCF, with which the measurement was done. + 48 if the compact output option (-c) was specified, + 49 append a "c" to the version (e.g. "1.0c") + 50 if the append output option (-a) was specified, + 51 append an "a" to the version + 52 cfg_separator : str + 53 String that separates the ensemble identifier from the configuration number (default 'n'). + 54 replica: list + 55 list of replica to be read, default is all + 56 files: list + 57 list of files to be read per replica, default is all. + 58 for non-compact output format, hand the folders to be read here. + 59 check_configs: + 60 list of list of supposed configs, eg. [range(1,1000)] + 61 for one replicum with 1000 configs + 62 """ + 63 if kwargs.get('im'): + 64 im = 1 + 65 part = 'imaginary' + 66 else: + 67 im = 0 + 68 part = 'real' + 69 if "replica" in kwargs: + 70 reps = kwargs.get("replica") + 71 if corr_type == 'bb': + 72 b2b = True + 73 single = True + 74 elif corr_type == 'bib': + 75 b2b = True + 76 single = False + 77 else: + 78 b2b = False + 79 single = False + 80 compact = True + 81 appended = False + 82 known_versions = ["0.0", "1.0", "2.0", "1.0c", "2.0c", "1.0a", "2.0a"] + 83 + 84 if version not in known_versions: + 85 raise Exception("This version is not known!") + 86 if (version[-1] == "c"): + 87 appended = False + 88 compact = True + 89 version = version[:-1] + 90 elif (version[-1] == "a"): + 91 appended = True + 92 compact = False + 93 version = version[:-1] + 94 else: + 95 compact = False + 96 appended = False + 97 read = 0 + 98 T = 0 + 99 start = 0 +100 ls = [] +101 if "replica" in kwargs: +102 ls = reps +103 else: +104 for (dirpath, dirnames, filenames) in os.walk(path): +105 if not appended: +106 ls.extend(dirnames) +107 else: +108 ls.extend(filenames) +109 break +110 if not ls: +111 raise Exception('Error, directory not found') +112 # Exclude folders with different names +113 for exc in ls: +114 if not fnmatch.fnmatch(exc, prefix + '*'): +115 ls = list(set(ls) - set([exc])) +116 +117 if not appended: +118 if len(ls) > 1: +119 # New version, to cope with ids, etc. +120 ls.sort(key=lambda x: int(re.findall(r'\d+', x[len(prefix):])[0])) +121 replica = len(ls) +122 else: +123 replica = len([file.split(".")[-1] for file in ls]) // len(set([file.split(".")[-1] for file in ls])) +124 print('Read', part, 'part of', name, 'from', prefix[:-1], +125 ',', replica, 'replica') +126 if 'names' in kwargs: +127 new_names = kwargs.get('names') +128 if len(new_names) != len(set(new_names)): +129 raise Exception("names are not unique!") +130 if len(new_names) != replica: +131 raise Exception('Names does not have the required length', replica) +132 else: +133 new_names = [] +134 if not appended: +135 for entry in ls: +136 try: +137 idx = entry.index('r') +138 except Exception: +139 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +140 +141 if 'ens_name' in kwargs: +142 new_names.append(kwargs.get('ens_name') + '|' + entry[idx:]) +143 else: +144 new_names.append(entry[:idx] + '|' + entry[idx:]) +145 else: +146 +147 for exc in ls: +148 if not fnmatch.fnmatch(exc, prefix + '*.' + name): +149 ls = list(set(ls) - set([exc])) +150 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +151 for entry in ls: +152 myentry = entry[:-len(name) - 1] +153 try: +154 idx = myentry.index('r') +155 except Exception: +156 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +157 +158 if 'ens_name' in kwargs: +159 new_names.append(kwargs.get('ens_name') + '|' + myentry[idx:]) +160 else: +161 new_names.append(myentry[:idx] + '|' + myentry[idx:]) +162 idl = [] +163 if not appended: +164 for i, item in enumerate(ls): +165 sub_ls = [] +166 if "files" in kwargs: +167 sub_ls = kwargs.get("files") +168 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +169 else: +170 for (dirpath, dirnames, filenames) in os.walk(path + '/' + item): +171 if compact: +172 sub_ls.extend(filenames) +173 else: +174 sub_ls.extend(dirnames) +175 break +176 if compact: +177 for exc in sub_ls: +178 if not fnmatch.fnmatch(exc, prefix + '*'): +179 sub_ls = list(set(sub_ls) - set([exc])) +180 sub_ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +181 else: +182 for exc in sub_ls: +183 if not fnmatch.fnmatch(exc, 'cfg*'): +184 sub_ls = list(set(sub_ls) - set([exc])) +185 sub_ls.sort(key=lambda x: int(x[3:])) +186 rep_idl = [] +187 no_cfg = len(sub_ls) +188 for cfg in sub_ls: +189 try: +190 if compact: +191 rep_idl.append(int(cfg.split(cfg_separator)[-1])) +192 else: +193 rep_idl.append(int(cfg[3:])) +194 except Exception: +195 raise Exception("Couldn't parse idl from directroy, problem with file " + cfg) +196 rep_idl.sort() +197 # maybe there is a better way to print the idls +198 print(item, ':', no_cfg, ' configurations') +199 idl.append(rep_idl) +200 # here we have found all the files we need to look into. +201 if i == 0: +202 # here, we want to find the place within the file, +203 # where the correlator we need is stored. +204 # to do so, the pattern needed is put together +205 # from the input values +206 if version == "0.0": +207 pattern = "# " + name + " : offset " + str(noffset) + ", wf " + str(wf) +208 # if b2b, a second wf is needed +209 if b2b: +210 pattern += ", wf_2 " + str(wf2) +211 qs = quarks.split(" ") +212 pattern += " : " + qs[0] + " - " + qs[1] +213 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") +214 for k, line in enumerate(file): +215 if read == 1 and not line.strip() and k > start + 1: +216 break +217 if read == 1 and k >= start: +218 T += 1 +219 if pattern in line: +220 read = 1 +221 start = k + 1 +222 print(str(T) + " entries found.") +223 file.close() +224 else: +225 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) +226 if b2b: +227 pattern += '\nwf_2 ' + str(wf2) +228 # and the file is parsed through to find the pattern +229 if compact: +230 file = open(path + '/' + item + '/' + sub_ls[0], "r") +231 else: +232 # for non-compactified versions of the files +233 file = open(path + '/' + item + '/' + sub_ls[0] + '/' + name, "r") +234 +235 content = file.read() +236 match = re.search(pattern, content) +237 if match: +238 start_read = content.count('\n', 0, match.start()) + 5 + b2b +239 end_match = re.search(r'\n\s*\n', content[match.start():]) +240 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b +241 assert T > 0 +242 print(T, 'entries, starting to read in line', start_read) +243 file.close() +244 else: +245 file.close() +246 raise Exception('Correlator with pattern\n' + pattern + '\nnot found.') 247 -248 for t in range(T): -249 deltas[t].append(np.zeros(no_cfg)) -250 if compact: -251 for cfg in range(no_cfg): -252 with open(path + '/' + item + '/' + sub_ls[cfg]) as fp: -253 lines = fp.readlines() -254 # check, if the correlator is in fact -255 # printed completely -256 if (start_read + T > len(lines)): -257 raise Exception("EOF before end of correlator data! Maybe " + path + '/' + item + '/' + sub_ls[cfg] + " is corrupted?") -258 # and start to read the correlator. -259 # the range here is chosen like this, -260 # since this allows for implementing -261 # a security check for every read correlator later... -262 for k in range(start_read - 6, start_read + T): -263 if k == start_read - 5 - b2b: -264 if lines[k].strip() != 'name ' + name: -265 raise Exception('Wrong format', sub_ls[cfg]) -266 if (k >= start_read and k < start_read + T): -267 floats = list(map(float, lines[k].split())) -268 deltas[k - start_read][i][cfg] = floats[-2:][im] -269 else: -270 for cnfg, subitem in enumerate(sub_ls): -271 with open(path + '/' + item + '/' + subitem + '/' + name) as fp: -272 # since the non-compatified files -273 # are typically not so long, -274 # we can iterate over the whole file. -275 # here one can also implement the chekc from above. -276 for k, line in enumerate(fp): -277 if (k >= start_read and k < start_read + T): -278 floats = list(map(float, line.split())) -279 if version == "0.0": -280 deltas[k - start][i][cnfg] = floats[im - single] -281 else: -282 deltas[k - start_read][i][cnfg] = floats[1 + im - single] -283 -284 else: -285 if "files" in kwargs: -286 ls = kwargs.get("files") -287 else: -288 for exc in ls: -289 if not fnmatch.fnmatch(exc, prefix + '*.' + name): -290 ls = list(set(ls) - set([exc])) -291 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -292 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) -293 if b2b: -294 pattern += '\nwf_2 ' + str(wf2) -295 for rep, file in enumerate(ls): -296 rep_idl = [] -297 with open(path + '/' + file, 'r') as fp: -298 content = fp.readlines() -299 data_starts = [] -300 for linenumber, line in enumerate(content): -301 if "[run]" in line: -302 data_starts.append(linenumber) -303 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: -304 raise Exception("Irregularities in file structure found, not all runs have the same output length") -305 chunk = content[:data_starts[1]] -306 for linenumber, line in enumerate(chunk): -307 if line.startswith("gauge_name"): -308 gauge_line = linenumber -309 elif line.startswith("[correlator]"): -310 corr_line = linenumber -311 found_pat = "" -312 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: -313 found_pat += li -314 if re.search(pattern, found_pat): -315 start_read = corr_line + 7 + b2b -316 break -317 endline = corr_line + 6 + b2b -318 while not chunk[endline] == "\n": -319 endline += 1 -320 T = endline - start_read -321 if rep == 0: -322 deltas = [] -323 for t in range(T): -324 deltas.append([]) -325 for t in range(T): -326 deltas[t].append(np.zeros(len(data_starts))) -327 # all other chunks should follow the same structure -328 for cnfg in range(len(data_starts)): -329 start = data_starts[cnfg] -330 stop = start + data_starts[1] -331 chunk = content[start:stop] -332 try: -333 rep_idl.append(int(chunk[gauge_line].split(cfg_separator)[-1])) -334 except Exception: -335 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) -336 -337 found_pat = "" -338 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: -339 found_pat += li -340 if re.search(pattern, found_pat): -341 for t, line in enumerate(chunk[start_read:start_read + T]): -342 floats = list(map(float, line.split())) -343 deltas[t][rep][cnfg] = floats[im + 1 - single] -344 idl.append(rep_idl) -345 -346 if "check_configs" in kwargs: -347 print("Checking for missing configs...") -348 che = kwargs.get("check_configs") -349 if not (len(che) == len(idl)): -350 raise Exception("check_configs has to be the same length as replica!") -351 for r in range(len(idl)): -352 print("checking " + new_names[r]) -353 utils.check_idl(idl[r], che[r]) -354 print("Done") -355 result = [] -356 for t in range(T): -357 result.append(Obs(deltas[t], new_names, idl=idl)) -358 return result +248 # we found where the correlator +249 # that is to be read is in the files +250 # after preparing the datastructure +251 # the correlators get parsed into... +252 deltas = [] +253 for j in range(T): +254 deltas.append([]) +255 +256 for t in range(T): +257 deltas[t].append(np.zeros(no_cfg)) +258 if compact: +259 for cfg in range(no_cfg): +260 with open(path + '/' + item + '/' + sub_ls[cfg]) as fp: +261 lines = fp.readlines() +262 # check, if the correlator is in fact +263 # printed completely +264 if (start_read + T > len(lines)): +265 raise Exception("EOF before end of correlator data! Maybe " + path + '/' + item + '/' + sub_ls[cfg] + " is corrupted?") +266 # and start to read the correlator. +267 # the range here is chosen like this, +268 # since this allows for implementing +269 # a security check for every read correlator later... +270 for k in range(start_read - 6, start_read + T): +271 if k == start_read - 5 - b2b: +272 if lines[k].strip() != 'name ' + name: +273 raise Exception('Wrong format', sub_ls[cfg]) +274 if (k >= start_read and k < start_read + T): +275 floats = list(map(float, lines[k].split())) +276 deltas[k - start_read][i][cfg] = floats[-2:][im] +277 else: +278 for cnfg, subitem in enumerate(sub_ls): +279 with open(path + '/' + item + '/' + subitem + '/' + name) as fp: +280 # since the non-compatified files +281 # are typically not so long, +282 # we can iterate over the whole file. +283 # here one can also implement the chekc from above. +284 for k, line in enumerate(fp): +285 if (k >= start_read and k < start_read + T): +286 floats = list(map(float, line.split())) +287 if version == "0.0": +288 deltas[k - start][i][cnfg] = floats[im - single] +289 else: +290 deltas[k - start_read][i][cnfg] = floats[1 + im - single] +291 +292 else: +293 if "files" in kwargs: +294 ls = kwargs.get("files") +295 else: +296 for exc in ls: +297 if not fnmatch.fnmatch(exc, prefix + '*.' + name): +298 ls = list(set(ls) - set([exc])) +299 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +300 pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) +301 if b2b: +302 pattern += '\nwf_2 ' + str(wf2) +303 for rep, file in enumerate(ls): +304 rep_idl = [] +305 with open(path + '/' + file, 'r') as fp: +306 content = fp.readlines() +307 data_starts = [] +308 for linenumber, line in enumerate(content): +309 if "[run]" in line: +310 data_starts.append(linenumber) +311 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: +312 raise Exception("Irregularities in file structure found, not all runs have the same output length") +313 chunk = content[:data_starts[1]] +314 for linenumber, line in enumerate(chunk): +315 if line.startswith("gauge_name"): +316 gauge_line = linenumber +317 elif line.startswith("[correlator]"): +318 corr_line = linenumber +319 found_pat = "" +320 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: +321 found_pat += li +322 if re.search(pattern, found_pat): +323 start_read = corr_line + 7 + b2b +324 break +325 endline = corr_line + 6 + b2b +326 while not chunk[endline] == "\n": +327 endline += 1 +328 T = endline - start_read +329 if rep == 0: +330 deltas = [] +331 for t in range(T): +332 deltas.append([]) +333 for t in range(T): +334 deltas[t].append(np.zeros(len(data_starts))) +335 # all other chunks should follow the same structure +336 for cnfg in range(len(data_starts)): +337 start = data_starts[cnfg] +338 stop = start + data_starts[1] +339 chunk = content[start:stop] +340 try: +341 rep_idl.append(int(chunk[gauge_line].split(cfg_separator)[-1])) +342 except Exception: +343 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) +344 +345 found_pat = "" +346 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: +347 found_pat += li +348 if re.search(pattern, found_pat): +349 for t, line in enumerate(chunk[start_read:start_read + T]): +350 floats = list(map(float, line.split())) +351 deltas[t][rep][cnfg] = floats[im + 1 - single] +352 idl.append(rep_idl) +353 +354 if "check_configs" in kwargs: +355 print("Checking for missing configs...") +356 che = kwargs.get("check_configs") +357 if not (len(che) == len(idl)): +358 raise Exception("check_configs has to be the same length as replica!") +359 for r in range(len(idl)): +360 print("checking " + new_names[r]) +361 utils.check_idl(idl[r], che[r]) +362 print("Done") +363 result = [] +364 for t in range(T): +365 result.append(Obs(deltas[t], new_names, idl=idl)) +366 return result @@ -805,11 +821,24 @@
Parameters