:py:mod:`pygsti.extras.paritybenchmarking.disturbancecalc` ========================================================== .. py:module:: pygsti.extras.paritybenchmarking.disturbancecalc Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pygsti.extras.paritybenchmarking.disturbancecalc.ResidualTVD pygsti.extras.paritybenchmarking.disturbancecalc.RegularizedDeltaLikelihood pygsti.extras.paritybenchmarking.disturbancecalc.ProfileLikelihood pygsti.extras.paritybenchmarking.disturbancecalc.ResidualTVDWithConfidence pygsti.extras.paritybenchmarking.disturbancecalc.ProfileLikelihoodPlot Functions ~~~~~~~~~ .. autoapisummary:: pygsti.extras.paritybenchmarking.disturbancecalc.default_cvxpy_args pygsti.extras.paritybenchmarking.disturbancecalc.remove_kicked pygsti.extras.paritybenchmarking.disturbancecalc.print_revert_msg pygsti.extras.paritybenchmarking.disturbancecalc.unit_vector pygsti.extras.paritybenchmarking.disturbancecalc.matrix_units pygsti.extras.paritybenchmarking.disturbancecalc.multikron pygsti.extras.paritybenchmarking.disturbancecalc.interior_tensor_product pygsti.extras.paritybenchmarking.disturbancecalc.swell_slow pygsti.extras.paritybenchmarking.disturbancecalc.swell pygsti.extras.paritybenchmarking.disturbancecalc.n_matrices_per_weight pygsti.extras.paritybenchmarking.disturbancecalc.n_parameters_per_matrix pygsti.extras.paritybenchmarking.disturbancecalc.n_parameters pygsti.extras.paritybenchmarking.disturbancecalc.transition_matrix pygsti.extras.paritybenchmarking.disturbancecalc.comprehensive_transition_matrix pygsti.extras.paritybenchmarking.disturbancecalc.nlogp pygsti.extras.paritybenchmarking.disturbancecalc.log_likelihood pygsti.extras.paritybenchmarking.disturbancecalc.max_log_likelihood pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_with_confidence pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_over_tvd_ratio pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances_noconfidence pygsti.extras.paritybenchmarking.disturbancecalc.compute_residual_tvds pygsti.extras.paritybenchmarking.disturbancecalc.resample_data pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_bootstrap_rawdata pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances_bootstrap_rawdata pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances_from_bootstrap_rawdata pygsti.extras.paritybenchmarking.disturbancecalc.compute_disturbances pygsti.extras.paritybenchmarking.disturbancecalc.compute_ovd_corrected_disturbances Attributes ~~~~~~~~~~ .. autoapisummary:: pygsti.extras.paritybenchmarking.disturbancecalc.REBUILD pygsti.extras.paritybenchmarking.disturbancecalc.REVERT_MSG_THRESHOLD pygsti.extras.paritybenchmarking.disturbancecalc.MAX_RESIDUAL_TVD_REDUCTION_PER_ITER pygsti.extras.paritybenchmarking.disturbancecalc.OBJ_CHK_TOL pygsti.extras.paritybenchmarking.disturbancecalc.ZERO_RTVD_THRESHOLD pygsti.extras.paritybenchmarking.disturbancecalc.CONSTRAINT_ZERO pygsti.extras.paritybenchmarking.disturbancecalc.default_cvxpy_solver_args pygsti.extras.paritybenchmarking.disturbancecalc.build_basis .. py:data:: REBUILD :value: 'True' .. py:data:: REVERT_MSG_THRESHOLD :value: '10.0' .. py:data:: MAX_RESIDUAL_TVD_REDUCTION_PER_ITER :value: '0.3' .. py:data:: OBJ_CHK_TOL :value: '1e-06' .. py:data:: ZERO_RTVD_THRESHOLD :value: '1e-05' .. py:data:: CONSTRAINT_ZERO :value: '0.0' .. py:data:: default_cvxpy_solver_args .. py:function:: default_cvxpy_args(solver) .. py:function:: remove_kicked(s) .. py:function:: print_revert_msg(formatted_str, tup, verbosity) .. py:function:: unit_vector(a, b) Returns the unit vector of length 'b' with the 'a'th element = 1 .. py:function:: matrix_units(dim) Returns a list of all matrix units of dimension `dim` .. py:function:: multikron(a) Kronecker product of all the elements of `a` .. py:function:: 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 .. py:function:: swell_slow(mx, which_bits, n_bits=4) .. py:function:: swell(mx, which_bits, n_bits=4) .. py:function:: n_matrices_per_weight(weight, n_bits) The number of submatrices there are for `weight` .. py:function:: n_parameters_per_matrix(weight, n_bits) The number of parameters needed to define a weight-w transition submatrix on `n_bits` .. py:function:: n_parameters(weight, n_bits) The number of parameters needed to define a complete weight-w transition matrix .. py:function:: 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 .. py:function:: comprehensive_transition_matrix(v, weight, n_bits) Build a generic weight-n transition_matrix .. py:function:: nlogp(n, p) n*log(p) such that if n == 0 the product is 0 too .. py:function:: log_likelihood(data, probs) Compute log likelihood of a probability distribution over bitstrings given data .. py:function:: max_log_likelihood(data) Compute log likelihood of a probability distribution over bitstrings given data .. py:data:: build_basis .. py:class:: 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 ---------- weight : int The weight: all stochastic errors of this weight or below are considered "free", i.e. contribute nothing, to this residual TVD. n_bits : int The number of bits (qubits). initial_treg_factor : float, 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. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) .. py:attribute:: exactly_zero .. py:attribute:: n_bits .. py:attribute:: n .. py:attribute:: weight .. py:attribute:: dim .. py:attribute:: solver :value: "'SCS'" .. py:attribute:: initial_treg_factor :value: '0.001' .. py:attribute:: warning_msg :value: 'None' .. py:attribute:: t_params .. py:attribute:: P .. py:attribute:: Q .. py:attribute:: Treg_factor .. py:method:: build_transfer_mx(t_params=None, apply_abs=True) Builds transition matrix from a vector of parameters .. py:class:: 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_q : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) .. py:attribute:: data_P .. py:attribute:: data_Q .. py:attribute:: solver :value: "'SCS'" .. py:attribute:: warning_msg :value: 'None' .. py:attribute:: n .. py:attribute:: p .. py:attribute:: q .. py:attribute:: T .. py:attribute:: alpha .. py:attribute:: max_logl .. py:class:: 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 ---------- weight : int The weight: all stochastic errors of this weight or below are considered "free", i.e. contribute nothing, to the residual TVD. n_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) .. py:attribute:: weight .. py:attribute:: n_bits .. py:attribute:: data_ref .. py:attribute:: data_test .. py:attribute:: solver :value: "'SCS'" .. py:attribute:: residual_tvd .. py:attribute:: reg_likelihood .. py:attribute:: max_logl .. py:method:: at_logl_value(logl_value, maxiters=20, search_tol=0.1, reltol=1e-05, abstol=1e-05, init_log10_alpha=3, verbosity=1) .. py:method:: 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_value : float the target profile (max - log-likelihood) value. maxiters : int, optional The maximum number of alternating-minimization iterations to allow before giving up and deeming the final result "ok". search_tol : float, optional The tolerance used when testing whether an obtained profile delta-log-likelihood value is close enough to `delta_logl_value`. reltol : float, optional The relative tolerance used to within the alternating minimization. abstol : float, optional The absolute tolerance used to within the alternating minimization. init_log10_alpha : float, optional The initial log10(alpha) value to use. This shouldn't matter except that better initial values will cause the routine to run faster. verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). Returns ------- residualTVD : float ProfileLikelihood(residualTVD) : float .. py:method:: 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). .. py:method:: 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. .. py:class:: 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 :class:`ResidualTVD`. A confidence region is constructed by finding where the :class:`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 ---------- weight : int The weight: all stochastic errors of this weight or below are considered "free", i.e. contribute nothing, to this residual TVD. n_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) initial_treg_factor : float, optional The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see :class:`ResidualTVD`). .. py:attribute:: exactly_zero .. py:attribute:: residual_tvd .. py:attribute:: profile_likelihood .. py:attribute:: pML .. py:attribute:: qML .. py:class:: 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_likelihood : ProfileLikelihood 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). maxiters : int, optional The maximum number of alternating-minimization iterations to allow before giving up and deeming the final result "ok". search_tol : float, optional The tolerance on the log-likelihood used when trying to locate a (residualTVD, logL) pair with a particular logL. reltol : float, optional The relative tolerance used to within profile likelihood. abstol : float, optional The absolute tolerance used to within profile likelihood. log10_alpha_values : list, optional A list of log10(alpha) values to use to determing the (x,y)=(residualTVD, logL) points to plot when `mode == "manual"`. num_auto_pts : int, optional The number of points to include in the plot when `mode` is "auto-cr" or "auto-fullrange". verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). .. py:attribute:: profile_likelihood .. py:attribute:: mode :value: "'auto-cr'" .. py:attribute:: residual_tvds :value: '[]' .. py:attribute:: log_likelihoods :value: '[]' .. py:attribute:: ps :value: '[]' .. py:attribute:: ts :value: '[]' .. py:attribute:: qs :value: '[]' .. py:method:: make_plot(xlim=None, ylim=None, figsize=(10, 7), title=None) Creates the plot figure using matplotlib. Arguments are familiar plot variables. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. confidence_percent : float 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_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. maxiters : int, 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_tol : float, 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. reltol : float, optional The relative tolerance used to within profile likelihood. abstol : float, optional The absolute tolerance used to within profile likelihood. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) initial_treg_factor : float, optional The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see :class:`ResidualTVD`). verbosity : int, 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`. .. py:function:: compute_ovd_over_tvd_ratio(n_bits, data_ref, data_test, p_ideal, return_all=False) TODO: docstring .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. p_ideal : numpy array The ideal probability distribution (of both reference and test experiments). max_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. maxiters : int, 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_tol : float, 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. reltol : float, optional The relative tolerance used to within profile likelihood. abstol : float, optional The absolute tolerance used to within profile likelihood. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) initial_treg_factor : float, optional The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see :class:`ResidualTVD`). verbosity : int, 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. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. confidence_percent : float 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_weight : int, optional The maximum weight residual TVD to compute. Typically this is the same as `n_bits`. maxiters : int, 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_tol : float, 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. reltol : float, optional The relative tolerance used to within profile likelihood. abstol : float, optional The absolute tolerance used to within profile likelihood. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) initial_treg_factor : float, optional The magnitude of an internal penalty factor on the off-diagonals of the T matrix (see :class:`ResidualTVD`). verbosity : int, 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`. .. py:function:: resample_data(data, n_data_points=None, seed=None) Sample from the ML probability distrubution of `data`. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy 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_samples : int The number of boostrap (re-)samples to use. max_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). add_one_to_data : bool, optional Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome. Returns ------- disturbance_by_weight_ML : numpy.ndarray The ML disturbances by weight (length `max_weight`) bootstrap_disturbances_by_weight : numpy.ndarray A (max_weight, num_bootstrap_samples) sized array of each disturbance computed for each of the `num_bootstrap_samples` re-sampled data sets. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy array Arrays of outcome counts from the reference and test experiments, respectively. Each array has one element per 2^n_bits bit string. p_ideal : numpy array The ideal probability distribution (of both reference and test experiments). num_bootstrap_samples : int The number of boostrap (re-)samples to use. max_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). add_one_to_data : bool, optional Sets whether the bootstrap should be calculated after adding a single fake count to every possible outcome. Returns ------- disturbance_by_weight_ML : numpy.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_weight : numpy.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. .. py:function:: 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_disturbances : numpy.ndarray The disturbances by weight (length `max_weight`) for the maximum-likelhood (ML) distribution of some set of data. bootstrap_disturbances : numpy.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_samples : int 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`. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy 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_samples : int The number of boostrap (re-)samples to use. If 0, then error bars are not computed. max_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). add_one_to_data : bool, 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`. .. py:function:: 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_bits : int The number of bits (qubits). data_ref, data_test : numpy 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_samples : int The number of boostrap (re-)samples to use. If 0, then error bars are not computed. max_weight : int, optional The maximum weight disturbance to compute. Typically this is the same as `n_bits`. solver : str, optional The name of the solver to used (see `cvxpy.installed_solvers()`) verbosity : int, optional Sets the level of detail for messages printed to the console (higher = more detail). add_one_to_data : bool, 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.