Пример #1
0
    def initialize(self, operator_fits, **extra_options):
        """ initializes the needed objects to perform fits to correlators
        with sigmond

    Args:
      operator_fits ({OperatorSet: {Operator: {Fits: [FitInfo]}}}): 
          Specifies all the fits to be done.
      **minimizer_info (MinimizerInfo): Speicifies the 
          minimizer to use and the info to pass to the minimizer
      **fit_plots (bool): whether fit plots should be made
      **fit_plot_info (FitPlotInfo): Contains information for how to make
          the fit plots.
      **tmin_plots (bool): whether tmin plots should be made
      **tmin_plot_info (TMinPlotInfo): Contains information for how to make
          the tmin plots.
      **scattering_particles ({ScatteringParticle: Operator}): A dict
          of all the scattering particles used for ratio fits.
      **reference_fit_info (FitInfo): The fit to be used as a
          reference energy.
    """
        self.operator_fits = operator_fits
        self.minimizer_info = extra_options.pop('minimizer_info',
                                                sigmond.MinimizerInfo())
        self.fit_plots = extra_options.pop('fit_plots', True)
        self.fit_plot_info = extra_options.pop(
            'fit_plot_info', sigmond_info.sigmond_info.FitPlotInfo())
        self.tmin_plots = extra_options.pop('tmin_plots', True)
        self.tmin_plot_info = extra_options.pop(
            'tmin_plot_info', sigmond_info.sigmond_info.TMinPlotInfo())
        self.scattering_particle = extra_options.pop('scattering_particles',
                                                     dict())
        self.reference_fit_info = extra_options.pop('reference_fit_info', None)

        util.check_extra_keys(extra_options, 'FitCorrelators.initialize')
Пример #2
0
  def initialize(self, operator_bases, **extra_options):
    """sets the needed parameters for the rotate correlators task

    Args:
      operator_bases ([RotatedOperatorSet]): A list of rotated
          operator sets.
      **rotate_mode (sigmond_info.RotateMode): rotate mode to use,
          either bins, samplings, samplings_all, samplings_unsubt
      **show_transformation (bool): whether or not the transformation
          used for the rotation should be shown
      **negative_eigenvalue_alarm (float): see sigmond docs
      **subtractvev (bool): whether operators with non-zero VEVs
          should have the VEV subtracted
      **plot_info (PlotInfo): info about the plot
    """
    self.hermitian = True
    self.operator_bases = operator_bases

    self.rotate_mode = extra_options.pop('rotate_mode', sigmond_info.sigmond_info.RotateMode.samplings_all)

    self.show_transformation = extra_options.pop('show_transformation', True)

    self.neg_eig_alarm = extra_options.pop('negative_eigenvalue_alarm', -0.01)
    self.subtractvev = extra_options.pop('subtractvev', True)

    self.plot_info = extra_options.pop('plot_info', sigmond_info.sigmond_info.PlotInfo())

    util.check_extra_keys(extra_options, self.task_name)
Пример #3
0
def getMinimizerInfo(options):
  if (minimizer_info_conf := options.pop('minimizer_info', False)):
    minimizer = minimizer_info_conf.pop("minimizer", "lmder")[0].upper()
    parameter_rel_tol = float(minimizer_info_conf.pop("parameter_rel_tol", 1e-6))
    chisquare_rel_tol = float(minimizer_info_conf.pop("chisquare_rel_tol", 1e-4))
    max_iterations = minimizer_info_conf.pop("max_iterations", 1024)
    verbosity = minimizer_info_conf.pop("verbosity", "low")[0].upper()

    util.check_extra_keys(minimizer_info_conf, "minimizer_info")

    minimizer_info = sigmond.MinimizerInfo(minimizer, parameter_rel_tol, chisquare_rel_tol, max_iterations, verbosity)
Пример #4
0
def _get_file_list_infos(conf_infos):
    file_list_infos = list()
    for file_list_conf in conf_infos:
        try:
            file_stub = file_list_conf.pop('file_stub')
            min_suffix = file_list_conf.pop('min_suffix')
            max_suffix = file_list_conf.pop('max_suffix')
            overwrite = file_list_conf.pop('overwrite', False)
        except KeyError as err:
            logging.error(f"Missing required key in file list info {err}")

        util.check_extra_keys(file_list_conf, 'file_list_info')
        file_list_info = sigmond.FileListInfo(file_stub, min_suffix,
                                              max_suffix, overwrite)
        file_list_infos.append(file_list_info)

    return file_list_infos
