def getOperatorSetSmallestTRange(self, max_time, operator_set):
        tmax = max_time
        tmin = 0
        for two_ops in itertools.combinations_with_replacement(
                operator_set.operators, 2):
            corr = sigmond.CorrelatorInfo(two_ops[0].operator_info,
                                          two_ops[1].operator_info)
            corr_rev = sigmond.CorrelatorInfo(two_ops[1].operator_info,
                                              two_ops[0].operator_info)

            corr_info = self.getCorrInfo(corr)
            corr_info_rev = self.getCorrInfo(corr_rev)

            if corr_info is not None and corr_info_rev is not None:
                tmin_try = min(corr_info.tmin, corr_info_rev.tmin)
                tmax_try = max(corr_info.tmax, corr_info_rev.tmax)

            elif corr_info is not None:
                tmin_try = corr_info.tmin
                tmax_try = corr_info.tmax

            elif corr_info_rev is not None:
                tmin_try = corr_info_rev.tmin
                tmax_try = corr_info_rev.tmax

            else:
                return (-1, -1)

            if tmin_try > tmin:
                tmin = tmin_try
            if tmax_try < tmax:
                tmax = tmax_try

        return (tmin, tmax)
Exemple #2
0
    def addPlotsToPDF(self, doc, data_files, operators, name):
        obs_handler, _ = util.get_obs_handlers(data_files, self.bins_info,
                                               self.sampling_info)

        corr_plotsdir = self.correlator_plotdir(name)
        energy_plotsdir = self.energy_plotdir(name)
        util.dirGrace2pdf(corr_plotsdir)
        util.dirGrace2pdf(energy_plotsdir)

        off_diag_corrs = list()

        for op_src in operators:
            for op_snk in operators:
                if op_src == op_snk:
                    continue

                corr = sigmond.CorrelatorInfo(op_snk.operator_info,
                                              op_src.operator_info)
                if not self.data_handler.hasCorrelator(corr):
                    continue

                off_diag_corrs.append(corr)

        with doc.create(pylatex.Subsection("Diagonal Correlators")):
            for operator in operators:
                corr = sigmond.CorrelatorInfo(operator.operator_info,
                                              operator.operator_info)
                if self.data_handler.hasCorrelator(corr):
                    with doc.create(pylatex.Subsubsection(str(operator))):
                        util.add_correlator(doc, self, corr, name, obs_handler)

        if self.off_diagonal and off_diag_corrs:
            with doc.create(pylatex.Subsection("Off-Diagonal Correlators")):
                for corr in off_diag_corrs:
                    with doc.create(pylatex.Subsubsection(corr.corr_str())):
                        util.add_correlator(doc, self, corr, name, obs_handler)
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 finalize(self):
    doc = util.create_doc(f"Rotated Correlators and Effective Energies: {self.task_name} - {self.ensemble_name}")

    for operator_basis in self.operator_bases:
      logfile = self.logfile(repr(operator_basis))
      rotation_log = sigmond_info.sigmond_log.RotationLog(logfile)
      if rotation_log.failed:
        logging.warning(f"Rotation {operator_basis.name} failed")
        continue

      corr_plotsdir = self.correlator_plotdir(operator_basis)
      energy_plotsdir = self.energy_plotdir(operator_basis)
      util.dirGrace2pdf(corr_plotsdir)
      util.dirGrace2pdf(energy_plotsdir)

      data_files = self.data_handler.getRotatedDataFiles(operator_basis)
      obs_handler, _ = util.get_obs_handlers(data_files, self.bins_info, self.sampling_info)

      with doc.create(pylatex.Section(f"{operator_basis.channel!s} - {operator_basis.name}")):
        with doc.create(pylatex.Subsection("Rotation Info")):
          with doc.create(pylatex.Center()) as centered:
            with centered.create(
                pylatex.LongTabu("X[c]|X[c]|X[c]|X[c]|X[c]|X[3,c]|X[3,c]|X[3,c]|X[3,c]|X[3,c]",
                                 to=r"\linewidth")) as param_table:
              header_row = [
                  pylatex.NoEscape(r"$N_{op}$"),
                  pylatex.NoEscape(r"$N_{\text{d}}$"),
                  pylatex.NoEscape(r"$\tau_N$"),
                  pylatex.NoEscape(r"$\tau_0$"),
                  pylatex.NoEscape(r"$\tau_D$"),
                  pylatex.NoEscape(r"$\xi_{cn}$ (max)"),
                  pylatex.NoEscape(r"$\xi_{cn}^C$ (input)"),
                  pylatex.NoEscape(r"$\xi_{cn}^C$ (retain)"),
                  pylatex.NoEscape(r"$\xi_{cn}^G$ (input)"),
                  pylatex.NoEscape(r"$\xi_{cn}^G$ (retain)"),
              ]
              param_table.add_row(header_row, mapper=[pylatex.utils.bold])
              param_table.add_hline()
              param_table.end_table_header()
              value_row = [
                  operator_basis.num_operators,
                  operator_basis.num_operators - rotation_log.number_levels,
                  operator_basis.pivot_info.norm_time,
                  operator_basis.pivot_info.metric_time,
                  operator_basis.pivot_info.diagonalize_time,
                  operator_basis.pivot_info.max_condition_number,
                  rotation_log.metric_condition(False),
                  rotation_log.metric_condition(True),
                  rotation_log.matrix_condition(False),
                  rotation_log.matrix_condition(True),
              ]
              param_table.add_row(value_row)

          doc.append(pylatex.NoEscape(r"\textbf{Metric Null Space Check:} " + \
                                      rotation_log.metric_null_space_message))

          with doc.create(pylatex.Subsubsection("Input Operators")):
            with doc.create(pylatex.Center()) as centered:
              with centered.create(
                  pylatex.LongTabu("X[2,c] X[c] X[c]", row_height=1.5)) as op_table:
                header_row = [
                    "Operator",
                    pylatex.NoEscape(r"$\delta C(\tau_0)$"),
                    pylatex.NoEscape(r"$\delta C(\tau_D)$")
                ]
                op_table.add_row(header_row, mapper=[pylatex.utils.bold])
                op_table.add_hline()
                op_table.end_table_header()
                for op, errors in rotation_log.diagonal_correlator_errors.items():
                  row = [
                      op,
                      errors.metric,
                      errors.matrix,
                  ]
                  op_table.add_row
                  op_table.add_row(row)

          with doc.create(pylatex.Subsubsection("Diagonal Deviations From Zero")):
            with doc.create(pylatex.Center()) as centered:
              with centered.create(
                  pylatex.LongTabu("X[c] X[4,c] X[3,c] X[3,c] X[3,c] X[3,c] X[2,c]")) as deviation_table:
                header_row = [
                    "time",
                    pylatex.NoEscape(r"$\delta 0_{max}$"),
                    pylatex.NoEscape(r"$\% > 1 \sigma$"),
                    pylatex.NoEscape(r"$\% > 2 \sigma$"),
                    pylatex.NoEscape(r"$\% > 3 \sigma$"),
                    pylatex.NoEscape(r"$\% > 4 \sigma$"),
                    "Status",
                ]
                deviation_table.add_row(header_row, mapper=[pylatex.utils.bold])
                deviation_table.add_hline()
                deviation_table.end_table_header()
                for time, deviation in rotation_log.deviations_from_zero.items():
                  row = [
                      time,
                      deviation.max,
                      deviation.one,
                      deviation.two,
                      deviation.three,
                      deviation.four,
                      deviation.status,
                  ]
                  deviation_table.add_row(row)

        doc.append(pylatex.NoEscape(r"\newpage"))

        operators = self.data_handler.getRotatedOperators(operator_basis)
        with doc.create(pylatex.Subsection("Correlators/Effective Energies")):
          for operator in operators:
            with doc.create(pylatex.Subsubsection(str(operator))):
              corr = sigmond.CorrelatorInfo(operator.operator_info, operator.operator_info)
              util.add_correlator(doc, self, corr, operator_basis, obs_handler)

    results_dir = self.results_dir
    os.makedirs(results_dir, exist_ok=True)
    filename = os.path.join(results_dir, self.task_name)
    util.compile_pdf(doc, filename, self.latex_compiler)
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
Exemple #10
0
    def insertSigmondPlotTasks(self, sigmond_input, name, operators):
        for op_src in operators:
            src_channel = op_src.channel
            subtractvev = self.subtractvev and src_channel.vev

            for op_snk in operators:
                snk_channel = op_snk.channel

                if src_channel != snk_channel:
                    continue

                corr = sigmond.CorrelatorInfo(op_snk.operator_info,
                                              op_src.operator_info)
                '''
        The plot task will simply fail if the data isn't found
        if not self.data_handler.hasCorrelator(corr):
          continue
        '''

                if corr.isSinkSourceSame():
                    corr_plotfile = self.correlator_plotfile(corr, name)
                    energy_plotfile = self.energy_plotfile(op_src, name)

                    sigmond_input.doCorrelatorPlot(
                        corr,
                        sigmond.ComplexArg.RealPart,
                        corr_plotfile,
                        hermitian=self.hermitian,
                        subtractvev=subtractvev,
                        corrname=self.plot_info.corrname,
                        symbol_color=self.plot_info.symbol_color,
                        symbol_type=self.plot_info.symbol_type,
                        rescale=self.plot_info.rescale)
                    sigmond_input.doEnergyPlot(
                        corr,
                        sigmond.ComplexArg.RealPart,
                        energy_plotfile,
                        eff_energy_type=self.plot_info.eff_energy_type,
                        timestep=self.plot_info.timestep,
                        hermitian=self.hermitian,
                        subtractvev=subtractvev,
                        corrname=self.plot_info.corrname,
                        symbol_color=self.plot_info.symbol_color,
                        symbol_type=self.plot_info.symbol_type)

                elif self.off_diagonal:
                    re_corr_plotfile = self.correlator_plotfile(
                        corr, name, complex_arg=sigmond.ComplexArg.RealPart)
                    sigmond_input.doCorrelatorPlot(
                        corr,
                        sigmond.ComplexArg.RealPart,
                        re_corr_plotfile,
                        hermitian=self.hermitian,
                        subtractvev=subtractvev,
                        corrname=self.plot_info.corrname,
                        symbol_color=self.plot_info.symbol_color,
                        symbol_type=self.plot_info.symbol_type,
                        rescale=self.plot_info.rescale)

                    im_corr_plotfile = self.correlator_plotfile(
                        corr,
                        name,
                        complex_arg=sigmond.ComplexArg.ImaginaryPart)
                    sigmond_input.doCorrelatorPlot(
                        corr,
                        sigmond.ComplexArg.ImaginaryPart,
                        im_corr_plotfile,
                        hermitian=self.hermitian,
                        subtractvev=subtractvev,
                        corrname=self.plot_info.corrname,
                        symbol_color=self.plot_info.symbol_color,
                        symbol_type=self.plot_info.symbol_type,
                        rescale=self.plot_info.rescale)