From 62cb0ab1bbf9b587dc9335735a835c508562313f Mon Sep 17 00:00:00 2001 From: jkuhl-uni Date: Fri, 14 Jan 2022 21:06:41 +0100 Subject: [PATCH] flake8 compliance without E501 --- pyerrors/input/openQCD.py | 56 +++++++------------ pyerrors/input/sfcf.py | 114 ++++++++++++++------------------------ 2 files changed, 62 insertions(+), 108 deletions(-) diff --git a/pyerrors/input/openQCD.py b/pyerrors/input/openQCD.py index 60ed64c7..8caede78 100644 --- a/pyerrors/input/openQCD.py +++ b/pyerrors/input/openQCD.py @@ -75,8 +75,7 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs): for entry in ls: truncated_entry = entry.split('.')[0] idx = truncated_entry.index('r') - rep_names.append(truncated_entry[:idx] + '|' - + truncated_entry[idx:]) + rep_names.append(truncated_entry[:idx] + '|' + truncated_entry[idx:]) print_err = 0 if 'print_err' in kwargs: @@ -99,12 +98,8 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs): deltas.append([]) else: # little weird if-clause due to the /2 operation needed. - if ((nrw != struct.unpack('i', t)[0] and - (not version == '2.0')) or - (nrw != struct.unpack('i', t)[0] / 2 and - version == '2.0')): - raise Exception('Error: different number of reweighting\ - factors for replicum', rep) + if ((nrw != struct.unpack('i', t)[0] and (not version == '2.0')) or (nrw != struct.unpack('i', t)[0] / 2 and version == '2.0')): + raise Exception('Error: different number of reweighting factors for replicum', rep) for k in range(nrw): tmp_array.append([]) @@ -307,8 +302,7 @@ def extract_t0(path, prefix, dtr_read, xmin, samples[-1].append(cnfg[n]) samples[-1] = samples[-1][r_start[nrep]:r_stop[nrep]] new_obs = Obs(samples, [(w.split('.'))[0] for w in ls]) - t2E_dict[n * dn * eps] = (n * dn * eps) ** 2 * new_obs \ - / (spatial_extent ** 3) - 0.3 + t2E_dict[n * dn * eps] = (n * dn * eps) ** 2 * new_obs / (spatial_extent ** 3) - 0.3 zero_crossing = np.argmax(np.array( [o.value for o in t2E_dict.values()]) > 0.0) @@ -424,9 +418,7 @@ def read_qtop(path, prefix, c, dtr_cnfg=1, version="1.2", **kwargs): supposed_L = kwargs.get("L") else: if "L" not in kwargs: - raise Exception("This version of openQCD needs you \ - to provide the spatial length of the \ - lattice as parameter 'L'.") + raise Exception("This version of openQCD needs you to provide the spatial length of the lattice as parameter 'L'.") else: L = kwargs.get("L") r_start = 1 @@ -441,12 +433,12 @@ def read_qtop(path, prefix, c, dtr_cnfg=1, version="1.2", **kwargs): # find files in path found = [] files = [] - for (dirpath, dirnames, filenames) in os.walk(path+"/"): + for (dirpath, dirnames, filenames) in os.walk(path + "/"): # print(filenames) found.extend(filenames) break for f in found: - if fnmatch.fnmatch(f, prefix+"*"+".ms.dat"): + if fnmatch.fnmatch(f, prefix + "*" + ".ms.dat"): files.append(f) print(files) # now that we found our files, we dechiffer them... @@ -455,7 +447,7 @@ def read_qtop(path, prefix, c, dtr_cnfg=1, version="1.2", **kwargs): deltas = [] idl = [] for rep, file in enumerate(files): - with open(path+"/"+file, "rb") as fp: + with open(path + "/" + file, "rb") as fp: # header t = fp.read(12) header = struct.unpack(' 0 - print(T, 'entries, starting to read in line', - start_read) + print(T, 'entries, starting to read in line', start_read) else: - raise Exception('Correlator with pattern\n' - + pattern + '\nnot found.') + raise Exception('Correlator with pattern\n' + pattern + '\nnot found.') else: # this part does the same as above, # but for non-compactified versions of the files - with open(path + '/' + item + '/' + sub_ls[0] + '/' - + name) as fp: + with open(path + '/' + item + '/' + sub_ls[0] + '/' + name) as fp: for k, line in enumerate(fp): if version == "0.0": # check if this is really the right file # by matching pattern similar to above - pattern = "# "+name+" : offset "+str(noffset)\ - + ", wf "+str(wf) + pattern = "# " + name + " : offset " + str(noffset) + ", wf " + str(wf) # if b2b, a second wf is needed if b2b: - pattern += ", wf_2 "+str(wf2) + pattern += ", wf_2 " + str(wf2) qs = quarks.split(" ") - pattern += " : " + qs[0]+" - " + qs[1] + pattern += " : " + qs[0] + " - " + qs[1] # print(pattern) - if read == 1 and not line.strip() \ - and k > start + 1: + if read == 1 and not line.strip() and k > start + 1: break if read == 1 and k >= start: T += 1 @@ -277,13 +258,13 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, if pattern in line: # print(line) read = 1 - start = k+1 + start = k + 1 else: if '[correlator]' in line: read = 1 start = k + 7 + b2b T -= b2b - print(str(T)+" entries found.") + print(str(T) + " entries found.") # we found where the correlator # that is to be read is in the files # after preparing the datastructure @@ -303,9 +284,7 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, # check, if the correlator is in fact # printed completely if(start_read + T > len(lines)): - raise Exception("EOF before end of correlator data! \ - Maybe "+path + '/' + item + '/' + sub_ls[cfg]+" \ - is corrupted?") + raise Exception("EOF before end of correlator data! Maybe " + path + '/' + item + '/' + sub_ls[cfg] + " is corrupted?") # and start to read the correlator. # the range here is chosen like this, # since this allows for implementing @@ -317,12 +296,10 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, sub_ls[cfg]) if(k >= start_read and k < start_read + T): floats = list(map(float, lines[k].split())) - deltas[k - start_read][i][cfg] = \ - floats[-2:][im] + deltas[k - start_read][i][cfg] = floats[-2:][im] else: for cnfg, subitem in enumerate(sub_ls): - with open(path + '/' + item + '/' + subitem - + '/' + name) as fp: + with open(path + '/' + item + '/' + subitem + '/' + name) as fp: # since the non-compatified files # are typically not so long, # we can iterate over the whole file. @@ -331,23 +308,20 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, if(k >= start and k < start + T): floats = list(map(float, line.split())) if version == "0.0": - deltas[k-start][i][cnfg] = floats[im] + deltas[k - start][i][cnfg] = floats[im] else: - deltas[k - start][i][cnfg] = \ - floats[1 + im - single] + deltas[k - start][i][cnfg] = floats[1 + im - single] else: if "files" in kwargs: ls = kwargs.get("files") else: for exc in ls: - if not fnmatch.fnmatch(exc, prefix + '*.'+name): + if not fnmatch.fnmatch(exc, prefix + '*.' + name): ls = list(set(ls) - set([exc])) ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) # print(ls) - pattern = 'name ' + name + '\nquarks '\ - + quarks + '\noffset ' + str(noffset)\ - + '\nwf ' + str(wf) + pattern = 'name ' + name + '\nquarks ' + quarks + '\noffset ' + str(noffset) + '\nwf ' + str(wf) if b2b: pattern += '\nwf_2 ' + str(wf2) for rep, file in enumerate(ls): @@ -358,10 +332,9 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, for linenumber, line in enumerate(content): if "[run]" in line: data_starts.append(linenumber) - if len(set([data_starts[i]-data_starts[i-1] for i in - range(1, len(data_starts))])) > 1: - raise Exception("Irregularities in file structure found,\ - not all runs have the same output length") + if len(set([data_starts[i] - data_starts[i - 1] for i in + range(1, len(data_starts))])) > 1: + raise Exception("Irregularities in file structure found, not all runs have the same output length") # first chunk of data chunk = content[:data_starts[1]] for linenumber, line in enumerate(chunk): @@ -370,11 +343,11 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, elif line.startswith("[correlator]"): corr_line = linenumber found_pat = "" - for li in chunk[corr_line+1:corr_line+6+b2b]: + for li in chunk[corr_line + 1:corr_line + 6 + b2b]: found_pat += li if re.search(pattern, found_pat): - start_read = corr_line+7+b2b - T = len(chunk)-1-start_read + start_read = corr_line + 7 + b2b + T = len(chunk) - 1 - start_read if rep == 0: deltas = [] for t in range(T): @@ -384,21 +357,19 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, # all other chunks should follow the same structure for cnfg in range(len(data_starts)): start = data_starts[cnfg] - stop = start+data_starts[1] + stop = start + data_starts[1] chunk = content[start:stop] # meta_data = {} try: rep_idl.append(int(chunk[gauge_line].split("n")[-1])) except Exception: - raise Exception("Couldn't parse idl from directroy, \ - problem with chunk around line "+gauge_line) + raise Exception("Couldn't parse idl from directroy, problem with chunk around line " + gauge_line) found_pat = "" - for li in chunk[corr_line+1:corr_line+6+b2b]: + for li in chunk[corr_line + 1:corr_line + 6 + b2b]: found_pat += li if re.search(pattern, found_pat): - for t, line in \ - enumerate(chunk[start_read:start_read+T]): + for t, line in enumerate(chunk[start_read:start_read + T]): floats = list(map(float, line.split())) deltas[t][rep][cnfg] = floats[-2:][im] idl.append(rep_idl) @@ -407,10 +378,9 @@ def read_sfcf(path, prefix, name, quarks='.*', noffset=0, wf=0, wf2=0, print("Checking for missing configs...") che = kwargs.get("check_configs") if not (len(che) == len(idl)): - raise Exception("check_configs has to be the same length\ - as replica!") + raise Exception("check_configs has to be the same length as replica!") for r in range(len(idl)): - print("checking "+new_names[r]) + print("checking " + new_names[r]) utils.check_idl(idl[r], che[r]) print("Done") result = []