def get_data(correlator, data_file, ensemble_name): stub, ext = os.path.splitext(data_file) suffix = int(ext[1:]) file_list_info = sigmond.FileListInfo(stub, suffix, suffix, False) mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") corr_data_xml.append(file_list_info.xml()) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler([file_list_info], set(), set(), ensemble_info) keys = corr_handler.getOrderedKeys(correlator) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() correlator_data = dict() corr_time_info = sigmond.CorrelatorAtTimeInfo(correlator, 0, True, False) for tsep in range(tmin, tmax + 1): for cmp_i, complex_arg in enumerate(COMPLEX_ARGS): corr_time_info.resetTimeSeparation(tsep) obs_info = sigmond.MCObsInfo(corr_time_info, complex_arg) data = obs_handler.getBins(obs_info) correlator_data[obs_info] = np.array(data.array()) return correlator_data
def get_data(correlator, data_files, ensemble_name, ensemble_Nt, tsrc, forward): if not forward: correlator.setBackwards() mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") bl_op = correlator.getSource().getBasicLapH() # TODO: replace with isFermionic() change_sign = bl_op.isBaryon() or bl_op.isMesonBaryon() file_list_infos = list() has_opposite = data_files[1] is not None for data_file in data_files: if data_file is None: continue stub, ext = os.path.splitext(data_file) suffix = int(ext[1:]) file_list_info = sigmond.FileListInfo(stub, suffix, suffix, False) corr_data_xml.append(file_list_info.xml()) file_list_infos.append(file_list_info) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(), set(), ensemble_info) keys = corr_handler.getOrderedKeys(correlator) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() if has_opposite: correlator_opposite = sigmond.CorrelatorInfo(correlator.getSource(), correlator.getSink()) keys = corr_handler.getOrderedKeys(correlator_opposite) tmin_opp = keys[0].getTimeIndex() tmax_opp = keys[-1].getTimeIndex() if tmin != tmin_opp: print("mismatch between tmin on corresponding correlators") exit() if tmax != tmax_opp: print("mismatch between tmax on corresponding correlators") exit() correlator_data = dict() corr_time_info = sigmond.CorrelatorAtTimeInfo(correlator, 0, False, False) if has_opposite: corr_time_info_opp = sigmond.CorrelatorAtTimeInfo( correlator_opposite, 0, False, False) corr_time_info_herm = sigmond.CorrelatorAtTimeInfo(correlator, 0, True, False) for tsep in range(tmin, tmax + 1): for complex_arg in COMPLEX_ARGS: if correlator.isSinkSourceSame( ) and complex_arg is sigmond.ComplexArg.ImaginaryPart: continue corr_time_info.resetTimeSeparation(tsep) corr_time_info_obs_info = sigmond.MCObsInfo( corr_time_info, complex_arg) data = np.array( obs_handler.getBins(corr_time_info_obs_info).array()) if has_opposite: corr_time_info_opp.resetTimeSeparation(tsep) corr_time_info_opp_obs_info = sigmond.MCObsInfo( corr_time_info_opp, complex_arg) data_opp = np.array( obs_handler.getBins(corr_time_info_opp_obs_info).array()) if complex_arg is sigmond.ComplexArg.RealPart: data = 0.5 * (data + data_opp) else: data = 0.5 * (data - data_opp) if change_sign: if not forward: data = -data for bin_i, config in enumerate( defs.config_indices[ensemble_name]): if forward: T = tsep + tsrc + defs.source_lists[ensemble_name][ config] % SOURCE_MOD else: T = -tsep + tsrc + defs.source_lists[ensemble_name][ config] % SOURCE_MOD if T >= ensemble_Nt or T < 0: data[bin_i] = -data[bin_i] corr_time_info_herm.resetTimeSeparation(tsep) if not forward: corr_time_info_herm.setForwards() corr_time_info_herm_obs_info = sigmond.MCObsInfo( corr_time_info_herm, complex_arg) correlator_data[corr_time_info_herm_obs_info] = data if not forward: correlator.setForwards() return correlator_data
def get_data(correlator, data_file, data_file_opposite, is_backwards, ensemble_name): if is_backwards: correlator.setBackwards() mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") file_list_infos = list() has_opposite = data_file_opposite is not None if has_opposite: data_files = [data_file, data_file_opposite] else: data_files = [data_file] for d_file in data_files: stub, ext = os.path.splitext(d_file) suffix = int(ext[1:]) file_list_info = sigmond.FileListInfo(stub, suffix, suffix, False) corr_data_xml.append(file_list_info.xml()) file_list_infos.append(file_list_info) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(), set(), ensemble_info) keys = corr_handler.getOrderedKeys(correlator) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() if has_opposite: correlator_opposite = sigmond.CorrelatorInfo(correlator.getSource(), correlator.getSink()) keys = corr_handler.getOrderedKeys(correlator_opposite) tmin_opp = keys[0].getTimeIndex() tmax_opp = keys[-1].getTimeIndex() if tmin != tmin_opp: print("mismatch between tmin on corresponding correlators") exit() if tmax != tmax_opp: print("mismatch between tmax on corresponding correlators") exit() correlator_data = dict() corr_time_info = sigmond.CorrelatorAtTimeInfo(correlator, 0, False, False) if has_opposite: corr_time_info_opp = sigmond.CorrelatorAtTimeInfo( correlator_opposite, 0, False, False) corr_time_info_herm = sigmond.CorrelatorAtTimeInfo(correlator, 0, True, False) for tsep in range(tmin, tmax + 1): for cmp_i, complex_arg in enumerate(COMPLEX_ARGS): if correlator.isSinkSourceSame( ) and complex_arg is sigmond.ComplexArg.ImaginaryPart: continue corr_time_info.resetTimeSeparation(tsep) corr_time_info_obs_info = sigmond.MCObsInfo( corr_time_info, complex_arg) data = np.array( obs_handler.getBins(corr_time_info_obs_info).array()) if has_opposite: corr_time_info_opp.resetTimeSeparation(tsep) corr_time_info_opp_obs_info = sigmond.MCObsInfo( corr_time_info_opp, complex_arg) data_opp = np.array( obs_handler.getBins(corr_time_info_opp_obs_info).array()) data = 0.5 * (data + np.conj(data_opp)) corr_time_info_herm.resetTimeSeparation(tsep) if is_backwards: corr_time_info_herm.setForwards() corr_time_info_herm_obs_info = sigmond.MCObsInfo( corr_time_info_herm, complex_arg) correlator_data[corr_time_info_herm_obs_info] = data if is_backwards: correlator.setForwards() return correlator_data
def convert_dibaryons(ensemble, channel, ops): if channel.flavor is None and ensemble.su3: return if channel.flavor is not None and not ensemble.su3: return if not ops: return data_dir = os.path.join(base_data_dir, f"analysis_{ensemble.dir_name}") data_str = 'c2_dibaryon' if ensemble.su3: data_str += f"/{channel.P}/{channel.irrep}/{channel.flavor}" else: data_str += f"/{channel.strangeness}/{channel.isospin}/{channel.P}/{channel.irrep}" data_handlers = list() raw_datas = list() for replica in ensemble.replica: if ensemble.su3: data_filename = f"{ensemble.dir_name}{replica}_{ensemble.modes}modes.hdf5" else: data_filename = f"{ensemble.dir_name}{replica}_{ensemble.modes}modes_{channel.strangeness}.hdf5" data_file = os.path.join(data_dir, data_filename) f_handler = h5py.File(data_file, 'r') data_handlers.append(f_handler) raw_datas.append(f_handler[data_str]) ensemble_info = sig.MCEnsembleInfo(f"cls_{ensemble.name}", 'ensembles.xml') bins_info = sig.MCBinsInfo(ensemble_info) sampling_info = sig.MCSamplingInfo() xml_obs = sig.XMLHandler("MCObservables", "") obs_get_handler = sig.MCObsGetHandler(xml_obs, bins_info, sampling_info) obs_handler = sig.MCObsHandler(obs_get_handler, False) if ensemble.su3: bin_dir = os.path.join("data", ensemble.name, "dibaryons", channel.P, channel.irrep, channel.flavor) os.makedirs(bin_dir, exist_ok=True) bin_filename = "{}{}_{}modes_{}_{}_F{}.bin".format( ensemble.name, ensemble.replica_str, ensemble.modes, channel.P, channel.irrep, channel.flavor) else: bin_dir = os.path.join("data", ensemble.name, "dibaryons", f"{channel.isospin}_{channel.strangeness}", channel.P, channel.irrep) os.makedirs(bin_dir, exist_ok=True) bin_filename = "{}{}_{}modes_{}_{}_{}_{}.bin".format( ensemble.name, ensemble.replica_str, ensemble.modes, channel.isospin, channel.strangeness, channel.P, channel.irrep) bin_file = os.path.join(bin_dir, bin_filename) obs_keys = set() for opsrc_i, opsrc_str in enumerate(ops): opsnks_enum = enumerate( ops[opsrc_i:], start=opsrc_i) if FORCE_HERM else enumerate(ops) for opsnk_i, opsnk_str in opsnks_enum: for t in range(ensemble.t0, ensemble.t0 + ensemble.ts): bin_datas = list() for raw_data in raw_datas: bin_data = np.zeros(raw_data.shape[0], dtype=np.complex128) for tsrc in range(ensemble.srcs): for par in range(2): if skip_source(ensemble.name, tsrc, par): continue if FORCE_HERM: bin_data += 0.5 * ( raw_data[:, tsrc, par, opsnk_i, opsrc_i, t - ensemble.t0] + np.conj( raw_data[:, tsrc, par, opsrc_i, opsnk_i, t - ensemble.t0])) else: bin_data += raw_data[:, tsrc, par, opsnk_i, opsrc_i, t - ensemble.t0] bin_datas.append(bin_data) opsrc = sig.OperatorInfo(opsrc_str, sig.OpKind.GenIrrep) opsnk = sig.OperatorInfo(opsnk_str, sig.OpKind.GenIrrep) corr = sig.CorrelatorAtTimeInfo(opsnk, opsrc, t, FORCE_HERM, False) corr_re = sig.MCObsInfo(corr, sig.ComplexArg.RealPart) re_bin_data = sig.RVector( sum([[x.real for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_re, re_bin_data) obs_keys.add(corr_re) if not FORCE_HERM or opsrc != opsnk: corr_im = sig.MCObsInfo(corr, sig.ComplexArg.ImaginaryPart) im_bin_data = sig.RVector( sum([[x.imag for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_im, im_bin_data) obs_keys.add(corr_im) xml_out = sig.XMLHandler("output", "") obs_handler.writeBinsToFile(obs_keys, bin_file, xml_out, sig.WriteMode.Protect) obs_handler.clearData() for data_handler in data_handlers: data_handler.close()
def convert_pseudoscalar(ensemble): data_dir = os.path.join(base_data_dir, f"analysis_{ensemble.dir_name}") data_handlers = list() tsrc_list = dict() raw_datas = dict() for ps_name in defs.pseudoscalar_names[ensemble.name]: raw_datas[ps_name] = list() for rep_num, replica in enumerate(ensemble.replica): data_filename = "{}{}_{}modes_pseudoscalar.hdf5".format( ensemble.dir_name, replica, defs.pseudoscalar_modes[ensemble.name]) data_file = os.path.join(data_dir, data_filename) f_handler = h5py.File(data_file, 'r') data_handlers.append(f_handler) for ps_name in defs.pseudoscalar_names[ensemble.name]: raw_datas[ps_name].append(f_handler[ps_name]) if ensemble.name in defs.tsrc_files: tsrc_list[rep_num] = dict() tsrc_file = os.path.join(data_dir, defs.tsrc_files[ensemble.name] + replica) with open(tsrc_file, 'r') as tsrc_file_h: for line in tsrc_file_h: conf, tsrc = line.split() tsrc_list[rep_num][int(conf) - 1] = int(tsrc) ensemble_info = sig.MCEnsembleInfo(f"cls_{ensemble.name}", 'ensembles.xml') bins_info = sig.MCBinsInfo(ensemble_info) sampling_info = sig.MCSamplingInfo() xml_obs = sig.XMLHandler("MCObservables", "") obs_get_handler = sig.MCObsGetHandler(xml_obs, bins_info, sampling_info) obs_handler = sig.MCObsHandler(obs_get_handler, False) bin_dir = os.path.join("data", ensemble.name, "single_particles") os.makedirs(bin_dir, exist_ok=True) bin_filename = "{}{}_{}modes_pseudoscalar.bin".format( ensemble.name, ensemble.replica_str, defs.pseudoscalar_modes[ensemble.name]) bin_file = os.path.join(bin_dir, bin_filename) obs_keys = set() for ps_name in defs.pseudoscalar_names[ensemble.name]: for t in range(ensemble.Nt): bin_datas = list() for rep_num, raw_data in enumerate(raw_datas[ps_name]): bin_data = np.zeros(raw_data.shape[0], dtype=np.complex128) for tsrc in range(ensemble.srcs): if tsrc_list: for config in range(raw_data.shape[0]): t0 = defs.pseudoscalar_sources[ensemble.name][ tsrc] + tsrc_list[rep_num][config] ts_forward = (t0 + t) % ensemble.Nt ts_reverse = (t0 - t) % ensemble.Nt if not ensemble.open: bin_data[config] += raw_data[config, tsrc, ts_forward] elif use_forward_pseudoscalar( ensemble.name, tsrc) and use_backward_pseudoscalar( ensemble.name, tsrc): bin_data[config] += raw_data[config, tsrc, ts_forward] bin_data[config] += raw_data[config, tsrc, ts_reverse] elif use_forward_pseudoscalar(ensemble.name, tsrc): bin_data[config] += raw_data[config, tsrc, ts_forward] elif use_backward_pseudoscalar( ensemble.name, tsrc): bin_data[config] += raw_data[config, tsrc, ts_reverse] else: t0 = defs.pseudoscalar_sources[ensemble.name][tsrc] ts_forward = (t0 + t) % ensemble.Nt ts_reverse = (t0 - t) % ensemble.Nt if not ensemble.open: bin_data += raw_data[:, tsrc, ts_forward] elif use_forward_pseudoscalar( ensemble.name, tsrc) and use_backward_pseudoscalar( ensemble.name, tsrc): bin_data += raw_data[:, tsrc, ts_forward] bin_data += raw_data[:, tsrc, ts_reverse] elif use_forward_pseudoscalar(ensemble.name, tsrc): bin_data += raw_data[:, tsrc, ts_forward] elif use_backward_pseudoscalar(ensemble.name, tsrc): bin_data += raw_data[:, tsrc, ts_reverse] bin_datas.append(bin_data) op_str = defs.pseudoscalar_op_strs[ensemble.name][ps_name] op = sig.OperatorInfo(op_str, sig.OpKind.GenIrrep) corr = sig.CorrelatorAtTimeInfo(op, op, t, FORCE_HERM, False) corr_re = sig.MCObsInfo(corr, sig.ComplexArg.RealPart) re_bin_data = sig.RVector( sum([[x.real for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_re, re_bin_data) obs_keys.add(corr_re) if not FORCE_HERM: corr_im = sig.MCObsInfo(corr, sig.ComplexArg.ImaginaryPart) im_bin_data = sig.RVector( sum([[x.imag for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_im, im_bin_data) obs_keys.add(corr_im) xml_out = sig.XMLHandler("output", "") obs_handler.writeBinsToFile(obs_keys, bin_file, xml_out, sig.WriteMode.Protect) obs_handler.clearData() for data_handler in data_handlers: data_handler.close()
def convert_baryons(ensemble): data_dir = os.path.join(base_data_dir, f"analysis_{ensemble.dir_name}") data_handlers = list() raw_datas = list() for replica in ensemble.replica: data_filename = "{}{}_{}modes_baryon.hdf5".format( ensemble.dir_name, replica, ensemble.modes) data_file = os.path.join(data_dir, data_filename) f_handler = h5py.File(data_file, 'r') data_handlers.append(f_handler) raw_datas.append(f_handler['c2_baryon']) flavors = ['lambda'] num_flavors = 1 if not ensemble.su3: flavors = list( map(lambda x: x.decode('utf-8'), f_handler['baryons'][:])) num_flavors = len(flavors) ensemble_info = sig.MCEnsembleInfo(f"cls_{ensemble.name}", 'ensembles.xml') bins_info = sig.MCBinsInfo(ensemble_info) sampling_info = sig.MCSamplingInfo() xml_obs = sig.XMLHandler("MCObservables", "") obs_get_handler = sig.MCObsGetHandler(xml_obs, bins_info, sampling_info) obs_handler = sig.MCObsHandler(obs_get_handler, False) bin_dir = os.path.join("data", ensemble.name, "single_particles") os.makedirs(bin_dir, exist_ok=True) if ensemble.su3: bin_filename = "{}{}_{}modes_lambda.bin".format( ensemble.name, ensemble.replica_str, ensemble.modes) else: bin_filename = "{}{}_{}modes_baryons.bin".format( ensemble.name, ensemble.replica_str, ensemble.modes) bin_file = os.path.join(bin_dir, bin_filename) obs_keys = set() for psq in range(4): irrep = defs.spin_half_irreps[psq] for flavor in range(num_flavors): flav_name = flavors[flavor] isospin = defs.baryon_isospin[flav_name] strangeness = defs.baryon_strangeness[flav_name] op_str = f"{isospin} S={strangeness} PSQ={psq} {irrep} {flav_name} 0" op = sig.OperatorInfo(op_str, sig.OpKind.GenIrrep) for t in range(ensemble.t0, ensemble.t0 + ensemble.ts): bin_datas = list() for raw_data in raw_datas: bin_data = np.zeros(raw_data.shape[0], dtype=np.complex128) for tsrc in range(ensemble.srcs): for par in range(2): if skip_source(ensemble.name, tsrc, par): continue bin_data += raw_data[:, tsrc, par, psq, flavor, t - ensemble.t0] bin_datas.append(bin_data) corr = sig.CorrelatorAtTimeInfo(op, op, t, FORCE_HERM, False) corr_re = sig.MCObsInfo(corr, sig.ComplexArg.RealPart) re_bin_data = sig.RVector( sum([[x.real for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_re, re_bin_data) obs_keys.add(corr_re) if not FORCE_HERM: corr_im = sig.MCObsInfo(corr, sig.ComplexArg.ImaginaryPart) im_bin_data = sig.RVector( sum([[x.imag for x in bins] for bins in bin_datas], [])) obs_handler.putBins(corr_im, im_bin_data) obs_keys.add(corr_im) xml_out = sig.XMLHandler("output", "") obs_handler.writeBinsToFile(obs_keys, bin_file, xml_out, sig.WriteMode.Protect) obs_handler.clearData() for data_handler in data_handlers: data_handler.close()
def find_sh_data(ensemble_name, search_dir): ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') # search for data files print(f"Searching for correlators and time separations in {search_dir}") file_list_infos = dict() for root, dirs, files in os.walk(search_dir, topdown=True): for filename in files: base, ext = os.path.splitext(filename) full_base = os.path.join(root, base) try: suffix = int(ext[1:]) except ValueError: continue if full_base in file_list_infos: if suffix < file_list_infos[full_base][0]: file_list_infos[full_base][0] = suffix elif suffix > file_list_infos[full_base][1]: file_list_infos[full_base][1] = suffix else: file_list_infos[full_base] = [suffix, suffix] file_list_infos = [sigmond.FileListInfo(stub, suffix[0], suffix[1], False) for stub, suffix in file_list_infos.items()] # create sigmond handlers mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") for file_list_info in file_list_infos: corr_data_xml.append(file_list_info.xml()) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(), set(), ensemble_info) corrs = corr_handler.getCorrelatorSet() # search through found data operators = dict() max_tsep = 0 time_seps = dict() for corr in corrs: if not corr.isSinkSourceSame(): print("aren't sh ops diagonal?") exit() op_src = corr.getSource() if op_src.op_str() in missing_sh_ops.missing_operators: continue keys = corr_handler.getOrderedKeys(corr) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() if tmax > max_tsep: max_tsep = tmax time_seps[corr] = (tmin, tmax) op_src = corr.getSource() op_src_bl = op_src.getBasicLapH() P = (op_src_bl.getXMomentum(), op_src_bl.getYMomentum(), op_src_bl.getZMomentum()) Psq = P[0]**2 + P[1]**2 + P[2]**2 irrep = op_src_bl.getLGIrrep() irrep_row = op_src_bl.getLGIrrepRow() flavor = op_src_bl.getFlavor() averaged_channel = defs.AveragedChannel(Psq, irrep) equivalent_frame = defs.EquivalentFrame(P, irrep_row) if flavor not in operators: operators[flavor] = dict() if averaged_channel not in operators[flavor]: operators[flavor][averaged_channel] = dict() if equivalent_frame in operators[flavor][averaged_channel]: print("aren't sh ops 1x1?") exit() operators[flavor][averaged_channel][equivalent_frame] = op_src print("Done searching for all correlators and time separations") print("Now finding data") data = dict() for flavor, averaged_channels in operators.items(): print(f"Working on {flavor}") data[flavor] = dict() for averaged_channel, channel_ops in averaged_channels.items(): print(f"\tWorking on {averaged_channel}") data[flavor][averaged_channel] = dict() for equivalent_frame, operator in channel_ops.items(): print(f"\t\tWorking on {equivalent_frame}") bin_data = np.zeros((len(defs.configs[ensemble_name]), max_tsep+1), dtype=np.complex128) corr_info = sigmond.CorrelatorInfo(operator, operator) trange = time_seps[corr_info] corr_time_info = sigmond.CorrelatorAtTimeInfo(corr_info, 0, False, False) for tsep in range(trange[0], trange[1]+1): corr_time_info.resetTimeSeparation(tsep) if FORCE_HERM: obs_info_re = sigmond.MCObsInfo(corr_time_info, sigmond.ComplexArg.RealPart) bin_data[:,tsep] = np.array([obs_handler.getBins(obs_info_re).array()]) else: obs_info_re = sigmond.MCObsInfo(corr_time_info, sigmond.ComplexArg.RealPart) obs_info_im = sigmond.MCObsInfo(corr_time_info, sigmond.ComplexArg.ImaginaryPart) bin_data[:,tsep] = np.array([(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_re).array(), obs_handler.getBins(obs_info_im).array())]) data[flavor][averaged_channel][equivalent_frame] = bin_data obs_handler.clearData() return data
def find_data(ensemble_name, search_dir): ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') # search for data files print(f"Searching for correlators and time separations in {search_dir}") file_list_infos = dict() for root, dirs, files in os.walk(search_dir, topdown=True): for filename in files: base, ext = os.path.splitext(filename) full_base = os.path.join(root, base) try: suffix = int(ext[1:]) except ValueError: continue if full_base in file_list_infos: if suffix < file_list_infos[full_base][0]: file_list_infos[full_base][0] = suffix elif suffix > file_list_infos[full_base][1]: file_list_infos[full_base][1] = suffix else: file_list_infos[full_base] = [suffix, suffix] file_list_infos = [sigmond.FileListInfo(stub, suffix[0], suffix[1], False) for stub, suffix in file_list_infos.items()] # create sigmond handlers mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") for file_list_info in file_list_infos: corr_data_xml.append(file_list_info.xml()) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(), set(), ensemble_info) corrs = corr_handler.getCorrelatorSet() # search through found data operators = dict() max_tsep = 0 time_seps = dict() for corr in corrs: op_snk = corr.getSink() op_src = corr.getSource() if EXCLUDE_OPERATORS and (op_snk.op_str() in excluded_ops.excluded_operators or op_src.op_str() in excluded_ops.excluded_operators): continue keys = corr_handler.getOrderedKeys(corr) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() if tmax > max_tsep: max_tsep = tmax time_seps[corr] = (tmin, tmax) op_snk_bl = op_snk.getBasicLapH() op_src_bl = op_src.getBasicLapH() P = (op_src_bl.getXMomentum(), op_src_bl.getYMomentum(), op_src_bl.getZMomentum()) Psq = P[0]**2 + P[1]**2 + P[2]**2 irrep = op_src_bl.getLGIrrep() irrep_row = op_src_bl.getLGIrrepRow() averaged_channel = defs.AveragedChannel(Psq, irrep) equivalent_frame = defs.EquivalentFrame(P, irrep_row) if averaged_channel not in operators: operators[averaged_channel] = dict() if equivalent_frame not in operators[averaged_channel]: operators[averaged_channel][equivalent_frame] = SortedSet() operators[averaged_channel][equivalent_frame].add(op_snk) operators[averaged_channel][equivalent_frame].add(op_src) print("Done searching for all correlators and time separations") print("Now finding data") data = dict() for averaged_channel, channel_ops in operators.items(): print(f"Working on {averaged_channel}") data[averaged_channel] = dict() for equivalent_frame, operators in channel_ops.items(): print(f"\tWorking on {equivalent_frame}") operator_list = list(operators) bin_data = np.zeros((len(defs.configs[ensemble_name]), max_tsep+1, len(operator_list), len(operator_list)), dtype=np.complex128) for op_snk_i, op_snk in enumerate(operator_list): snk_op_phase = defs.phases.get(op_snk.op_str(), 1) for op_src_i, op_src in enumerate(operator_list[op_snk_i:], start=op_snk_i): src_op_phase = defs.phases.get(op_src.op_str(), 1) phase = snk_op_phase*np.conj(src_op_phase) corr_info = sigmond.CorrelatorInfo(op_snk, op_src) corr_info_opposite = sigmond.CorrelatorInfo(op_src, op_snk) if corr_info_opposite not in time_seps: trange = time_seps[corr_info] elif corr_info not in time_seps: trange = time_seps[corr_info_opposite] else: trange1 = time_seps[corr_info] trange2 = time_seps[corr_info_opposite] trange = (max(trange1[0], trange2[0]), min(trange1[1], trange2[1])) corr_time_info = sigmond.CorrelatorAtTimeInfo(corr_info, 0, False, False) corr_time_info_opposite = sigmond.CorrelatorAtTimeInfo(corr_info_opposite, 0, False, False) for tsep in range(trange[0], trange[1]+1): corr_time_info.resetTimeSeparation(tsep) corr_time_info_opposite.resetTimeSeparation(tsep) obs_info_re = sigmond.MCObsInfo(corr_time_info, sigmond.ComplexArg.RealPart) obs_info_im = sigmond.MCObsInfo(corr_time_info, sigmond.ComplexArg.ImaginaryPart) obs_info_opposite_re = sigmond.MCObsInfo(corr_time_info_opposite, sigmond.ComplexArg.RealPart) obs_info_opposite_im = sigmond.MCObsInfo(corr_time_info_opposite, sigmond.ComplexArg.ImaginaryPart) if corr_info_opposite not in time_seps: the_data = np.array([phase*(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_re).array(), obs_handler.getBins(obs_info_im).array())]) bin_data[:,tsep,op_snk_i,op_src_i] = the_data bin_data[:,tsep,op_src_i,op_snk_i] = np.conj(the_data) elif corr_info not in time_seps: the_data = np.array([np.conj(phase)*(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_opposite_re).array(), obs_handler.getBins(obs_info_opposite_im).array())]) bin_data[:,tsep,op_snk_i,op_src_i] = np.conj(the_data) bin_data[:,tsep,op_src_i,op_snk_i] = the_data elif corr_info == corr_info_opposite: if FORCE_HERM: the_data = np.array(obs_handler.getBins(obs_info_re).array()) else: the_data = np.array([(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_re).array(), obs_handler.getBins(obs_info_im).array())]) bin_data[:,tsep,op_snk_i,op_src_i] = the_data else: the_data = np.array([phase*(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_re).array(), obs_handler.getBins(obs_info_im).array())]) the_data_opposite = np.array([np.conj(phase)*(re + im*1j) for re, im in zip(obs_handler.getBins(obs_info_opposite_re).array(), obs_handler.getBins(obs_info_opposite_im).array())]) if FORCE_HERM: bin_data[:,tsep,op_snk_i,op_src_i] = 0.5*(the_data + np.conj(the_data_opposite)) bin_data[:,tsep,op_src_i,op_snk_i] = 0.5*(np.conj(the_data) + the_data_opposite) else: bin_data[:,tsep,op_snk_i,op_src_i] = the_data bin_data[:,tsep,op_src_i,op_snk_i] = the_data_opposite data[averaged_channel][equivalent_frame] = (operator_list, bin_data) obs_handler.clearData() return data
def get_data(correlators, ensemble_name, ensemble_Nt, tsrc): mcobs_xml = ET.Element("MCObservables") corr_data_xml = ET.SubElement(mcobs_xml, "BLCorrelatorData") file_list_infos = list() for data_file in correlators['data_files']: stub, ext = os.path.splitext(data_file) suffix = int(ext[1:]) file_list_info = sigmond.FileListInfo(stub, suffix, suffix, False) corr_data_xml.append(file_list_info.xml()) file_list_infos.append(file_list_info) mcobs_xml_handler = sigmond.XMLHandler() mcobs_xml_handler.set_from_string(ET.tostring(mcobs_xml)) sampling_info = sigmond.MCSamplingInfo() ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml') bins_info = sigmond.MCBinsInfo(ensemble_info) bins_info.addOmissions(defs.omissions[ensemble_name]) obs_get_handler = sigmond.MCObsGetHandler(mcobs_xml_handler, bins_info, sampling_info) obs_handler = sigmond.MCObsHandler(obs_get_handler, False) corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(), set(), ensemble_info) operators = set() tmin = None tmax = None for corr in correlators['correlators']: src_op_str = corr.getSource() snk_op_str = corr.getSink() operators.add(src_op_str) operators.add(snk_op_str) if tmin is None: keys = corr_handler.getOrderedKeys(corr) tmin = keys[0].getTimeIndex() tmax = keys[-1].getTimeIndex() operators = sorted(list([operator_info.operator.Operator(op) for op in operators])) operators = [op.operator_info for op in operators] single_correlator = True if len(correlators['correlators']) == 1 else False if single_correlator: corr_data = np.zeros((bins_info.getNumberOfBins(), tmax+1), dtype=np.complex128) else: corr_data = np.zeros((bins_info.getNumberOfBins(), len(operators), len(operators), tmax+1), dtype=np.complex128) for snk_i, snk_op in enumerate(operators): for src_i, src_op in enumerate(operators): correlator = sigmond.CorrelatorInfo(snk_op, src_op) correlator_opposite = sigmond.CorrelatorInfo(src_op, snk_op) for tsep in range(tmin, tmax+1): correlator_time = sigmond.CorrelatorAtTimeInfo(correlator, tsep, False, False) correlator_time_re_obsinfo = sigmond.MCObsInfo(correlator_time, sigmond.ComplexArg.RealPart) correlator_time_im_obsinfo = sigmond.MCObsInfo(correlator_time, sigmond.ComplexArg.ImaginaryPart) has_re = obs_handler.queryBins(correlator_time_re_obsinfo) has_im = obs_handler.queryBins(correlator_time_im_obsinfo) if has_re and has_im: data = np.array(obs_handler.getBins(correlator_time_re_obsinfo).array()) + 1j*np.array(obs_handler.getBins(correlator_time_im_obsinfo).array()) elif has_re: data = np.array(obs_handler.getBins(correlator_time_re_obsinfo).array()) elif has_im: data = 1j*np.array(obs_handler.getBins(correlator_time_im_obsinfo).array()) else: continue if single_correlator: corr_data[:,tsep] = data else: corr_data[:,snk_i,src_i,tsep] = data operators = [op.op_str() for op in operators] return corr_data, operators