pygsti.extras.paritybenchmarking.disturbancecalc

Module Contents

Classes

ResidualTVD

Computes the "weight-X residual TVD": the TVD between two probability

RegularizedDeltaLikelihood

The max - log-likelihood regularized by a "fixed-transition-matrix residual TVD".

ProfileLikelihood

The profile likelihood obtained by maximizing the likelihood on level-sets of

ResidualTVDWithConfidence

Residual TVD with error bars given by an assumed-symmetric confidence-region.

ProfileLikelihoodPlot

Creates a plot of the profile log-likelihood.

Functions

default_cvxpy_args(solver)

remove_kicked(s)

print_revert_msg(formatted_str, tup, verbosity)

unit_vector(a, b)

Returns the unit vector of length 'b' with the 'a'th element = 1

matrix_units(dim)

Returns a list of all matrix units of dimension dim

multikron(a)

Kronecker product of all the elements of a

interior_tensor_product(mx, dim_a, dim_b[, e])

mx is an operator on two subsystems of dimension dim_a and dim_b

swell_slow(mx, which_bits[, n_bits])

swell(mx, which_bits[, n_bits])

n_matrices_per_weight(weight, n_bits)

The number of submatrices there are for weight

n_parameters_per_matrix(weight, n_bits)

The number of parameters needed to define a weight-w transition submatrix on n_bits

n_parameters(weight, n_bits)

The number of parameters needed to define a complete weight-w transition matrix

transition_matrix(v, dimension)

Produce a transition matrix of a given dimension given a parameter vector v.

comprehensive_transition_matrix(v, weight, n_bits)

Build a generic weight-n transition_matrix

nlogp(n, p)

n*log(p) such that if n == 0 the product is 0 too

log_likelihood(data, probs)

Compute log likelihood of a probability distribution over bitstrings given data

max_log_likelihood(data)

Compute log likelihood of a probability distribution over bitstrings given data

compute_disturbances_with_confidence(n_bits, data_ref, ...)

Compute the weight-X distrubances between two data sets (including error bars).

compute_ovd_over_tvd_ratio(n_bits, data_ref, ...[, ...])

TODO: docstring

compute_ovd_corrected_disturbances_noconfidence(...[, ...])

Compute the weight-X distrubances between two data sets (including error bars).

compute_residual_tvds(n_bits, data_ref, data_test[, ...])

Compute the weight-X residual TVDs between two data sets (including error bars).

resample_data(data[, n_data_points, seed])

Sample from the ML probability distrubution of data.

compute_disturbances_bootstrap_rawdata(n_bits, ...[, ...])

Compute the weight-X distrubances between two data sets (including error bars).

compute_ovd_corrected_disturbances_bootstrap_rawdata(...)

Compute the weight-X distrubances between two data sets (including error bars).

compute_disturbances_from_bootstrap_rawdata(...[, ...])

Compute 1-sigma error bars for a set of disturbances (given by ml_disturbances)

compute_disturbances(n_bits, data_ref, data_test[, ...])

Compute the weight-X disturbances between two data sets (including error bars).

compute_ovd_corrected_disturbances(n_bits, data_ref, ...)

Compute the weight-X disturbances between two data sets (including error bars).

Attributes

REBUILD

REVERT_MSG_THRESHOLD

MAX_RESIDUAL_TVD_REDUCTION_PER_ITER

OBJ_CHK_TOL

ZERO_RTVD_THRESHOLD

CONSTRAINT_ZERO

default_cvxpy_solver_args

build_basis

