pygsti.models.explicitcalc
¶
Defines the ExplicitOpModelCalc class and supporting functionality.
Module Contents¶
Classes¶
Performs calculations with explicitly-represented objects. |
Attributes¶
- 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
dim (int) – The dimenstion 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
).
- all_objects(self)¶
An iterator over all the state preparation, POVM effect, and layer operations.
- copy(self)¶
Return a shallow copy of this ExplicitOpModelCalc
- Returns
ExplicitOpModelCalc
- frobeniusdist(self, 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, 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 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.
- Returns
float
- residuals(self, 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.
- jtracedist(self, 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.
- Returns
float
- diamonddist(self, 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.
- Returns
float
- deriv_wrt_params(self)¶
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.
- _buildup_dpg(self)¶
- Helper function for building gauge/non-gauge projectors and
for computing the number of gauge/non-gauge elements.
Returns the [ dP | dG ] matrix, i.e. np.concatenate( (dP,dG), axis=1 ) whose nullspace gives the gauge directions in parameter space.
- nongauge_projector(self, 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” 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_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
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.