# DragCalAnalysis¶

class DragCalAnalysis(models=None, name=None)[source]

Drag calibration analysis based on a fit to a cosine function.

Fit model

This is the curve fitting analysis. The following equation(s) are used to represent curve(s).

Analyse a Drag calibration experiment by fitting multiple series each to a cosine function. All functions share the phase parameter (i.e. beta), amplitude, and baseline. The frequencies of the oscillations are related through the number of repetitions of the Drag gates. Several initial guesses are tried if the user does not provide one. The fit function is

$y_i = {\rm amp} \cos\left(2 \pi\cdot {\rm reps}_i \cdot {\rm freq}\cdot x - 2 \pi\cdot {\rm reps}_i \cdot {\rm freq}\cdot \beta\right) + {\rm base}$

Here, the fit parameter $$freq$$ is the frequency of the oscillation of a single pair of Drag plus and minus rotations and $${\rm reps}_i$$ is the number of times that the Drag plus and minus rotations are repeated in curve $$i$$. Note that the aim of the Drag calibration is to find the $$\beta$$ that minimizes the phase shifts. This implies that the optimal $$\beta$$ occurs when all $$y$$ curves are minimum, i.e. they produce the ground state. This occurs when

${\rm reps}_i * {\rm freq} * (x - \beta) = N$

is satisfied with $$N$$ an integer. Note, however, that this condition produces a minimum only when the amplitude is negative. To ensure this is the case, we bound the amplitude to be less than 0.

Fit parameters

The following fit parameters are estimated during the analysis.

Descriptions
• $$\rm amp$$: Amplitude of all series.

• $$\rm base$$: Base line of all series.

• $${\rm freq}$$: Frequency of oscillation as a function of $$\beta$$ for a single pair of DRAG plus and minus pulses.

• $$\beta$$: Common beta offset. This is the parameter of interest.

Initial Guess
• $$\rm amp$$: The maximum y value scaled by -1, -0.5, and -0.25.

• $$\rm base$$: Half the maximum y-value of the data.

• $${\rm freq}$$: For the curve with the most Drag pulse repetitions, the peak frequency of the power spectral density is found and then divided by the number of repetitions.

• $$\beta$$: Linearly spaced between the maximum and minimum scanned beta.

Boundaries
• $$\rm amp$$: [-2, 0] scaled to the maximum signal value.

• $$\rm base$$: [-1, 1] scaled to the maximum y-value.

• $${\rm freq}$$: [0, inf].

• $$\beta$$: [-min scan range, max scan range].

Analysis options

These are the keyword arguments of the run() method.

Options
• Defined in the class BaseCurveAnalysis:

• plotter (BasePlotter)

Default value: Instance of CurvePlotter
A curve plotter instance to visualize the analysis result.
• plot_raw_data (bool)

Default value: False
Set True to draw processed data points, dataset without formatting, on canvas. This is False by default.
• plot_residuals (bool)

Default value: False
Set True to draw the residuals data for the fitting model. This is False by default.
• return_fit_parameters (bool)

Default value: True
(Deprecated) Set True to return all fit model parameters with details of the fit outcome. Default to False.
• data_processor (Callable)

Default value: None
A callback function to format experiment data. This can be a DataProcessor instance that defines the self.__call__ method.
• normalization (bool)

Default value: True
Set True to normalize y values within range [-1, 1]. Default to False.
• average_method (Literal[“sample”, “iwv”, “shots_weighted”])

Default value: "shots_weighted"
Method to average the y values when the same x values appear multiple times. One of “sample”, “iwv” (i.e. inverse weighted variance), “shots_weighted”. See mean_xy_data() for details. Default to “shots_weighted”.
• p0 (Dict[str, float])

Default value: {}
Initial guesses for the fit parameters. The dictionary is keyed on the fit parameter names.
• bounds (Dict[str, Tuple[float, float]])

Default value: {}
Boundary of fit parameters. The dictionary is keyed on the fit parameter names and values are the tuples of (min, max) of each parameter.
• fit_method (str)