pygsti.extras.paritybenchmarking.disturbancecalc.REBUILD = 'True'
pygsti.extras.paritybenchmarking.disturbancecalc.REVERT_MSG_THRESHOLD = '10.0'
pygsti.extras.paritybenchmarking.disturbancecalc.MAX_RESIDUAL_TVD_REDUCTION_PER_ITER = '0.3'
pygsti.extras.paritybenchmarking.disturbancecalc.OBJ_CHK_TOL = '1e-06'
pygsti.extras.paritybenchmarking.disturbancecalc.ZERO_RTVD_THRESHOLD = '1e-05'
pygsti.extras.paritybenchmarking.disturbancecalc.CONSTRAINT_ZERO = '0.0'
pygsti.extras.paritybenchmarking.disturbancecalc.default_cvxpy_solver_args
pygsti.extras.paritybenchmarking.disturbancecalc.default_cvxpy_args(solver)
pygsti.extras.paritybenchmarking.disturbancecalc.remove_kicked(s)
pygsti.extras.paritybenchmarking.disturbancecalc.print_revert_msg(formatted_str, tup, verbosity)
pygsti.extras.paritybenchmarking.disturbancecalc.unit_vector(a, b)

Returns the unit vector of length ‘b’ with the ‘a’th element = 1

pygsti.extras.paritybenchmarking.disturbancecalc.matrix_units(dim)

Returns a list of all matrix units of dimension dim

pygsti.extras.paritybenchmarking.disturbancecalc.multikron(a)

Kronecker product of all the elements of a

pygsti.extras.paritybenchmarking.disturbancecalc.interior_tensor_product(mx, dim_a, dim_b, e=None)

mx is an operator on two subsystems of dimension dim_a and dim_b mx = sum_i A_i otimes B_i where A_i is an operator on subsystem a and B_i is an operator on subsystem b Return: sum_i A_i otimes e otimes B_i

pygsti.extras.paritybenchmarking.disturbancecalc.swell_slow(mx, which_bits, n_bits=4)
pygsti.extras.paritybenchmarking.disturbancecalc.swell(mx, which_bits, n_bits=4)
pygsti.extras.paritybenchmarking.disturbancecalc.n_matrices_per_weight(weight, n_bits)

The number of submatrices there are for weight

pygsti.extras.paritybenchmarking.disturbancecalc.n_parameters_per_matrix(weight, n_bits)

The number of parameters needed to define a weight-w transition submatrix on n_bits

pygsti.extras.paritybenchmarking.disturbancecalc.n_parameters(weight, n_bits)

The number of parameters needed to define a complete weight-w transition matrix

pygsti.extras.paritybenchmarking.disturbancecalc.transition_matrix(v, dimension)

Produce a transition matrix of a given dimension given a parameter vector v. The only enforced constraint here is that the columns sum to 1

pygsti.extras.paritybenchmarking.disturbancecalc.comprehensive_transition_matrix(v, weight, n_bits)

Build a generic weight-n transition_matrix

pygsti.extras.paritybenchmarking.disturbancecalc.nlogp(n, p)

n*log(p) such that if n == 0 the product is 0 too

pygsti.extras.paritybenchmarking.disturbancecalc.log_likelihood(data, probs)

Compute log likelihood of a probability distribution over bitstrings given data

pygsti.extras.paritybenchmarking.disturbancecalc.max_log_likelihood(data)

Compute log likelihood of a probability distribution over bitstrings given data

pygsti.extras.paritybenchmarking.disturbancecalc.build_basis
class pygsti.extras.paritybenchmarking.disturbancecalc.ResidualTVD(weight, n_bits, initial_treg_factor=0.001, solver='SCS')

Computes the “weight-X residual TVD”: the TVD between two probability distributions up to weight-X transformations.

This corresponds to optimizing abs(Q - T*P) where P and Q are the two probability distributions and T is a transition matrix.

Create a ResidualTVD function object.

Parameters

weightint

The weight: all stochastic errors of this weight or below are considered “free”, i.e. contribute nothing, to this residual TVD.

n_bitsint

The number of bits (qubits).

initial_treg_factorfloat, optional

The magnitude of an internal penalty factor on the off-diagonals of the transition matrix (T), intended to eliminate unnecessarily-large T matrices which move a large proportion of probability between near-zero elements of both P and Q. You should only adjust this if you know what you’re doing.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

exactly_zero
n_bits
n
weight
dim
solver = "'SCS'"
initial_treg_factor = '0.001'
warning_msg = 'None'
t_params
P
Q
Treg_factor
build_transfer_mx(t_params=None, apply_abs=True)

