pygsti.modelmembers.povms.effect
¶
The POVMEffect class and supporting functionality.
Module Contents¶
Classes¶
TODO: update docstring |
- class pygsti.modelmembers.povms.effect.POVMEffect(rep, evotype)¶
Bases:
pygsti.modelmembers.modelmember.ModelMember
TODO: update docstring A parameterized state preparation OR POVM effect vector (operator).
This class is the common base class for all specific parameterizations of a POVM effect vector.
- Parameters
rep (object) – A representation object containing the core data for this spam vector.
evotype (Evotype) – The evolution type of this operator, for matching with forward simulators.
- size¶
The number of independent elements in this POVM effect vector (when viewed as a dense array).
- Type
int
- property outcomes(self)¶
The z-value outcomes corresponding to this effect POVM effect vector.
(Used in the context of a stabilizer-state simulation.)
- Returns
numpy.ndarray
- property dim(self)¶
Return the dimension of this effect (when viewed as a dense array)
- Returns
int
- property size(self)¶
Return the number of independent elements in this gate (when viewed as a dense array)
- Returns
int
- set_dense(self, vec)¶
Set the dense-vector value of this POVM effect vector.
Attempts to modify this POVM effect vector’s parameters so that the raw POVM effect vector becomes vec. Will raise ValueError if this operation is not possible.
- Parameters
vec (array_like or POVMEffect) – A numpy array representing a POVM effect vector, or a POVMEffect object.
- Returns
None
- set_time(self, t)¶
Sets the current time for a time-dependent operator.
For time-independent operators (the default), this function does absolutely nothing.
- Parameters
t (float) – The current time.
- Returns
None
- frobeniusdist_squared(self, other_spam_vec, transform=None, inv_transform=None)¶
Return the squared frobenius difference between this operation and other_spam_vec.
Optionally transforms this vector first using transform and inv_transform.
- Parameters
other_spam_vec (POVMEffect) – The other spam vector
transform (numpy.ndarray, optional) – Transformation matrix.
inv_transform (numpy.ndarray, optional) – Inverse of tranform.
- Returns
float
- residuals(self, other_spam_vec, transform=None, inv_transform=None)¶
Return a vector of residuals between this spam vector and other_spam_vec.
Optionally transforms this vector first using transform and inv_transform.
- Parameters
other_spam_vec (POVMEffect) – The other spam vector
transform (numpy.ndarray, optional) – Transformation matrix.
inv_transform (numpy.ndarray, optional) – Inverse of tranform.
- Returns
float
- transform_inplace(self, s)¶
Update POVM effect (column) vector V => s^T * V
Note that this is equivalent to the transpose of effect vectors being mapped as E^T -> E^T * s.
Generally, the transform function updates the parameters of the POVM effect vector such that the resulting vector is altered as described above. If such an update cannot be done (because the gate parameters do not allow for it), ValueError is raised.
- Parameters
s (GaugeGroupElement) – A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.
typ ({ 'prep', 'effect' }) – Which type of POVM effect vector is being transformed (see above).
- Returns
None
- property num_params(self)¶
Get the number of independent parameters which specify this POVM effect vector.
- Returns
int – the number of independent parameters.
- to_vector(self)¶
Get the POVM effect vector parameters as an array of values.
- Returns
numpy array – The parameters as a 1D array with length num_params().
- from_vector(self, v, close=False, dirty_value=True)¶
Initialize the POVM effect vector using a 1D array of parameters.
- Parameters
v (numpy array) – The 1D vector of POVM effect vector parameters. Length must == num_params()
close (bool, optional) – Whether v is close to this POVM effect vector’s current set of parameters. Under some circumstances, when this is true this call can be completed more quickly.
dirty_value (bool, optional) – The value to set this object’s “dirty flag” to before exiting this call. This is passed as an argument so it can be updated recursively. Leave this set to True unless you know what you’re doing.
- Returns
None
- deriv_wrt_params(self, wrt_filter=None)¶
The element-wise derivative this POVM effect vector.
Construct a matrix whose columns are the derivatives of the POVM effect vector with respect to a single param. Thus, each column is of length dimension and there is one column per POVM effect vector parameter.
- Parameters
wrt_filter (list or numpy.ndarray) – List of parameter indices to take derivative with respect to. (None means to use all the this operation’s parameters.)
- Returns
numpy array – Array of derivatives, shape == (dimension, num_params)
- has_nonzero_hessian(self)¶
Whether this POVM effect vector has a non-zero Hessian with respect to its parameters.
- Returns
bool
- hessian_wrt_params(self, wrt_filter1=None, wrt_filter2=None)¶
Construct the Hessian of this POVM effect vector with respect to its parameters.
This function returns a tensor whose first axis corresponds to the flattened operation matrix and whose 2nd and 3rd axes correspond to the parameters that are differentiated with respect to.
- Parameters
wrt_filter1 (list or numpy.ndarray) – List of parameter indices to take 1st derivatives with respect to. (None means to use all the this operation’s parameters.)
wrt_filter2 (list or numpy.ndarray) – List of parameter indices to take 2nd derivatives with respect to. (None means to use all the this operation’s parameters.)
- Returns
numpy array – Hessian with shape (dimension, num_params1, num_params2)
- abstract taylor_order_terms(self, order, max_polynomial_vars=100, return_coeff_polys=False)¶
Get the order-th order Taylor-expansion terms of this effect vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank-1”, meaning that it is a state preparation followed by or POVM effect preceded by actions on a density matrix rho of the form:
rho -> A rho B
The coefficients of these terms are typically polynomials of the State’s parameters, where the polynomial’s variable indices index the global parameters of the State’s parent (usually a
Model
) , not the State’s local parameter array (i.e. that returned from to_vector).- Parameters
order (int) – The order of terms to get.
max_polynomial_vars (int, optional) – maximum number of variables the created polynomials can have.
return_coeff_polys (bool) – Whether a parallel list of locally-indexed (using variable indices corresponding to this object’s parameters rather than its parent’s) polynomial coefficients should be returned as well.
- Returns
terms (list) – A list of
RankOneTerm
objects.coefficients (list) – Only present when return_coeff_polys == True. A list of compact polynomial objects, meaning that each element is a (vtape,ctape) 2-tuple formed by concatenating together the output of :method:`Polynomial.compact`.
- highmagnitude_terms(self, min_term_mag, force_firstorder=True, max_taylor_order=3, max_polynomial_vars=100)¶
Get terms with magnitude above min_term_mag.
Get the terms (from a Taylor expansion of this state vector) that have magnitude above min_term_mag (the magnitude of a term is taken to be the absolute value of its coefficient), considering only those terms up to some maximum Taylor expansion order, max_taylor_order.
Note that this function also sets the magnitudes of the returned terms (by calling term.set_magnitude(…)) based on the current values of this state vector’s parameters. This is an essential step to using these terms in pruned-path-integral calculations later on.
- Parameters
min_term_mag (float) – the threshold for term magnitudes: only terms with magnitudes above this value are returned.
force_firstorder (bool, optional) – if True, then always return all the first-order Taylor-series terms, even if they have magnitudes smaller than min_term_mag. This behavior is needed for using GST with pruned-term calculations, as we may begin with a guess model that has no error (all terms have zero magnitude!) and still need to compute a meaningful jacobian at this point.
max_taylor_order (int, optional) – the maximum Taylor-order to consider when checking whether term- magnitudes exceed min_term_mag.
max_polynomial_vars (int, optional) – maximum number of variables the created polynomials can have.
- Returns
highmag_terms (list) – A list of the high-magnitude terms that were found. These terms are sorted in descending order by term-magnitude.
first_order_indices (list) – A list of the indices into highmag_terms that mark which of these terms are first-order Taylor terms (useful when we’re forcing these terms to always be present).
- taylor_order_terms_above_mag(self, order, max_polynomial_vars, min_term_mag)¶
Get the order-th order Taylor-expansion terms of this state vector that have magnitude above min_term_mag.
This function constructs the terms at the given order which have a magnitude (given by the absolute value of their coefficient) that is greater than or equal to min_term_mag. It calls :method:`taylor_order_terms` internally, so that all the terms at order order are typically cached for future calls.
- Parameters
order (int) – The order of terms to get.
max_polynomial_vars (int, optional) – maximum number of variables the created polynomials can have.
min_term_mag (float) – the minimum term magnitude.
- Returns
list