# `pygsti.algorithms.rbfit`

Functions for analyzing RB data

## Module Contents

### Classes

 `FitResults` An object to contain the results from fitting RB data.

### Functions

 `std_least_squares_fit`(lengths, asps, n[, seed, ...]) Implements a "standard" least-squares fit of RB data. `custom_least_squares_fit`(lengths, asps, n[, a, b, ...]) Fits RB average success probabilities to the exponential decay a + Bp^m using least-squares fitting.
pygsti.algorithms.rbfit.std_least_squares_fit(lengths, asps, n, seed=None, asymptote=None, ftype='full', rtype='EI')

Implements a “standard” least-squares fit of RB data.

Fits the average success probabilities to the exponential decay A + Bp^m, using least-squares fitting.

#### Parameters

lengthslist

The RB lengths to fit to (the ‘m’ values in A + Bp^m).

aspslist

The average survival probabilities to fit (the observed P_m values to fit to P_m = A + Bp^m).

nint

The number of qubits the data was generated from.

seedlist, optional

Seeds for the fit of B and p (A, if a variable, is seeded to the asymptote defined by asympote).

asymptotefloat, optional

If not None, the A value for the fitting to A + Bp^m with A fixed. Defaults to 1/2^n. Note that this value is used even when fitting A; in that case B and p are estimated with A fixed to this value, and then this A and the estimated B and p are seed for the full fit.

ftype{‘full’,’FA’,’full+FA’}, optional

The fit type to implement. ‘full’ corresponds to fitting all of A, B and p. ‘FA’ corresponds to fixing ‘A’ to the value specified by asymptote. ‘full+FA’ returns the results of both fits.

rtype{‘EI’,’AGI’}, optional

The RB error rate rescaling convention. ‘EI’ results in RB error rates that are associated with the entanglement infidelity, which is the error probability with stochastic errors (and is equal to the diamond distance). ‘AGI’ results in RB error rates that are associated with average gate infidelity.

#### Returns

Dict or Dicts

If ftype = ‘full’ or ftype = ‘FA’ then a dict containing the results of the relevant fit. If ftype = ‘full+FA’ then two dicts are returned. The first dict corresponds to the full fit and the second to the fixed-asymptote fit.

pygsti.algorithms.rbfit.custom_least_squares_fit(lengths, asps, n, a=None, b=None, seed=None, rtype='EI')

Fits RB average success probabilities to the exponential decay a + Bp^m using least-squares fitting.

#### Parameters

lengthslist

The RB lengths to fit to (the ‘m’ values in a + Bp^m).

aspslist

The average survival probabilities to fit (the observed P_m values to fit to P_m = a + Bp^m).

nint

The number of qubits the data was generated from.

afloat, optional

If not None, a value to fix a to.

bfloat, optional

If not None, a value to fix b to.

seedlist, optional

Seeds for variables in the fit, in the order [a,b,p] (with a and/or b dropped if it is set to a fixed value).

rtype{‘EI’,’AGI’}, optional

The RB error rate rescaling convention. ‘EI’ results in RB error rates that are associated with the entanglement infidelity, which is the error probability with stochastic errors (and is equal to the diamond distance). ‘AGI’ results in RB error rates that are associated with average gate infidelity.

#### Returns

Dict

The fit results. If item with the key ‘success’ is False, the fit has failed.

class pygsti.algorithms.rbfit.FitResults(fittype, seed, rtype, success, estimates, variable, stds=None, bootstraps=None, bootstraps_failrate=None)

An object to contain the results from fitting RB data.

Currently just a container for the results, and does not include any methods.

#### Parameters

fittypestr

A string to identity the type of fit.

seedlist

The seed used in the fitting.

rtype{‘IE’,’AGI’}

The type of RB error rate that the ‘r’ in these fit results corresponds to.

successbool

Whether the fit was successful.

estimatesdict

A dictionary containing the estimates of all parameters

variabledict

A dictionary that specifies which of the parameters in “estimates” where variables to estimate (set to True for estimated parameters, False for fixed constants). This is useful when fitting to A + B*p^m and fixing one or more of these parameters: because then the “estimates” dict can still be queried for all three parameters.

stdsdict, optional

Estimated standard deviations for the parameters.

bootstrapsdict, optional

Bootstrapped values for the estimated parameters, from which the standard deviations were calculated.

bootstraps_failratefloat, optional

The proporition of the estimates of the parameters from bootstrapped dataset failed.

Initialize a FitResults object.

#### Parameters

fittypestr

A string to identity the type of fit.

seedlist

The seed used in the fitting.

rtype{‘IE’,’AGI’}

The type of RB error rate that the ‘r’ in these fit results corresponds to.

successbool

Whether the fit was successful.

estimatesdict

A dictionary containing the estimates of all parameters

variabledict

A dictionary that specifies which of the parameters in “estimates” where variables to estimate (set to True for estimated parameters, False for fixed constants). This is useful when fitting to A + B*p^m and fixing one or more of these parameters: because then the “estimates” dict can still be queried for all three parameters.

stdsdict, optional

Estimated standard deviations for the parameters.

bootstrapsdict, optional

Bootstrapped values for the estimated parameters, from which the standard deviations were calculated.

bootstraps_failratefloat, optional

The proporition of the estimates of the parameters from bootstrapped dataset failed.