Пример #5
0
    def initialize(self, scattering_particles, **options):
        """sets the needed paramters for the view data task

    Args:
      scattering_particles ({ScatteringParticle: FitInfo}): A dictionary
          of the scattering particles to their fit infos.
      **minimizer_info (sigmondbind.MinimizerInfo): Speicifies the 
          minimizer to use and the info to pass to the minimizer
      **anisotropy_plot_info (AnisotropyPlotInfo): Contains information for
        how to make the plots.
    """

        self.scattering_particles = scattering_particles
        self.minimizer_info = options.pop('minimizer_info',
                                          sigmond.MinimizerInfo())
        self.anisotropy_plot_info = options.pop(
            'anisotropy_plot_info',
            sigmond_info.sigmond_info.AnisotropyPlotInfo())

        util.check_extra_keys(options, self.task_name)
Пример #6
0
    def initialize(self, **options):
        """sets the needed paramters for the view data task

    Args:
      **channels (SortedSet(Channel)): The set of channels to print
      **operator_sets ([NamedOperatorSet]): A list of named operator sets
          to print
      **excluded_operators ({Operator}): A set of operators to not consider
      **auto_add (bool): Specifies whether channels should automatically
          be added.
      **off_diagonal (bool): specifies whether the off diagonal
          correlators should be printed
      **hermitian (bool): specifies whether the Hermitian tag
          should be used
      **subtractvev (bool): specifies whether operators with non-zero VEV
          should have the VEV subtracted
      **plot_info (PlotInfo): info about the plot
      **write_operators (bool): determines whether the operators
          should be written to file
      **split_pdfs (bool): specifies if PDFs should be split by channel,
          in which case it will group by irrep and P^2
    """

        self.channels = options.pop('channels', SortedSet())
        self.operator_sets = options.pop('operator_sets', dict())
        self.excluded_operators = options.pop('excluded_operators', set())

        self.off_diagonal = options.pop('off_diagonal', False)
        self.hermitian = options.pop('hermitian', True)
        self.subtractvev = options.pop('subtractvev', True)
        self.write_operators = options.pop('write_operators', False)
        self.split_pdfs = options.pop('split_pdfs', False)

        self.plot_info = options.pop('plot_info',
                                     sigmond_info.sigmond_info.PlotInfo())

        if options.pop('auto_add', False):
            self.channels |= self.data_handler.raw_channels

        util.check_extra_keys(options, self.task_name)