Builds transition matrix from a vector of parameters

class pygsti.extras.paritybenchmarking.disturbancecalc.RegularizedDeltaLikelihood(data_p, data_q, solver='SCS')

The max - log-likelihood regularized by a “fixed-transition-matrix residual TVD”. The ‘alpha’ parameter determines the strength of the regularizaton. The objective function is:

(max_logL - logL) + alpha * fixed_T_residual_tvd

Initialize a RegularizedLikelihood function object.

Parameters

data_p, data_qnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

data_P
data_Q
solver = "'SCS'"
warning_msg = 'None'
n
p
q
T
alpha
max_logl
class pygsti.extras.paritybenchmarking.disturbancecalc.ProfileLikelihood(weight, n_bits, data_ref, data_test, solver='SCS')

The profile likelihood obtained by maximizing the likelihood on level-sets of constant weight-X residual-TVD.

ProfileLikelihood(residual_TVD) values are evaluated by optimizing the function:

alpha*ResidualTVD(p,q;weight) - log(Likelihood(p,q;data_ref,data_test))

for a fixed value of alpha, yielding a single (residual_TVD, ProfileLikelihood) point. The optimization is implemented as an alternating minimization between optimize-T (ResidualTVD) and optimize-(P,Q) (RegularizedLikelihood) steps.

Create a ProfileLikelihood function object.

Parameters

weightint

The weight: all stochastic errors of this weight or below are considered “free”, i.e. contribute nothing, to the residual TVD.

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

weight
n_bits
data_ref
data_test
solver = "'SCS'"
residual_tvd
reg_likelihood
max_logl
at_logl_value(logl_value, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, init_log10_alpha=3, verbosity=1)
at_delta_logl_value(delta_logl_value, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, init_log10_alpha=3, verbosity=1)

Compute an (x,y) = (residualTVD, ProfileLikelihood(residualTVD)) point such that ProfileLikelihood(residualTVD) is within search_tol of logl_value.

Parameters
delta_logl_valuefloat

the target profile (max - log-likelihood) value.

maxitersint, optional

The maximum number of alternating-minimization iterations to allow before giving up and deeming the final result “ok”.

search_tolfloat, optional

The tolerance used when testing whether an obtained profile delta-log-likelihood value is close enough to delta_logl_value.

reltolfloat, optional

The relative tolerance used to within the alternating minimization.

abstolfloat, optional

The absolute tolerance used to within the alternating minimization.

init_log10_alphafloat, optional

The initial log10(alpha) value to use. This shouldn’t matter except that better initial values will cause the routine to run faster.

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

Returns

residualTVD : float ProfileLikelihood(residualTVD) : float

at_2llr_value(two_llr_value, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, init_log10_alpha=3, verbosity=1)

Similar to :method:`at_delta_logl_value` except target is a 2*log-likelihood-ratio value, i.e. 2*(max_logL - logL).

at_confidence(confidence_percent, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, init_log10_alpha=3, verbosity=1)

Similar to :method:`at_logl_value` except target is a given percent confidence value, yielding a (residualTVD, ProfileLikelihood(residualTVD)) point that lies on one end of a `confidence_percent`% confidence interval of the residualTVD.

Note that confidence_percent should be a number between 0 and 100, not 0 and 1.

class pygsti.extras.paritybenchmarking.disturbancecalc.ResidualTVDWithConfidence(weight, n_bits, data_ref, data_test, solver='SCS', initial_treg_factor=0.001)

Residual TVD with error bars given by an assumed-symmetric confidence-region.

The residual TVD is computed using ResidualTVD. A confidence region is constructed by finding where the ProfileLikelihood is reduced from its maximum by an amount given by the desired confidence level. This locates one side of the confidence region, and it is assumed to be symmetric.

Create a ResidualTVDWithConfidence function object.

Parameters

weightint

The weight: all stochastic errors of this weight or below are considered “free”, i.e. contribute nothing, to this residual TVD.

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

