pygsti.models.explicitcalc

Defines the ExplicitOpModelCalc class and supporting functionality.

Module Contents

Classes

ExplicitOpModelCalc

Performs calculations with explicitly-represented objects.

Attributes

P_RANK_TOL

pygsti.models.explicitcalc.P_RANK_TOL = 1e-07
class pygsti.models.explicitcalc.ExplicitOpModelCalc(dim, simplified_preps, simplified_ops, simplified_effects, np, interposer=None)

Bases: object

Performs calculations with explicitly-represented objects.

This class performs calculations with simplified objects (so don’t need to worry abount POVMs or Instruments, just preps, ops, & effects), but, unlike forward simulators, these calculations require knowledge of all of the possible operations in each category (not just the ones in a given circuti). As such, instances of ExplicitOpModelCalc are almost always associated with an instance of ExplicitOpModel.

Parameters

dimint

The dimenstion of the Hilbert-Schmidt space upon which the various operators act.

simplified_prepsdict

Dictionary containing all the possible state preparations.

simplified_opsdict

Dictionary containing all the possible layer operations.

simplified_effectsdict

Dictionary containing all the possible POVM effects.

npint

The total number of parameters in all the operators (the number of parameters of the associated ExplicitOpModel).

Initialize a new ExplicitOpModelCalc object.

Parameters

dimint

The dimenstion of the Hilbert-Schmidt space upon which the various operators act.

simplified_preps, simplified_ops, simplified_effectsdict

Dictionaries containing all the possible state preparations, layer operations, and POVM effects, respectively.

npint

The total number of parameters in all the operators (the number of parameters of the associated ExplicitOpModel).

interposerModelParamsInterposer, optional

An interposer object that converts between “operator” and “model” parameter arrays.

all_objects()

An iterator over all the state preparation, POVM effect, and layer operations.

copy()

Return a shallow copy of this ExplicitOpModelCalc

Returns

ExplicitOpModelCalc

frobeniusdist(other_calc, transform_mx=None, item_weights=None, normalize=True)

Compute the weighted frobenius norm of the difference between this calc object and other_calc.

Differences in each corresponding gate matrix and spam vector element are squared, weighted (using item_weights as applicable), then summed. The value returned is the square root of this sum, or the square root of this sum divided by the number of summands if normalize == True.

Parameters
other_calcForwardSimulator

the other gate calculator to difference against.

transform_mxnumpy array, optional

if not None, transform this model by G => inv(transform_mx) * G * transform_mx, for each operation matrix G (and similar for rho and E vectors) before taking the difference. This transformation is applied only for the difference and does not alter the values stored in this model.

item_weightsdict, optional

Dictionary of weighting factors for individual gates and spam operators. Weights are applied multiplicatively to the squared differences, i.e., (before the final square root is taken). Keys can be gate, state preparation, POVM effect, or spam labels, as well as the two special labels “gates” and “spam” which apply to all of the gate or SPAM elements, respectively (but are overridden by specific element values). Values are floating point numbers. By default, all weights are 1.0.

normalizebool, optional

if True (the default), the sum of weighted squared-differences is divided by the weighted number of differences before the final square root is taken. If False, the division is not performed.

Returns

float

residuals(other_calc, transform_mx=None, item_weights=None)

Compute the weighted residuals between two models/calcs.

Residuals are the differences in corresponding operation matrix and spam vector elements.

Parameters
other_calcForwardSimulator

the other gate calculator to difference against.

transform_mxnumpy array, optional

if not None, transform this model by G => inv(transform_mx) * G * transform_mx, for each operation matrix G (and similar for rho and E vectors) before taking the difference. This transformation is applied only for the difference and does not alter the values stored in this model.

item_weightsdict, optional

Dictionary of weighting factors for individual gates and spam operators. Weights applied such that they act multiplicatively on the squared differences, so that the residuals themselves are scaled by the square roots of these weights. Keys can be gate, state preparation, POVM effect, or spam labels, as well as the two special labels “gates” and “spam” which apply to all of the gate or SPAM elements, respectively (but are overridden by specific element values). Values are floating point numbers. By default, all weights are 1.0.

Returns
residualsnumpy.ndarray

A 1D array of residuals (differences w.r.t. other)

nSummandsint

The (weighted) number of elements accounted for by the residuals.

jtracedist(other_calc, transform_mx=None, include_spam=True)

Compute the Jamiolkowski trace distance between two models/calcs.

This is defined as the maximum of the trace distances between each corresponding gate, including spam gates.

Parameters
other_calcForwardSimulator

the other model to difference against.

transform_mxnumpy array, optional

if not None, transform this model by G => inv(transform_mx) * G * transform_mx, for each operation matrix G (and similar for rho and E vectors) before taking the difference. This transformation is applied only for the difference and does not alter the values stored in this model.

include_spambool, optional

Whether to add to the max-trace-distance the frobenius distances between corresponding SPAM vectors.

Returns

float

diamonddist(other_calc, transform_mx=None, include_spam=True)

Compute the diamond-norm distance between two models/calcs.

This is defined as the maximum of the diamond-norm distances between each corresponding gate, including spam gates.

Parameters
other_calcForwardSimulator

the other gate calculator to difference against.

transform_mxnumpy array, optional

if not None, transform this model by G => inv(transform_mx) * G * transform_mx, for each operation matrix G (and similar for rho and E vectors) before taking the difference. This transformation is applied only for the difference and does not alter the values stored in this model.

include_spambool, optional

Whether to add to the max-diamond-distance the frobenius distances between corresponding SPAM vectors.

Returns

float

deriv_wrt_params()

The element-wise derivative of all this calculator’s operations.

Constructs a matrix whose columns are the vectorized derivatives of all this calc object’s (model’s) raw matrix and vector elements (placed in a vector) with respect to each single model parameter.

Returns
numpy array

2D array of derivatives.

nongauge_and_gauge_spaces(item_weights=None, non_gauge_mix_mx=None)
nongauge_projector(item_weights=None, non_gauge_mix_mx=None)

Constructs a projector onto the non-gauge parameter space.

This is useful for isolating the gauge degrees of freedom from the non-gauge degrees of freedom.

Parameters
item_weightsdict, optional

Dictionary of weighting factors for individual gates and spam operators. Keys can be gate, state preparation, POVM effect, spam labels, or the special strings “gates” or “spam” whic represent the entire set of gate or SPAM operators, respectively. Values are floating point numbers. These weights define the metric used to compute the non-gauge space, orthogonal the gauge space, that is projected onto.

non_gauge_mix_mxnumpy array, optional

An array of shape (n_non_gauge_params,n_gauge_params) specifying how to mix the non-gauge degrees of freedom into the gauge degrees of freedom that are projected out by the returned object. This argument essentially sets the off-diagonal block of the metric used for orthogonality in the “gauge + non-gauge” space. It is for advanced usage and typically left as None (the default).

Returns
numpy array

The projection operator as a N x N matrix, where N is the number of parameters (obtained via num_params()). This projector acts on parameter-space, and has rank equal to the number of non-gauge degrees of freedom.