pygsti.models.explicitcalc.ExplicitOpModelCalc#
- class ExplicitOpModelCalc(dim, simplified_preps, simplified_ops, simplified_effects, np, interposer=None)#
Bases:
objectPerforms calculations with explicitly-represented objects.
This class performs calculations with simplified objects (so don’t need to worry about 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:
dim (int) – The dimension of the Hilbert-Schmidt space upon which the various operators act.
simplified_preps (dict) – Dictionary containing all the possible state preparations.
simplified_ops (dict) – Dictionary containing all the possible layer operations.
simplified_effects (dict) – Dictionary containing all the possible POVM effects.
np (int) – The total number of parameters in all the operators (the number of parameters of the associated
ExplicitOpModel).
Initialize a new ExplicitOpModelCalc object.
- Parameters:
dim (int) – The dimension of the Hilbert-Schmidt space upon which the various operators act.
simplified_preps (dict) – Dictionaries containing all the possible state preparations, layer operations, and POVM effects, respectively.
simplified_ops (dict) – Dictionaries containing all the possible state preparations, layer operations, and POVM effects, respectively.
simplified_effects (dict) – Dictionaries containing all the possible state preparations, layer operations, and POVM effects, respectively.
np (int) – The total number of parameters in all the operators (the number of parameters of the associated
ExplicitOpModel).interposer (ModelParamsInterposer, optional) – An interposer object that converts between “operator” and “model” parameter arrays.
Methods
__init__(dim, simplified_preps, ...[, ...])Initialize a new ExplicitOpModelCalc object.
An iterator over all the state preparation, POVM effect, and layer operations.
copy()Return a shallow copy of this ExplicitOpModelCalc
The element-wise derivative of all this calculator's operations.
diamonddist(other_calc[, transform_mx, ...])Compute the diamond-norm distance between two models/calcs.
frobeniusdist(other_calc[, transform_mx, ...])Compute the weighted frobenius norm of the difference between this calc object and other_calc.
jtracedist(other_calc[, transform_mx, ...])Compute the Jamiolkowski trace distance between two models/calcs.
nongauge_and_gauge_spaces([item_weights, ...])nongauge_projector([item_weights, ...])Constructs a projector onto the non-gauge parameter space.
residuals(other_calc[, transform_mx, ...])Compute the weighted residuals between two models/calcs.
- all_objects()#
An iterator over all the state preparation, POVM effect, and layer operations.
- copy()#
Return a shallow copy of this ExplicitOpModelCalc
- Return type:
- 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:
2D array of derivatives.
- Return type:
numpy array
- 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_calc (ForwardSimulator) – the other gate calculator to difference against.
transform_mx (numpy 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_spam (bool, optional) – Whether to add to the max-diamond-distance the frobenius distances between corresponding SPAM vectors.
- Return type:
float
- 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_calc (ForwardSimulator) – the other gate calculator to difference against.
transform_mx (numpy array or tuple, optional) –
If transform_mx is a numpy array, then for each operation matrix G we implicitly consider the transformed quantity
G => inv(transform_mx) * G * transform_mx
Similar transformations are applied for effect vectors. This transformation is applied only for the difference and does not alter the values stored in this model.
If transform_mx is a tuple, then its first entry should be a numpy ndarray that will be interpreted as transform_mx in the usual sense, and its second entry will be syntactically substituted for inv(transform_mx).
item_weights (dict, 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.
normalize (bool, 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.
- Return type:
float
- 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_calc (ForwardSimulator) – the other model to difference against.
transform_mx (numpy 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_spam (bool, optional) – Whether to add to the max-trace-distance the frobenius distances between corresponding SPAM vectors.
- Return type:
float
- 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_weights (dict, 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” which 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_mx (numpy 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:
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.
- Return type:
numpy array
- 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_calc (ForwardSimulator) – the other gate calculator to difference against.
transform_mx (numpy 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_weights (dict, 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:
residuals (numpy.ndarray) – A 1D array of residuals (differences w.r.t. other)
nSummands (int) – The (weighted) number of elements accounted for by the residuals.