initial_treg_factorfloat, optional

The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see ResidualTVD).

exactly_zero
residual_tvd
profile_likelihood
pML
qML
class pygsti.extras.paritybenchmarking.disturbancecalc.ProfileLikelihoodPlot(profile_likelihood, mode='auto-cr', maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, log10_alpha_values=None, num_auto_pts=10, verbosity=1)

Creates a plot of the profile log-likelihood.

Parameters

profile_likelihoodProfileLikelihood

The profile likelihood to plot

mode{“auto-cr”, “auto-fullrange”, “manual”}

How to decide what domain/range to plot. “auto-cr” plots the region of the profile likelihood relevant to finding a confidence region. “auto-fullrange” plots the entire range of log-likelihood values, from the maximum to the amount it is reduced when the residual-TVD reaches 0. “manual” lets the user specify the log10(alpha) values to use (given in the log10_alpha_values argument).

maxitersint, optional

The maximum number of alternating-minimization iterations to allow before giving up and deeming the final result “ok”.

search_tolfloat, optional

The tolerance on the log-likelihood used when trying to locate a (residualTVD, logL) pair with a particular logL.

reltolfloat, optional

The relative tolerance used to within profile likelihood.

abstolfloat, optional

The absolute tolerance used to within profile likelihood.

log10_alpha_valueslist, optional

A list of log10(alpha) values to use to determing the (x,y)=(residualTVD, logL) points to plot when mode == “manual”.

num_auto_ptsint, optional

The number of points to include in the plot when mode is “auto-cr” or “auto-fullrange”.

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

profile_likelihood
mode = "'auto-cr'"
residual_tvds = '[]'
log_likelihoods = '[]'
ps = '[]'
ts = '[]'
qs = '[]'
make_plot(xlim=None, ylim=None, figsize=(10, 7), title=None)

Creates the plot figure using matplotlib. Arguments are familiar plot variables.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_with_confidence(n_bits, data_ref, data_test, confidence_percent=68.0, max_weight=4, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, solver='SCS', initial_treg_factor=0.001, verbosity=1)

Compute the weight-X distrubances between two data sets (including error bars).

This function is computes the weight-X disturbance, defined as the difference between the weight-(X-1) and weight-X residual TVDs, (evaluated at the ML probability distributions implied by the data) for all weights up to max_weight. It also uses the data to compute `confidence_percent`% confidence intervals for each residualTVD and adds these in quadrature to arrive at error bars on each weight-X disturbance.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

confidence_percentfloat or None, optional

The confidence level desired for the computed error bars. Note that this number can range between 0 and 100, not 0 and 1. If None, then no error bars are computed.

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

maxitersint, optional

The maximum number of alternating-minimization iterations to allow within the profile-loglikelihood computation before giving up and deeming the final result “ok”.

search_tolfloat, optional

The tolerance on the log-likelihood used when trying to locate the (residualTVD, logL) pair with logL at the edge of the confidence interval.

reltolfloat, optional

The relative tolerance used to within profile likelihood.

abstolfloat, optional

The absolute tolerance used to within profile likelihood.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

initial_treg_factorfloat, optional

The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see ResidualTVD).

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

Returns

list

A list of the disturbances by weight. The lists i-th element is a (disturbance, errorbar_length) tuple for the weight (i+1) disturbance. That is, the weight (i+1) disturbance = disturbance +/- errorbar_length.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_over_tvd_ratio(n_bits, data_ref, data_test, p_ideal, return_all=False)

TODO: docstring

pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances_noconfidence(n_bits, data_ref, data_test, p_ideal, max_weight=4, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, solver='SCS', initial_treg_factor=0.001, verbosity=1)

Compute the weight-X distrubances between two data sets (including error bars).

This function is computes the weight-X OVD-corrected disturbances, defined as the scaled difference between the weight-(X-1) and weight-X residual TVDs, for all weights up to max_weight. Each difference is scaled by the ratio of the original variation distance (OVD) and the TVD, that is, multipled by r = OVD/TVD.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