Пример #7
0
    def readConfig(self, **task_options):
        """readConfig function for FitCorrelators

    YAML:
      subtractvev: true   # optional

      # optional
      minimizer_info:
        minimizer: lmder
        parameter_rel_tol: 1e-6
        chisquare_rel_tol: 1e-4
        max_iterations: 1024
        verbosity: high

      # optional
      fit_plots: true
      fit_plot_info:
        timestep: 3
        show_approach: true
        goodness: chisq
        corrname: standard
        symbol_color: blue
        symbol_type: circle
        max_relative_error: 0.0

      # optional
      tmin_plots: true
      tmin_plot_info:
        obsname: standard
        symbol_type: circle
        goodfit_color: blue
        badfit_color: red
        goodfit_hollow: false
        badfit_hollow: false
        quality_threshold: 0.1

      # optional
      reference_fit_info:
        operator: isotriplet S=0 P=(0,0,0) A1um P 0
        model: 1-exp
        tmin: 14
        tmax: 40

      # optional (used for ratio fits)
      scattering_particles:  
        - name: pi
          operators:
            - isotriplet S=0 P=(0,0,0) A1um P 0
            - isotriplet S=0 PSQ=1 A2m P 0
            - isotriplet S=0 PSQ=2 A2m P 0
            - isotriplet S=0 PSQ=3 A2m P 0
            ...
        - ...
        ...

      fits:
        - name: fit_type1
          model: 2-exp
          tmin: 7-12
          tmax: 15-30
          ratio: false             # optional
          exclude_times: [10,12]   # optional
          noise_cutoff: 1.2        # optional
        - ...
        ...

      ### operator_sets
      operator_sets:
        - name: pion_0
          operators: 
            - isotriplet S=0 P=(0,0,0) A1um P 0
          fits:                 # optional (if missing, does all fits)
            - fit_type1
        - name: op_basis1
          operators:
            - isodoublet S=0 P=(0,0,0) A1um P 0
            - isodoublet S=0 P=(0,0,0) A1um P 1
          non_interacting_levels:    # required for ratio fits
            - [pi(0), pi(2), pi(3)]
            - [pi(1), pi(2), pi(3)]
            - ...
          fits:                 # optional (if missing, does all fits)
            - fit_type1
            - ...
            ...
        - name: rotated_op_basis
          pivot_info:
            pivot_type: single_pivot
            norm_time: 5
            metric_time: 5
            diagonalize_time: 10
            max_condition_number: 100
        - ...
        ...
    """

        task_options[
            'minimizer_info'] = sigmond_info.sigmond_info.getMinimizerInfo(
                task_options)
        task_options[
            'fit_plot_info'] = sigmond_info.sigmond_info.FitPlotInfo.createFromConfig(
                task_options)
        task_options[
            'tmin_plot_info'] = sigmond_info.sigmond_info.TMinPlotInfo.createFromConfig(
                task_options)

        ref_fit_info = task_options.pop('reference_fit_info', None)
        if ref_fit_info is not None:
            ref_fit_info = sigmond_info.fit_info.FitInfo.createFromConfig(
                ref_fit_info)
        task_options['reference_fit_info'] = ref_fit_info

        # check for scattering_particles
        scattering_particles = dict()
        for scattering_particle in task_options.pop('scattering_particles',
                                                    []):
            try:
                name = scattering_particle.pop('name')
                op_strs = scattering_particle.pop('operators')
            except KeyError as err:
                logging.error(
                    f"Missing required key in 'scattering_particles': {err}")

            operators = dict()
            for op_str in op_strs:
                operator = operator_info.operator.Operator(op_str)
                psq = operator.psq
                scattering_particle = sigmond_info.sigmond_info.ScatteringParticle(
                    name, psq)
                if scattering_particle in scattering_particles:
                    logging.error(
                        f"Scattering particle '{scattering_particle}' encountered twice"
                    )

                scattering_particles[scattering_particle] = operator

        task_options['scattering_particles'] = scattering_particles

        # Read fits
        fits = dict()
        try:
            for fit in task_options.pop('fits'):
                name = fit.pop('name')
                if name in fits:
                    logging.warning(
                        f"Fit with name '{name}' appeared more than once...overwriting"
                    )

                model = sigmond_info.fit_info.FitModel(fit.pop('model'))
                exclude_times = fit.pop('exclude_times', tuple())
                noise_cutoff = fit.pop('noise_cutoff', 0.0)
                ratio = fit.pop('ratio', False)

                tmins = fit.pop('tmin')
                if isinstance(tmins, int):
                    tmins = [int(tmins)]
                else:
                    tmins = list(map(int, tmins.split('-')))
                    tmins = list(range(tmins[0], tmins[-1] + 1))

                tmaxs = fit.pop('tmax')
                if isinstance(tmaxs, int):
                    tmaxs = [int(tmaxs)]
                else:
                    tmaxs = list(map(int, tmaxs.split('-')))
                    tmaxs = list(range(tmaxs[0], tmaxs[-1] + 1))

                tranges = list()

                n_params = len(sigmond_info.fit_info.FitInfo.PARAMETERS[model])
                for tmin in tmins:
                    for tmax in tmaxs:
                        n_dof = tmax - tmin + 1 - n_params
                        if n_dof < 1:
                            continue

                        tranges.append(TRange(tmin, tmax))

                util.check_extra_keys(fit, "fits")

                fits[name] = Fits(name, model, tuple(tranges), ratio,
                                  tuple(exclude_times), noise_cutoff)

        except KeyError as err:
            err = str(err)
            if err == "'fits'":
                logging.error("Fit tasks need a 'fits' section")
            elif err == "'name'":
                logging.error(
                    f"No 'name' for fit in 'fits' section of task '{self.task_name}'"
                )
            else:
                logging.error(
                    f"Missing required key in '{name}' fit of task '{self.task_name}': {err}"
                )

        # read operator sets
        subtractvev = task_options.pop('subtractvev', True)
        operator_fits = dict()
        non_interacting_operators_lists = dict()
        try:
            for operator_set_conf in task_options.pop('operator_sets'):
                operator_set = operator_info.operator_set.getOperatorSet(
                    operator_set_conf)
                operator_fits[operator_set] = dict()
                operators = operator_set.getRotatedOperators(
                ) if operator_set.is_rotated else operator_set.operators
                non_interacting_levels = operator_set_conf.pop(
                    'non_interacting_levels', [None] * len(operators))

                fit_keys = operator_set_conf.pop('fits', list(fits.keys()))
                for operator, non_interacting_level in zip(
                        operators, non_interacting_levels):
                    if non_interacting_level is None:
                        non_interacting_operators = None
                    else:
                        non_interacting_operators = sigmond_info.sigmond_info.NonInteractingOperators.create(
                            scattering_particles, non_interacting_level)

                    operator_fits[operator_set][operator] = dict()
                    for fit_key in fit_keys:
                        if fit_key not in fits:
                            logging.error(f"Invalid fit name '{fit_key}")

                        fits_to_do = fits[fit_key]
                        operator_fits[operator_set][operator][fits_to_do] = {
                            'normal': [],
                            'tmin': []
                        }
                        for trange in fits_to_do.tranges:
                            fit_info = sigmond_info.fit_info.FitInfo(
                                operator, fits_to_do.model, trange.tmin,
                                trange.tmax, subtractvev, fits_to_do.ratio,
                                list(fits_to_do.exclude_times),
                                fits_to_do.noise_cutoff,
                                non_interacting_operators)

                            operator_fits[operator_set][operator][fits_to_do][
                                'normal'].append(fit_info)

                        for tmax, tranges in itertools.groupby(
                                sorted(fits_to_do.tranges,
                                       key=lambda trange: trange.tmax),
                                lambda trange: trange.tmax):
                            tmins = list(trange.tmin for trange in tranges)
                            tmin_min = min(tmins)
                            tmin_max = max(tmins)
                            fit_info = sigmond_info.fit_info.FitInfo(
                                operator, fits_to_do.model, tmin_min, tmax,
                                subtractvev, fits_to_do.ratio,
                                list(fits_to_do.exclude_times),
                                fits_to_do.noise_cutoff,
                                non_interacting_operators, tmin_max)

                            operator_fits[operator_set][operator][fits_to_do][
                                'tmin'].append(fit_info)

                util.check_extra_keys(operator_set_conf, "operator_sets")
        except KeyError as err:
            logging.error(f"Missing required key in 'operator_bases': {err}")

        self.initialize(operator_fits, **task_options)
