def get_bias_data_per_config(bias_list, sl_list, key_list, mom_labels): """ gets bias data from (ex and sl)-solves """ bias_data = None for file_pairs, keys in zip(bias_list, key_list): file_ex, file_sl = file_pairs aff_ex, aff_sl = aff.Reader(file_ex), aff.Reader(file_sl) dat_ex = get_aff_data(aff_ex, keys[0], mom_labels) dat_sl = get_aff_data(aff_sl, keys[1], mom_labels) if bias_data is None: bias_data = dat_ex - dat_sl else: bias_data += (dat_ex - dat_sl) aff_ex.close() aff_sl.close() bias_data = bias_data / float(len(bias_list)) return bias_data
def convert_from_file(t_in_fn, t_out_fn): print(f"Converting file: {t_in_fn}\n" + f"to file : {t_out_fn}") reader = aff.Reader(t_in_fn) with h5.File(t_out_fn, 'w') as h5f: for key in reader.ls(""): recursion_keypath(reader, key, h5f) reader.close()
def get_aff_key(aff_file): """ Returns the tree structure of an aff-file """ aff_r = aff.Reader(aff_file) loc, tree = '', [] while bool(aff_r.ls(loc)): val = aff_r.ls(loc) loc = loc + "/" + val[0] tree.append(val) aff_r.close() return tree
def get_sl_data_per_config(bias_list, sl_list, key_list, mom_labels): """ gets data from sl-solve """ aff_sl_list = [aff.Reader(f_sl) for f_sl in sl_list] aff_sl = np.asarray([ get_aff_data(afr, ksl, mom_labels) for afr, ksl in zip(aff_sl_list, key_list) ]) sl_data = aff_sl.mean(axis=0) for aff_r in aff_sl_list: aff_r.close() return sl_data
def get_ex_data_per_config(bias_list, sl_list, key_list, mom_labels): """ gets data from ex-solve """ ex_data = None for file_pairs, keys in zip(bias_list, key_list): file_ex = file_pairs[0] aff_ex = aff.Reader(file_ex) dat_ex = get_aff_data(aff_ex, keys[0], mom_labels) if ex_data is None: ex_data = dat_ex else: ex_data += dat_ex aff_ex.close() ex_data = ex_data / float(len(bias_list)) return ex_data
def check_output_data(p, test_dir='.'): aff_r = aff.Reader(test_dir + '/' + p['aff_file']) frw_p = np.array(aff_r.read(p['frw_kpath'])).reshape((3, 4, 3, 4)) bkw_p = np.array(aff_r.read(p['bkw_kpath'])).reshape((3, 4, 3, 4)) qv = np.empty((16, 3, 4, 3, 4), np.complex128) for iG in range(16): d = aff_r.read(p['qv_kpath'] + ('/g%d' % iG)) qv[iG] = np.array(d).reshape((3, 4, 3, 4)) frw_p1, bkw_p1, qv1 = make_test_res_p(p) cmp_data = (np.allclose(frw_p, frw_p1) and np.allclose(bkw_p, bkw_p1) and np.allclose(qv, qv1)) #print y.shape, y1.shape dqv = qv - qv1 print("%e\t%e\t%e" % (cplx_norm2(frw_p), cplx_norm2(frw_p1), rdiff(frw_p, frw_p1))) print("%e\t%e\t%e" % (cplx_norm2(bkw_p), cplx_norm2(bkw_p1), rdiff(bkw_p, bkw_p1))) print("%e\t%e\t%e" % (cplx_norm2(qv), cplx_norm2(qv1), rdiff(qv, qv1))) return cmp_data
def read_data(t_path, t_key_list, t_auto_first_key=None): """ t_path: pathlib.Path or string Represents the path where the *.aff data files are stored. This function reads all contained .aff files. t_key_list: list of strings Represents the keypath key0/key1/key2/... within the .aff files stored in t_path. t_auto_first_key: int, default: None If the first key, i.e. key0 is not the same for all files in t_path and automatically insert the one determined by ``` aff.Reader.ls("")[t_auto_first_key] ``` If None is given omit this step. The keypath will then be the intersection of all keys in `t_key_list` Returns: numpy.ndarray array representing the correlators in the format [ [gauge1], [gauge2], ..., [gaugeN] ] where [gauge1] is a numpy.array of the size t_Nt (temporal direction of gauge configuration used for the correlator) This functions reads all the data in t_path for a given set of t_keys. It returns a single np.ndarray containing the data. It is assumed that each file corresponds to one configuration. """ if isinstance(t_path, str): t_path = Path(t_path) # get the key path for the aff files keypath = keypath_from_list(t_key_list) # get the aff file names data_fn_list = [fn.name for fn in t_path.rglob('*.aff')] # get the data sizes. It is assumed that all files contain the same size under keypath size_reader = aff.Reader(t_path / data_fn_list[0]) if t_auto_first_key is not None: l_keypath = size_reader.ls("")[t_auto_first_key] + '/' + keypath data = np.ndarray(shape=(len(data_fn_list), size_reader.size(l_keypath)), dtype=size_reader.type(l_keypath)) else: data = np.ndarray(shape=(len(data_fn_list), size_reader.size(keypath)), dtype=size_reader.type(keypath)) size_reader.close() # a counter to index [gauge1],[gauge2], ... print("Reading files...") for i_fn, fn in enumerate(data_fn_list): # determine keypath: fn = t_path / fn # create reader reader = aff.Reader(fn) # correct the keypath bey key0 if desired if t_auto_first_key is not None: l_keypath = reader.ls("")[t_auto_first_key] + '/' + keypath else: l_keypath = keypath # read the data and store it in the array data[i_fn] = np.array(reader.read(l_keypath)) # finialize this step and go to next gauge file reader.close() print( f"Done reading! Read {data.shape[0]} files, with sizes = {data.shape[1:]}." ) return data