p_idealnumpy array

The ideal probability distribution (of both reference and test experiments).

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

maxitersint, optional

The maximum number of alternating-minimization iterations to allow within the profile-loglikelihood computation before giving up and deeming the final result “ok”.

search_tolfloat, optional

The tolerance on the log-likelihood used when trying to locate the (residualTVD, logL) pair with logL at the edge of the confidence interval.

reltolfloat, optional

The relative tolerance used to within profile likelihood.

abstolfloat, optional

The absolute tolerance used to within profile likelihood.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

initial_treg_factorfloat, optional

The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see ResidualTVD).

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

Returns

list

A list of the OVD-corrected disturbances by weight. The lists i-th element is the weight (i+1) disturbance. The max_weight-th element is the OVD/TVD ratio.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_residual_tvds(n_bits, data_ref, data_test, confidence_percent=68.0, max_weight=4, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, solver='SCS', initial_treg_factor=0.001, verbosity=1)

Compute the weight-X residual TVDs between two data sets (including error bars).

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

confidence_percentfloat or None, optional

The confidence level desired for the computed error bars. Note that this number can range between 0 and 100, not 0 and 1. If None, then no error bars are computed.

max_weightint, optional

The maximum weight residual TVD to compute. Typically this is the same as n_bits.

maxitersint, optional

The maximum number of alternating-minimization iterations to allow within the profile-loglikelihood computation before giving up and deeming the final result “ok”.

search_tolfloat, optional

The tolerance on the log-likelihood used when trying to locate the (residualTVD, logL) pair with logL at the edge of the confidence interval.

reltolfloat, optional

The relative tolerance used to within profile likelihood.

abstolfloat, optional

The absolute tolerance used to within profile likelihood.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

initial_treg_factorfloat, optional

The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see ResidualTVD).

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

Returns

list

A list of the residual TVDs by weight. The lists i-th element is a (residual_tvd, errorbar_length) tuple for the weight (i+1) residual TVD. That is, the weight (i+1) residual TVD = residual_tvd +/- errorbar_length.

pygsti.extras.paritybenchmarking.disturbancecalc.resample_data(data, n_data_points=None, seed=None)

Sample from the ML probability distrubution of data.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_bootstrap_rawdata(n_bits, data_ref, data_test, num_bootstrap_samples=20, max_weight=4, solver='SCS', verbosity=1, seed=0, return_resampled_data=False, add_one_to_data=True)

Compute the weight-X distrubances between two data sets (including error bars).

This function is computes the weight-X disturbance, defined as the difference between the weight-(X-1) and weight-X residual TVDs, (evaluated at the ML probability distributions implied by the data) for all weights up to max_weight. It also uses the data to compute 1-sigma error bar for each value using the boostrap method.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

num_bootstrap_samplesint

The number of boostrap (re-)samples to use.

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

add_one_to_databool, optional

Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome.

Returns

disturbance_by_weight_MLnumpy.ndarray

The ML disturbances by weight (length max_weight)

bootstrap_disturbances_by_weightnumpy.ndarray

A (max_weight, num_bootstrap_samples) sized array of each disturbance computed for each of the num_bootstrap_samples re-sampled data sets.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances_bootstrap_rawdata(n_bits, data_ref, data_test, p_ideal, num_bootstrap_samples=20, max_weight=4, solver='SCS', verbosity=1, seed=0, return_resampled_data=False, add_one_to_data=True)

Compute the weight-X distrubances between two data sets (including error bars).

This function is computes the weight-X disturbance, defined as the difference between the weight-(X-1) and weight-X residual TVDs, (evaluated at the ML probability distributions implied by the data) for all weights up to max_weight. It also uses the data to compute 1-sigma error bar for each value using the boostrap method.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

p_idealnumpy array

The ideal probability distribution (of both reference and test experiments).

num_bootstrap_samplesint

The number of boostrap (re-)samples to use.

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

add_one_to_databool, optional

Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome.

Returns

