def get_corr_files(ensemble_name, search_dir):
  file_list_infos = dict()
  for root, dirs, files in os.walk(search_dir, topdown=True):
    for filename in files:
      full_filename = os.path.join(root, filename)
      try:
        file_type = sigmond.getFileID(full_filename)
      except ValueError:
        continue

      if file_type != sigmond.FileType.Correlator:
        continue


      base, ext = os.path.splitext(full_filename)

      suffix = int(ext[1:])

      if base in file_list_infos:
        if suffix < file_list_infos[base][0]:
          file_list_infos[base][0] = suffix
        elif suffix > file_list_infos[base][1]:
          file_list_infos[base][1] = suffix
      else:
        file_list_infos[base] = [suffix, suffix]

  file_list_infos = [sigmond.FileListInfo(stub, suffix[0], suffix[1], False)
                     for stub, suffix in file_list_infos.items()]

  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))
  ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.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)

  corr_files = dict()
  for corr in corr_handler.getCorrelatorSet():
    channel = get_channel(corr)
    if channel not in corr_files:
      corr_files[channel] = dict()
      corr_files[channel]['data_files'] = list()
      corr_files[channel]['correlators'] = list()

    corr_files[channel]['data_files'].append(corr_handler.getFileName(corr))
    corr_files[channel]['correlators'].append(corr)

  return corr_files
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
Exemple #3
0
def get_corr_files(ensemble_name, search_dir):
    print("finding files...", end='')
    file_list_infos = dict()
    for root, dirs, files in os.walk(search_dir, topdown=True):
        for filename in files:
            full_filename = os.path.join(root, filename)
            try:
                file_type = sigmond.getFileID(full_filename)
            except ValueError:
                continue

            if file_type != sigmond.FileType.Correlator:
                continue

            base, ext = os.path.splitext(full_filename)

            suffix = int(ext[1:])

            if base in file_list_infos:
                if suffix < file_list_infos[base][0]:
                    file_list_infos[base][0] = suffix
                elif suffix > file_list_infos[base][1]:
                    file_list_infos[base][1] = suffix
            else:
                file_list_infos[base] = [suffix, suffix]

    print("done")

    file_list_infos = [
        sigmond.FileListInfo(stub, suffix[0], suffix[1], False)
        for stub, suffix in file_list_infos.items()
    ]

    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))
    ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.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)

    print("searching through correlators...", end='')
    corr_handler = sigmond.BLCorrelatorDataHandler(file_list_infos, set(),
                                                   set(), ensemble_info)

    corr_files = dict()
    for corr in corr_handler.getCorrelatorSet():
        corr_file_name = corr_handler.getFileName(corr)
        if corr.isBackwards():
            corr.setForwards()

        corr_opposite = sigmond.CorrelatorInfo(corr.getSource(),
                                               corr.getSink())
        if corr_opposite in corr_files:
            corr_files[corr_opposite][1] = corr_file_name
        else:
            corr_files[corr] = (corr_file_name, None)

    print("done")

    return corr_files
Exemple #4
0
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
Exemple #6
0
def find_data(ensemble_name, search_dir):
  ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml')

  # search for data files
  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)

      suffix = int(ext[1:])

      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:
    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 = corr.getSink()
    op_src = corr.getSource()
    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)

  return operators
Exemple #7
0
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
Exemple #8
0
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