Analysis#

The analysis subpackage contains objects to process and manipulate experimental data.

keysight.qcs.analysis.BaseFitter

A class for fitting real-valued data.

keysight.qcs.analysis.ComplexFitter

A class for fitting complex-valued data.

keysight.qcs.analysis.ComplexLorentzian

A fitter for a complex Lorentzian.

keysight.qcs.analysis.DecayingSinusoid

A fitter for a decaying sinusoid.

keysight.qcs.analysis.Estimate

Class that stores fit information returned from data analysis.

keysight.qcs.analysis.EstimateCollection

An iterable container of estimates with several convenience functions which make it easier to select specific estimates.

keysight.qcs.analysis.EstimateTuple

A namedtuple container for storing a single estimate name, value, and standard deviation.

keysight.qcs.analysis.Exponential

A fitter for an exponential curve.

keysight.qcs.analysis.FanoResonance

A fitter for a Fano resonance with an added Gaussian dip, to capture sharp resonator response features with an asymmetric background.

keysight.qcs.analysis.IQuadrature

Extracts the I quadrature from complex IQ data.

keysight.qcs.analysis.LinearDetrend

Removes linear trends from experimental data.

keysight.qcs.analysis.Preprocessor

A class that processes experimental data before fitting.

Estimates#

class keysight.qcs.analysis.Estimate(names: list[str], values: ndarray, cov: ndarray)#

Bases: Serializable

Class that stores fit information returned from data analysis.

Parameters:
  • names – The names of the parameters estimated by the fit.

  • values – The values of the estimates.

  • cov – The covariance matrix of the estimates.

property cov: ndarray#

The covariance matrix of this estimate.

property names: list[str]#

A list of strings which describe the parameters returned from fitting.

property std: ndarray#

A vector of standard deviations for every element of this estimate.

property values: ndarray#

A vector containing the estimated values associated with the provided names.

draw(filename: str = 'qcs_estimate.html', display: bool = True) None#

Creates an HTML representation of this Estimate and saves it to a file.

Parameters:
  • filename – The filename to write the HTML to (if executing in a script)

  • display – Whether to display the HTML. When set to False, this will only save the file to the specified filename.

class keysight.qcs.analysis.EstimateCollection(estimates: Estimate | Iterable[Estimate] | None = None, type: str = '1D')#

Bases: Serializable

An iterable container of estimates with several convenience functions which make it easier to select specific estimates.

Parameters:

estimates – Either a single estimate or an iterable of estimates to include in the collection.

property estimates: list[Estimate]#

The estimates in this collection.

property type: str#

The type of the estimate collection.

append(estimate: Estimate | Iterable[Estimate])#

Appends a single estimate or an iterable of estimates to the collection.

Parameters:

estimate – A single estimate or an iterable of estimates.

vector(name: str) ndarray#

Constructs a vector of estimates for a given parameter.

Parameters:

name – The name of the parameter to extract.

draw(filename: str = 'qcs_estimate_collection.html', display: bool = True) None#

Creates an HTML representation of this estimate collection and saves it to a file.

Parameters:
  • filename – The filename to write the HTML to (if executing in a script)

  • display – Whether to display the HTML. When set to False, this will only save the file to the specified filename.

class keysight.qcs.analysis.EstimateTuple(name, val, std)#

Bases: tuple

A namedtuple container for storing a single estimate name, value, and standard deviation.

Parameters:
  • name – The name of the estimate.

  • val – The value of the estimate.

  • std – The standard deviation of the estimate.

Fitting#

class keysight.qcs.analysis.BaseFitter#

Bases: Serializable

A class for fitting real-valued data.

abstract property model: Callable#

The model. Must have ‘x’ (corresponding to the x-axis data) as first parameter for displaying the model equation in interactive plot.

abstract property names: tuple[str, ...]#

The names of the parameters of the model. Must match the names used in the model for interactive plot.

apply_fitter(x_values: ndarray, y_values: ndarray, guess: tuple[float, ...] | None = None, preprocessors: Iterable[Preprocessor] | None = None, qudit_index: int | None = None, bounds: tuple[Sequence[float], Sequence[float]] | Bounds | None = None, method: Literal['lm', 'trf', 'dogbox'] | None = None, loss: Literal['linear', 'soft_l1', 'huber', 'cauchy', 'arctan'] | Callable[[ndarray], ndarray] | None = 'linear') Estimate#

Performs nonlinear least-squares fitting of a model to the input data.

Uses scipy.optimize.curve_fit(). For details on least-squares fitting, see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

  • guess – The initial guess for the parameters. If None, uses the make_guess method.

  • preprocessors – An iterable of Preprocessors that are applied to the data before fitting.

  • qudit_index – Optional index to look up a saved guess.

  • bounds – Lower and upper bounds on model parameters. If not given, defaults to unconstrained fitting.

  • method – Optimization algorithm to use. Sets ‘lm’ by default but if bounds are given, switches to method=’trf’ (or ‘dogbox’, if specified.)

  • loss – Loss function to use in robust fitting (for ‘trf’ and ‘dogbox’). Either a string with method name or custom callable that maps residuals to loss values.