disturbance_by_weight_MLnumpy.ndarray

The ML OVD-corrected disturbances by weight, with the OVD/TVD ratio tagged on at the end (so the length is max_weight + 1)

bootstrap_disturbances_by_weightnumpy.ndarray

A (max_weight + 1, num_bootstrap_samples) sized array of each disturbance and the OVD/TVD ratio (included as the final row in this matrix) for each of the num_bootstrap_samples re-sampled data sets.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_from_bootstrap_rawdata(ml_disturbances, bootstrap_disturbances, num_bootstrap_samples='all')

Compute 1-sigma error bars for a set of disturbances (given by ml_disturbances) using boostrap data.

Parameters

ml_disturbancesnumpy.ndarray

The disturbances by weight (length max_weight) for the maximum-likelhood (ML) distribution of some set of data.

bootstrap_disturbancesnumpy.ndarray

A (max_weight, num_bootstrap_samples) sized array where each column is the set of by-weight disturbances for a distribution corresponding to a re-sampled bootstrap data set.

num_bootstrap_samplesint or tuple or ‘all’

How many bootstrap samples to use when computing the boostrap error bars. This number can be less than the total number of bootstrap samples to test how using fewer boostrap samples would have performed. ‘all’ means to use all available bootstrap samples. If a tuple, then each entry should be an integer and a series of error bars is returned (instead of a single one) corresponding to using each number of samples.

Returns

list

A list of the disturbances by weight. The lists i-th element is a (disturbance, errorbar_length) tuple for the weight (i+1) disturbance. That is, the weight (i+1) disturbance = disturbance +/- errorbar_length. If num_bootstrap_samples is a tuple, then elements are instead (disturbance, errorbar_length1, errorbar_length2, …) where error bar lengths correspond to entries in num_bootstrap_samples.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances(n_bits, data_ref, data_test, num_bootstrap_samples=20, max_weight=4, solver='SCS', verbosity=1, add_one_to_data=True)

Compute the weight-X disturbances between two data sets (including error bars).

This function is computes the weight-X disturbance, defined as the difference between the weight-(X-1) and weight-X residual TVDs, (evaluated at the ML probability distributions implied by the data) for all weights up to max_weight. It also uses the data to compute 1-sigma error bar for each value using the boostrap method.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

num_bootstrap_samplesint

The number of boostrap (re-)samples to use. If 0, then error bars are not computed.

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

add_one_to_databool, optional

Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome.

Returns

list

A list of the disturbances by weight. The lists i-th element is a (disturbance, errorbar_length) tuple for the weight (i+1) disturbance. That is, the weight (i+1) disturbance = disturbance +/- errorbar_length.

pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances(n_bits, data_ref, data_test, p_ideal, num_bootstrap_samples=20, max_weight=4, solver='SCS', verbosity=1, add_one_to_data=True)

Compute the weight-X disturbances between two data sets (including error bars).

This function is computes the weight-X disturbance, defined as the difference between the weight-(X-1) and weight-X residual TVDs, (evaluated at the ML probability distributions implied by the data) for all weights up to max_weight. It also uses the data to compute 1-sigma error bar for each value using the boostrap method.

Parameters

n_bitsint

The number of bits (qubits).

data_ref, data_testnumpy array

Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string.

num_bootstrap_samplesint

The number of boostrap (re-)samples to use. If 0, then error bars are not computed.

max_weightint, optional

The maximum weight disturbance to compute. Typically this is the same as n_bits.

solverstr, optional

The name of the solver to used (see cvxpy.installed_solvers())

verbosityint, optional

Sets the level of detail for messages printed to the console (higher = more detail).

add_one_to_databool, optional

Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome.

Returns

list

A list of the disturbances by weight. The lists i-th element is a (disturbance, errorbar_length) tuple for the weight (i+1) disturbance. That is, the weight (i+1) disturbance = disturbance +/- errorbar_length. the max_weight-th element gives the OVD/TVD ratio used to correct the TVD-based disturbance values, along with its error bar.