Пример #8
0
class AverageCorrelators(tasks.task.Task):
    """ Average Correlators task

  TODO:
    Do a finalize in which averaged correlators are put into a PDF?
  """

    task_type = "average_corrs"

    def initiliaze(self, **options):
        """sets the needed parameters for the task

    Args:
      **averaged_channels (SortedSet(Channel)): The set of
          channels to be created after averaging over
          the available raw channels.
      **coefficients ({Operator: float}): the coefficients
          other than 1.0 to use for operators. All operators
          not present are assumed to have a coefficient
          of 1.0
      **excluded_operators ({Operator}): A set of operators to not consider
      **file_mode (sigmond.WriteMode): the file mode to use (see
          sigmond docs)
      **off_diagonal (bool): specifies whether the off diagonal
          correlators should be printed
      **hermitian (bool): whether we should be looking for hermitian
          correlators
      **use_spatial_info (bool): specifies if spatial info should be
          given in averaged op name
      **use_irrep_info (bool): specifies if irrep info should be
          given in averaged op name
      **plot_info (PlotInfo): info about the plot
      **write_operators (bool): determines whether the operators
          should be written to file
    """
        self.subtractvev = False

        self.hermitian = options.pop('hermitian', True)
        self.off_diagonal = options.pop('off_diagonal', False)
        self.plot_info = options.pop('plot_info',
                                     sigmond_info.sigmond_info.PlotInfo())
        self.write_operators = options.pop('write_operators', False)
        self.excluded_operators = options.pop('excluded_operators', set())

        self.use_spatial_info = options.pop('use_spatial_info', False)
        self.use_irrep_info = options.pop('use_irrep_info', False)

        raw_channels = self.data_handler.raw_channels
        self.averaged_channels = dict()
        for raw_channel in raw_channels:
            if raw_channel.is_averaged:
                logging.warning(f"Channel '{raw_channel}' is averaged already")
                continue

            averaged_channel = raw_channel.averaged
            if averaged_channel not in self.averaged_channels:
                self.averaged_channels[averaged_channel] = SortedSet()

            self.averaged_channels[averaged_channel].add(raw_channel)

        if (user_averaged_channels := options.pop('averaged_channels',
                                                  SortedSet())):
            try:
                self.averaged_channels = {
                    averaged_channel: self.averaged_channels[averaged_channel]
                    for averaged_channel in user_averaged_channels
                }
            except KeyError as err:
                logging.error(
                    "Channel {err} not an averaged channel of the found raw channels"
                )

        self.coefficients = options.pop('coefficients', dict())
        self.file_mode = options.pop('file_mode', sigmond.WriteMode.Overwrite)

        util.check_extra_keys(options, self.task_name)