Exemplo n.º 1
0
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def find_data(ensemble_name, search_dir):
    ensemble_info = sigmond.MCEnsembleInfo(ensemble_name, 'ensembles.xml')

    # search for data files
    bin_files = set()
    smp_files = set()
    print(f"Searching for correlators and time separations in {search_dir}")
    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.Bins:
                bin_files.add(full_filename)
            elif file_type == sigmond.FileType.Samplings:
                smp_files.add(full_filename)
            else:
                continue

    if not BINS and bin_files:
        print("ignoring bin files found")
    elif BINS and smp_files:
        print("ignoring smp files found")

    # create sigmond handlers
    mcobs_xml = ET.Element("MCObservables")
    if BINS:
        bins_data_xml = ET.SubElement(mcobs_xml, "BinData")
        for bin_file in bin_files:
            ET.SubElement(bins_data_xml, "FileName").text = bin_file
    else:
        smp_data_xml = ET.SubElement(mcobs_xml, "SamplingData")
        for smp_file in smp_files:
            ET.SubElement(smp_data_xml, "FileName").text = smp_file

    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)

    if BINS:
        data_handler = sigmond.BinsGetHandler(bins_info, bin_files)
        data_size = bins_info.getNumberOfBins()
    else:
        data_handler = sigmond.SamplingsGetHandler(bins_info, sampling_info,
                                                   smp_files)
        data_size = sampling_info.getNumberOfReSamplings(bins_info) + 1

    obs_infos = data_handler.getKeys()

    data_dict = dict()
    max_level = dict()
    max_time = dict()
    data_size

    for obs_info in obs_infos:
        if obs_info.isImaginaryPart():
            continue
        operator = obs_info.getCorrelatorSourceInfo().getGenIrrep()
        channel = get_channel(operator)
        if channel not in data_dict:
            data_dict[channel] = dict()
        if channel not in max_level:
            max_level[channel] = 0
        if channel not in max_time:
            max_time[channel] = 0

        level = operator.getIDIndex()
        if level not in data_dict[channel]:
            data_dict[channel][level] = dict()

        max_level[channel] = max(max_level[channel], level)

        time = obs_info.getCorrelatorTimeIndex()
        #print(f"{channel!r} - {level} - {time}")
        if time in data_dict[channel][level]:
            print("another problem")
            exit()
        max_time[channel] = max(max_time[channel], time)

        if BINS:
            data = obs_handler.getBins(obs_info).array()
        else:
            data = obs_handler.getFullAndSamplingValues(
                obs_info, sampling_info.getSamplingMode()).array()

        data_dict[channel][level][time] = data

    final_data_dict = dict()
    for channel, levels in data_dict.items():
        data_arr = np.zeros(
            (data_size, max_level[channel] + 1, max_time[channel] + 1),
            dtype=np.float64)
        for level, times in levels.items():
            for time, data in times.items():
                data_arr[:, level, time] = data

        final_data_dict[channel] = data_arr

    return final_data_dict