Default value: "least_squares"
Fit method that LMFIT minimizer uses. Default to least_squares method which implements the Trust Region Reflective algorithm to solve the minimization problem. See LMFIT documentation for available options.
• lmfit_options (Dict[str, Any])

Default value: {}
Options that are passed to the LMFIT minimizer. Acceptable options depend on fit_method.
• x_key (str)

Default value: "xval"
Circuit metadata key representing a scanned value.
• fit_category (str)

Default value: "formatted"
Name of dataset in the scatter table to fit.
• result_parameters (List[Union[str, ParameterRepr])

Default value: ["beta"]
Parameters reported in the database as a dedicated entry. This is a list of parameter representation which is either string or ParameterRepr object. If you provide more information other than name, you can specify [ParameterRepr("alpha", "α", "a.u.")] for example. The parameter name should be defined in the series definition. Representation should be printable in standard output, i.e. no latex syntax.
• extra (Dict[str, Any])

Default value: {}
A dictionary that is appended to all database entries as extra information.
• fixed_parameters (Dict[str, Any])

Default value: {}
Fitting model parameters that are fixed during the curve fitting. This should be provided with default value keyed on one of the parameter names in the series definition.
• filter_data (Dict[str, Any])

Default value: {}
Dictionary of experiment data metadata to filter. Experiment outcomes with metadata that matches with this dictionary are used in the analysis. If not specified, all experiment data are input to the curve fitter. By default, no filtering condition is set.
• data_subfit_map (Dict[str, Dict[str, Any]])

Default value: {}
The mapping of experiment result data to sub-fit models. This dictionary is keyed on the LMFIT model name, and the value is a sorting key-value pair that filters the experiment results, and the filtering is done based on the circuit metadata.
• Defined in the class BaseAnalysis:

• figure_names (str or List[str])

Default value: None
Identifier of figures that appear in the experiment data to sort figures by name.

Initialization

Initialize data fields that are privately accessed by methods.

Parameters:
• models (List[Model] | None) – List of LMFIT Model class to define fitting functions and parameters. If multiple models are provided, the analysis performs multi-objective optimization where the parameters with the same name are shared among provided models. When multiple models are provided, user must specify the data_subfit_map value in the analysis options to allocate experimental results to a particular fit model.

• name (str | None) – Optional. Name of this analysis.

Attributes

models

Return fit models.

name

Return name of this analysis.

options

Return the analysis options for run() method.

parameters

Return parameters of this curve analysis.

plotter

A short-cut to the curve plotter instance.

Methods

config()

Return the config dataclass for this analysis

Return type:

AnalysisConfig

copy()

Return a copy of the analysis

Return type:

BaseAnalysis

classmethod from_config(config)

Initialize an analysis class from analysis config

Return type:

BaseAnalysis

model_names()

Return model names.

Return type:

List[str]

run(experiment_data, replace_results=False, **options)

Run analysis and update ExperimentData with analysis result.

Parameters:
• experiment_data (ExperimentData) – the experiment data to analyze.

• replace_results (bool) – If True clear any existing analysis results, figures, and artifacts in the experiment data and replace with new results. See note for additional information.

• options – additional analysis options. See class documentation for supported options.

Returns:

An experiment data object containing analysis results, figures, and artifacts.

Raises:

QiskitError – If experiment_data container is not valid for analysis.

Return type:

ExperimentData

Note

Updating Results

If analysis is run with replace_results=True then any analysis results, figures, and artifacts in the experiment data will be cleared and replaced with the new analysis results. Saving this experiment data will replace any previously saved data in a database service using the same experiment ID.

If analysis is run with replace_results=False and the experiment data being analyzed has already been saved to a database service, or already contains analysis results or figures, a copy with a unique experiment ID will be returned containing only the new analysis results and figures. This data can then be saved as its own experiment to a database service.

set_options(**fields)[source]

Set the analysis options for run() method.

Parameters:

fields – The fields to update the options

Raises:

KeyError – When removed option curve_fitter is set.