Returns:

Estimate for the parameters of the fitting model.

abstract make_guess(x_values: ndarray, y_values: ndarray) tuple[float, ...]#

Generates a guess for the parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

class keysight.qcs.analysis.ComplexFitter#

Bases: BaseFitter

A class for fitting complex-valued data.

apply_fitter(x_values: ndarray, y_values: ndarray, guess=None, preprocessors=None, qudit_index: int | None = None, bounds: tuple[Sequence[float], Sequence[float]] | Bounds | None = None, method: Literal['lm', 'trf', 'dogbox'] | None = None, loss: Literal['linear', 'soft_l1', 'huber', 'cauchy', 'arctan'] | Callable[[ndarray], ndarray] | None = 'linear') Estimate#

Performs nonlinear least-squares fitting of a model to the input data.

Uses scipy.optimize.curve_fit(). For details on least-squares fitting, see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

  • guess – The initial guess for the parameters. If None, uses the make_guess method.

  • preprocessors – An iterable of Preprocessors that are applied to the data before fitting.

  • qudit_index – Optional index to look up a saved guess.

  • bounds – Lower and upper bounds on model parameters. If not given, defaults to unconstrained fitting.

  • method – Optimization algorithm to use. Sets ‘lm’ by default but if bounds are given, switches to method=’trf’ (or ‘dogbox’, if specified.)

  • loss – Loss function to use in robust fitting (for ‘trf’ and ‘dogbox’).

Returns:

Estimate for the parameters of the fitting model.

class keysight.qcs.analysis.ComplexLorentzian#

Bases: ComplexFitter

A fitter for a complex Lorentzian.

property model#

The model. Must have ‘x’ (corresponding to the x-axis data) as first parameter for displaying the model equation in interactive plot.

property names#

The names of the parameters of the model. Must match the names used in the model for interactive plot.

make_guess(x_values: ndarray, y_values: ndarray) tuple#

Generates a guess for the parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

class keysight.qcs.analysis.DecayingSinusoid#

Bases: BaseFitter

A fitter for a decaying sinusoid.

property model#

The model. Must have ‘x’ (corresponding to the x-axis data) as first parameter for displaying the model equation in interactive plot.

property names#

The names of the parameters of the model. Must match the names used in the model for interactive plot.

make_guess(x_values, y_values) tuple#

Generates a guess for the parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

class keysight.qcs.analysis.Exponential#

Bases: BaseFitter

A fitter for an exponential curve.

property model#

The model. Must have ‘x’ (corresponding to the x-axis data) as first parameter for displaying the model equation in interactive plot.

property names#

The names of the parameters of the model. Must match the names used in the model for interactive plot.

make_guess(x_values, y_values)#

Generates a guess for the parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

class keysight.qcs.analysis.FanoResonance#

Bases: ComplexFitter

A fitter for a Fano resonance with an added Gaussian dip, to capture sharp resonator response features with an asymmetric background.

\[\begin{equation*} A\times((q + ε)^2/(1 + ε^2))+ B-C\times\exp{(-(x - x_0)^2/(2 \times \sigma^2))} \end{equation*}\]

where \(ε = (x - x_0) / (\gamma / 2)\)

property model#

The model. Must have ‘x’ (corresponding to the x-axis data) as first parameter for displaying the model equation in interactive plot.

property names#

The names of the parameters of the model.

Returns:

  • q: Fano asymmetry parameter. Controls the skewness of the resonance.

  • gamma: Full width at half maximum (FWHM) of the resonance.

  • x0: Resonance frequency.

  • A: Amplitude (depth or height) of the Fano profile.

  • offset: Vertical offset added to the Fano profile.

  • amp_dip: Amplitude of the Gaussian dip subtracted from the Fano curve.

  • sigma_dip: Standard deviation of the Gaussian dip.

make_guess(x_values: ndarray, y_values: ndarray)#

Generates a guess for the parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

apply_fitter(x_values: ndarray, y_values: ndarray, guess: tuple[float, float, float, float, float, float, float] | None = None, qudit_index: int | None = None) Estimate#

Fits an array and returns the fitted parameters.

Parameters:
  • x_values – The independent variable values.

  • y_values – The data to fit.

  • guess – The initial guess for the parameters. If None, uses the make_guess method.

  • qudit_index – Optional index to look up a saved guess.

Returns:

Estimate for the parameters of the fitting model.

Preprocessing#

class keysight.qcs.analysis.Preprocessor#

Bases: Serializable

A class that processes experimental data before fitting.

abstract process(x_values: ndarray, y_values: ndarray) tuple[ndarray, ndarray]#

Process the data.

class keysight.qcs.analysis.LinearDetrend#

Bases: Preprocessor

Removes linear trends from experimental data.

process(x_values, y_values)#

Process the data.

class keysight.qcs.analysis.IQuadrature#

Bases: Preprocessor

Extracts the I quadrature from complex IQ data.

process(x_values, y_values)#

Process the data.