pygsti.modelmembers.povms
¶
Subpackage holding model POVM and POVM effect objects.
Submodules¶
pygsti.modelmembers.povms.basepovm
pygsti.modelmembers.povms.complementeffect
pygsti.modelmembers.povms.composedeffect
pygsti.modelmembers.povms.composedpovm
pygsti.modelmembers.povms.computationaleffect
pygsti.modelmembers.povms.computationalpovm
pygsti.modelmembers.povms.conjugatedeffect
pygsti.modelmembers.povms.denseeffect
pygsti.modelmembers.povms.effect
pygsti.modelmembers.povms.fulleffect
pygsti.modelmembers.povms.fullpureeffect
pygsti.modelmembers.povms.marginalizedpovm
pygsti.modelmembers.povms.povm
pygsti.modelmembers.povms.staticeffect
pygsti.modelmembers.povms.staticpureeffect
pygsti.modelmembers.povms.tensorprodeffect
pygsti.modelmembers.povms.tensorprodpovm
pygsti.modelmembers.povms.tppovm
pygsti.modelmembers.povms.unconstrainedpovm
Package Contents¶
Classes¶
TODO: docstring 

TODO: update docstring 

TODO: update docstring 

A static POVM effect that is tensor product of 1qubit Zeigenstates. 

A POVM that "measures" states in the computational "Z" basis. 

TODO: update docstring 

TODO: update docstring 

A "fully parameterized" effect vector where each element is an independent parameter. 

TODO: docstring 

A POVM whose effects are the sums of sets of effect vectors in a parent POVM. 

A generalized positive operatorvalued measure (POVM). 

A POVM effect vector that is completely fixed, or "static" (i.e. that posesses no parameters). 

TODO: docstring 

A state vector that is a tensorproduct of other state vectors. 

A POVM that is effectively the tensor product of several other POVMs (which can be TP). 

A POVM whose sumofeffects is constrained to what, by definition, we call the "identity". 

A POVM that just holds a set of effect vectors, parameterized individually however you want. 
Functions¶

TODO: docstring  create a POVM from a list/dict of (key, purevector) pairs 

TODO: docstring  create a POVM from a list/dict of (key, purevector) pairs 

TODO: docstring  create a State from a state vector 



Decode an op type into an appropriate povm type. 

Convert a POVM to a new type of parameterization. 

TODO: update docstring 

Optimize the parameters of vec_to_optimize. 
 class pygsti.modelmembers.povms.ComplementPOVMEffect(identity, other_effects)¶
Bases:
pygsti.modelmembers.povms.conjugatedeffect.ConjugatedStatePOVMEffect
TODO: docstring A POVM effect vector that ensures that all the effects of a POVM sum to the identity.
This POVM effect vector is paramterized as I  sum(other_spam_vecs) where I is a (static) identity element and other_param_vecs is a list of other spam vectors in the same parent
POVM
. This only partially implements the modelmember interface (some methods such as to_vector and from_vector will thunk down to base class versions which raise NotImplementedError), as instances are meant to be contained within aPOVM
which takes care of vectorization. Parameters
identity (array_like or POVMEffect) – a 1D numpy array representing the static identity operation from which the sum of the other vectors is subtracted.
other_spamvecs (list of POVMEffects) – A list of the “other” parameterized POVM effect vectors which are subtracted from identity to compute the final value of this “complement” POVM effect vector.
 _construct_vector(self)¶
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 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 elementwise 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 nonzero Hessian with respect to its parameters.
 Returns
bool
 class pygsti.modelmembers.povms.ComposedPOVMEffect(static_effect, errormap)¶
Bases:
pygsti.modelmembers.povms.effect.POVMEffect
TODO: update docstring A Lindbladparameterized POVMEffect (that is also expandable into terms).
 Parameters
pure_vec (numpy array or POVMEffect) –
An array or POVMEffect in the full densitymatrix space (this vector will have dimension 4 in the case of a single qubit) which represents a purestate preparation or projection. This is used as the “base” preparation or projection that is followed or preceded by, respectively, the parameterized Lindbladform error generator. (This argument is not copied if it is a POVMEffect. A numpy array
is converted to a new static POVM effect.)
errormap (MapOperator) – The error generator action and parameterization, encapsulated in a gate object. Usually a
LindbladOp
orComposedOp
object. (This argument is not copied, to allow ComposedPOVMEffects to share error generator parameters with other gates and spam vectors.)
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 property size(self)¶
Return the number of independent elements in this gate (when viewed as a dense array)
 Returns
int
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 set_gpindices(self, gpindices, parent, memo=None)¶
Set the parent and indices into the parent’s parameter vector that are used by this ModelMember object.
 Parameters
gpindices (slice or integer ndarray) – The indices of this objects parameters in its parent’s array.
parent (Model or ModelMember) – The parent whose parameter array gpindices references.
memo (dict, optional) – A memo dict used to avoid circular references.
 Returns
None
 to_dense(self, on_space='minimal', scratch=None)¶
Return this POVM effect vector as a (dense) numpy array.
The memory in scratch maybe used when it is notNone.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
scratch (numpy.ndarray, optional) – scratch space available for use.
 Returns
numpy.ndarray
 taylor_order_terms(self, order, max_polynomial_vars=100, return_coeff_polys=False)¶
Get the orderth order Taylorexpansion terms of this POVM effect vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank1”, 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 POVMEffect’s parameters, where the polynomial’s variable indices index the global parameters of the POVMEffect’s parent (usually a
Model
) , not the POVMEffect’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 locallyindexed (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) 2tuple formed by concatenating together the output of :method:`Polynomial.compact`.
 taylor_order_terms_above_mag(self, order, max_polynomial_vars, min_term_mag)¶
Get the orderth order Taylorexpansion terms of this POVM effect 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
 property total_term_magnitude(self)¶
Get the total (sum) of the magnitudes of all this POVM effect vector’s terms.
The magnitude of a term is the absolute value of its coefficient, so this function returns the number you’d get from summing up the absolutecoefficients of all the Taylor terms (at all orders!) you get from expanding this POVM effect vector in a Taylor series.
 Returns
float
 property total_term_magnitude_deriv(self)¶
The derivative of the sum of all this POVM effect vector’s terms.
Get the derivative of the total (sum) of the magnitudes of all this POVM effect vector’s terms with respect to the operators (local) parameters.
 Returns
numpy array – An array of length self.num_params
 deriv_wrt_params(self, wrt_filter=None)¶
The elementwise 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)
 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)
 property parameter_labels(self)¶
An array of labels (usually strings) describing this model member’s parameters.
 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)¶
Extract a vector of the underlying gate parameters from this gate.
 Returns
numpy array – a 1D numpy 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
 transform_inplace(self, s)¶
Update POVM effect (column) vector V as inv(s) * V or s^T * V
Note that this is equivalent to state preparation vectors getting mapped: rho > inv(s) * rho and 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.
 Returns
None
 depolarize(self, amount)¶
Depolarize this POVM effect vector by the given amount.
Generally, the depolarize function updates the parameters of the POVMEffect such that the resulting vector is depolarized. If such an update cannot be done (because the gate parameters do not allow for it), ValueError is raised.
 Parameters
amount (float or tuple) – The amount to depolarize by. If a tuple, it must have length equal to one less than the dimension of the spam vector. All but the first element of the spam vector (often corresponding to the identity element) are multiplied by amount (if a float) or the corresponding amount[i] (if a tuple).
 Returns
None
 class pygsti.modelmembers.povms.ComposedPOVM(errormap, povm=None, mx_basis=None)¶
Bases:
pygsti.modelmembers.povms.povm.POVM
TODO: update docstring A POVM that is effectively a single Lindbladparameterized gate followed by a computationalbasis POVM.
 Parameters
errormap (MapOperator) – The error generator action and parameterization, encapsulated in a gate object. Usually a
LindbladOp
orComposedOp
object. (This argument is not copied, to allow ComposedPOVMEffects to share error generator parameters with other gates and spam vectors.)povm (POVM, optional) – A subPOVM which supplies the set of “reference” effect vectors that errormap acts on to produce the final effect vectors of this LindbladPOVM. This POVM must be static (have zero parameters) and its evolution type must match that of errormap. If None, then a
ComputationalBasisPOVM
is used on the number of qubits appropriate to errormap’s dimension.mx_basis ({'std', 'gm', 'pp', 'qt'} or Basis object) – The basis for this spam vector. Allowed values are Matrixunit (std), GellMann (gm), Pauliproduct (pp), and Qutrit (qt) (or a custom basis object). If None, then this is extracted (if possible) from errormap.
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 __contains__(self, key)¶
For lazy creation of effect vectors
 __iter__(self)¶
Implement iter(self).
 __len__(self)¶
Return len(self).
 keys(self)¶
An iterator over the effect (outcome) labels of this POVM.
 values(self)¶
An iterator over the effect effect vectors of this POVM.
 items(self)¶
An iterator over the (effect_label, effect_vector) items in this POVM.
 __getitem__(self, key)¶
For lazy creation of effect vectors
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 set_gpindices(self, gpindices, parent, memo=None)¶
Set the parent and indices into the parent’s parameter vector that are used by this ModelMember object.
 Parameters
gpindices (slice or integer ndarray) – The indices of this objects parameters in its parent’s array.
parent (Model or ModelMember) – The parent whose parameter array gpindices references.
memo (dict, optional) – A memo dict used to avoid circular references.
 Returns
None
 simplify_effects(self, prefix='')¶
Creates a dictionary of simplified effect vectors.
Returns a dictionary of effect POVMEffects that belong to the POVM’s parent Model  that is, whose gpindices are set to all or a subset of this POVM’s gpindices. Such effect vectors are used internally within computations involving the parent Model.
 Parameters
prefix (str) – A string, usually identitying this POVM, which may be used to prefix the simplified gate keys.
 Returns
OrderedDict of POVMEffects
 property parameter_labels(self)¶
An array of labels (usually strings) describing this model member’s parameters.
 property num_params(self)¶
Get the number of independent parameters which specify this POVM.
 Returns
int – the number of independent parameters.
 to_vector(self)¶
Extract a vector of the underlying gate parameters from this POVM.
 Returns
numpy array – a 1D numpy array with length == num_params().
 from_vector(self, v, close=False, dirty_value=True)¶
Initialize this POVM using a vector of its parameters.
 Parameters
v (numpy array) – The 1D vector of POVM parameters. Length must == num_params().
close (bool, optional) – Whether v is close to this POVM’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
 transform_inplace(self, s)¶
Update each POVM effect E as s^T * E.
Note that this is equivalent to the transpose of the effect vectors being mapped as E^T > E^T * s.
 Parameters
s (GaugeGroupElement) – A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.
 Returns
None
 depolarize(self, amount)¶
Depolarize this POVM by the given amount.
 Parameters
amount (float or tuple) – The amount to depolarize by. If a tuple, it must have length equal to one less than the dimension of the gate. All but the first element of each spam vector (often corresponding to the identity element) are multiplied by amount (if a float) or the corresponding amount[i] (if a tuple).
 Returns
None
 __str__(self)¶
Return str(self).
 errorgen_coefficient_labels(self)¶
The elementary errorgenerator labels corresponding to the elements of :method:`errorgen_coefficients_array`.
 Returns
tuple – A tuple of (<type>, <basisEl1> [,<basisEl2]) elements identifying the elementary error generators of this gate.
 errorgen_coefficients_array(self)¶
The weighted coefficients of this POVM’s error generator in terms of “standard” error generators.
Constructs a 1D array of all the coefficients returned by :method:`errorgen_coefficients`, weighted so that different error generators can be weighted differently when a errorgen_penalty_factor is used in an objective function.
 Returns
numpy.ndarray – A 1D array of length equal to the number of coefficients in the linear combination of standard error generators that is this state preparation’s error generator.
 errorgen_coefficients(self, return_basis=False, logscale_nonham=False)¶
Constructs a dictionary of the Lindbladerrorgenerator coefficients of this POVM.
Note that these are not necessarily the parameter values, as these coefficients are generally functions of the parameters (so as to keep the coefficients positive, for instance).
 Parameters
return_basis (bool, optional) – Whether to also return a
Basis
containing the elements with which the error generator terms were constructed.logscale_nonham (bool, optional) – Whether or not the nonhamiltonian error generator coefficients should be scaled so that the returned dict contains: (1  exp(d^2 * coeff)) / d^2 instead of coeff. This essentially converts the coefficient into a rate that is the contribution this term would have within a depolarizing channel where all stochastic generators had this same coefficient. This is the value returned by :method:`error_rates`.
 Returns
lindblad_term_dict (dict) – Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify offdiagonal nonHamiltonian Lindblad terms. Basis labels are integers starting at 0. Values are complex coefficients.
basis (Basis) – A Basis mapping the basis labels used in the keys of lindblad_term_dict to basis matrices.
 set_errorgen_coefficients(self, lindblad_term_dict, action='update', logscale_nonham=False, truncate=True)¶
Sets the coefficients of terms in the error generator of this POVM.
The dictionary lindblad_term_dict has tuplekeys describing the type of term and the basis elements used to construct it, e.g. (‘H’,’X’).
 Parameters
lindblad_term_dict (dict) – Keys are (termType, basisLabel1, <basisLabel2>) tuples, where termType is “H” (Hamiltonian), “S” (Stochastic), or “A” (Affine). Hamiltonian and Affine terms always have a single basis label (so key is a 2tuple) whereas Stochastic tuples have 1 basis label to indicate a diagonal term and otherwise have 2 basis labels to specify offdiagonal nonHamiltonian Lindblad terms. Values are the coefficients of these error generators, and should be real except for the 2basislabel case.
action ({"update","add","reset"}) – How the values in lindblad_term_dict should be combined with existing errorgenerator coefficients.
logscale_nonham (bool, optional) – Whether or not the values in lindblad_term_dict for nonhamiltonian error generators should be interpreted as error rates (of an “equivalent” depolarizing channel, see :method:`errorgen_coefficients`) instead of raw coefficients. If True, then the nonhamiltonian coefficients are set to log(1  d^2*rate)/d^2, where rate is the corresponding value given in lindblad_term_dict. This is what is performed by the function :method:`set_error_rates`.
truncate (bool, optional) – Whether to allow adjustment of the errogen coefficients in order to meet constraints (e.g. to preserve CPTP) when necessary. If False, then an error is thrown when the given coefficients cannot be set as specified.
 Returns
None
 errorgen_coefficients_array_deriv_wrt_params(self)¶
The jacobian of :method:`errogen_coefficients_array` with respect to this POVM’s parameters.
 Returns
numpy.ndarray – A 2D array of shape (num_coeffs, num_params) where num_coeffs is the number of coefficients of this operation’s error generator and num_params is this operation’s number of parameters.
 class pygsti.modelmembers.povms.ComputationalBasisPOVMEffect(zvals, basis='pp', evotype='default', state_space=None)¶
Bases:
pygsti.modelmembers.povms.effect.POVMEffect
A static POVM effect that is tensor product of 1qubit Zeigenstates.
This is called a “computational basis state” in many contexts.
 Parameters
zvals (iterable) – A list or other iterable of integer 0 or 1 outcomes specifying which computational basis element this object represents. The length of zvals gives the total number of qubits.
basis (Basis or {'pp','gm','std'}, optional) – The basis used to construct the HilbertSchmidt space representation of this state as a superket.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.
 classmethod from_state_vector(cls, vec, basis='pp', evotype='default', state_space=None)¶
Create a new ComputationalBasisPOVMEffect from a dense vector.
 Parameters
vec (numpy.ndarray) – A state vector specifying a computational basis state in the standard basis. This vector has length 4^n for n qubits.
basis (Basis or {'pp','gm','std'}, optional) – The basis of vec as a superket.
evotype (Evotype or str, optional) – The evolution type of the resulting effect vector. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.
 Returns
ComputationalBasisPOVMEffect
 classmethod from_pure_vector(cls, purevec, basis='pp', evotype='default', state_space=None)¶
TODO: update docstring Create a new StabilizerEffectVec from a purestate vector.
Currently, purevec must be a single computational basis state (it cannot be a superpostion of multiple of them).
 Parameters
purevec (numpy.ndarray) – A complexvalued state vector specifying a pure state in the standard computational basis. This vector has length 2^n for n qubits.
basis (Basis or {'pp','gm','std'}, optional) – The basis of vec as a superket.
evotype (Evotype or str, optional) – The evolution type of the resulting effect vector. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.
 Returns
ComputationalBasisPOVMEffect
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 to_dense(self, on_space='minimal', scratch=None)¶
Return this POVM effect vector as a (dense) numpy array.
The memory in scratch maybe used when it is notNone.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
scratch (numpy.ndarray, optional) – scratch space available for use.
 Returns
numpy.ndarray
 taylor_order_terms(self, order, max_polynomial_vars=100, return_coeff_polys=False)¶
Get the orderth order Taylorexpansion terms of this POVM effect vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank1”, 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 POVMEffect’s parameters, where the polynomial’s variable indices index the global parameters of the POVMEffect’s parent (usually a
Model
) , not the POVMEffect’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 locallyindexed (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) 2tuple formed by concatenating together the output of :method:`Polynomial.compact`.
 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
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.ComputationalBasisPOVM(nqubits, evotype='default', qubit_filter=None, state_space=None)¶
Bases:
pygsti.modelmembers.povms.povm.POVM
A POVM that “measures” states in the computational “Z” basis.
 Parameters
nqubits (int) – The number of qubits
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
qubit_filter (list, optional) – An optional list of integers specifying a subset of the qubits to be measured.
state_space (StateSpace, optional) – The state space for this POVM. If None a default state space with the appropriate number of qubits is used.
 classmethod from_pure_vectors(cls, pure_vectors, evotype, state_space)¶
 __contains__(self, key)¶
For lazy creation of effect vectors
 __iter__(self)¶
Implement iter(self).
 __len__(self)¶
Return len(self).
 keys(self)¶
An iterator over the effect (outcome) labels of this POVM.
 values(self)¶
An iterator over the effect vectors of this POVM.
 items(self)¶
An iterator over the (effect_label, effect_vector) items in this POVM.
 __getitem__(self, key)¶
For lazy creation of effect vectors
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 simplify_effects(self, prefix='')¶
Creates a dictionary of simplified effect vectors.
Returns a dictionary of effect POVMEffects that belong to the POVM’s parent Model  that is, whose gpindices are set to all or a subset of this POVM’s gpindices. Such effect vectors are used internally within computations involving the parent Model.
 Parameters
prefix (str) – A string, usually identitying this POVM, which may be used to prefix the simplified gate keys.
 Returns
OrderedDict of POVMEffects
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.ConjugatedStatePOVMEffect(state)¶
Bases:
DenseEffectInterface
,pygsti.modelmembers.povms.effect.POVMEffect
TODO: update docstring A POVM effect vector that behaves like a numpy array.
This class is the common base class for parameterizations of an effect vector that have a dense representation and can be accessed like a numpy array.
 Parameters
vec (numpy.ndarray) – The POVM effect vector as a dense numpy array.
evotype ({"statevec", "densitymx"}) – The evolution type.
 _base_1d¶
Direct access to the underlying 1D array.
 Type
numpy.ndarray
 base¶
Direct access the the underlying data as column vector, i.e, a (dim,1)shaped array.
 Type
numpy.ndarray
 property parameter_labels(self)¶
An array of labels (usually strings) describing this model member’s parameters.
 to_dense(self, on_space='minimal', scratch=None)¶
Return this POVM effect vector as a (dense) numpy array.
The memory in scratch maybe used when it is notNone.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
scratch (numpy.ndarray, optional) – scratch space available for use.
 Returns
numpy.ndarray
 property _ptr(self)¶
 _ptr_has_changed(self)¶
Derived classes should override this function to handle rep updates when the _ptr property is changed.
 property size(self)¶
Return the number of independent elements in this gate (when viewed as a dense array)
 Returns
int
 __str__(self)¶
Return str(self).
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 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 elementwise 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 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 nonzero 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)
 taylor_order_terms(self, order, max_polynomial_vars=100, return_coeff_polys=False)¶
Get the orderth order Taylorexpansion terms of this state vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank1”, 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 locallyindexed (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) 2tuple formed by concatenating together the output of :method:`Polynomial.compact`.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 class pygsti.modelmembers.povms.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 zvalue outcomes corresponding to this effect POVM effect vector.
(Used in the context of a stabilizerstate 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 densevector 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 timedependent operator.
For timeindependent 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 elementwise 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 nonzero 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 orderth order Taylorexpansion terms of this effect vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank1”, 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 locallyindexed (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) 2tuple 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 prunedpathintegral 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 firstorder Taylorseries terms, even if they have magnitudes smaller than min_term_mag. This behavior is needed for using GST with prunedterm 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 Taylororder 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 highmagnitude terms that were found. These terms are sorted in descending order by termmagnitude.
first_order_indices (list) – A list of the indices into highmag_terms that mark which of these terms are firstorder 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 orderth order Taylorexpansion 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
 class pygsti.modelmembers.povms.FullPOVMEffect(vec, evotype='default', state_space=None)¶
Bases:
pygsti.modelmembers.povms.conjugatedeffect.ConjugatedStatePOVMEffect
A “fully parameterized” effect vector where each element is an independent parameter.
 Parameters
vec (array_like or POVMEffect) – a 1D numpy array representing the POVM effect. The shape of this array sets the dimension of the POVM effect.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this POVM effect. If None a default state space with the appropriate number of qubits is used.
 set_dense(self, vec)¶
Set the densevector 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
 depolarize(self, amount)¶
Depolarize this effect vector (as though it were a states) by the given amount.
 Parameters
amount (float or tuple) – The amount to depolarize by. If a tuple, it must have length equal to one less than the dimension of the gate. All but the first element of the spam vector (often corresponding to the identity element) are multiplied by amount (if a float) or the corresponding amount[i] (if a tuple).
 Returns
None
 class pygsti.modelmembers.povms.FullPOVMPureEffect(vec, basis='pp', evotype='default', state_space=None)¶
Bases:
pygsti.modelmembers.povms.conjugatedeffect.ConjugatedStatePOVMEffect
TODO: docstring A “fully parameterized” effect vector where each element is an independent parameter.
 Parameters
vec (array_like or POVMEffect) – a 1D numpy array representing the POVM effect. The shape of this array sets the dimension of the POVM effect.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
 set_dense(self, vec)¶
Set the densevector 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
 class pygsti.modelmembers.povms.MarginalizedPOVM(povm_to_marginalize, all_sslbls, sslbls_after_marginalizing)¶
Bases:
pygsti.modelmembers.povms.povm.POVM
A POVM whose effects are the sums of sets of effect vectors in a parent POVM.
Namely the effects of the parent POVN whose labels have the same character at certain “marginalized” indices are summed together.
 Parameters
povm_to_marginalize (POVM) – The POVM to marginalize (the “parent” POVM).
all_sslbls (StateSpaceLabels or tuple) – The state space labels of the parent POVM, which should have as many labels (factors) as the parent POVM’s outcome/effect labels have characters.
sslbls_after_marginalizing (tuple) – The subset of all_sslbls that should be kept after marginalizing.
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 marginalize_effect_label(self, elbl)¶
Removes the “marginalized” characters from elbl, resulting in a marginalized POVM effect label.
 Parameters
elbl (str) – Effect label (typically of the parent POVM) to marginalize.
 __contains__(self, key)¶
For lazy creation of effect vectors
 __iter__(self)¶
Implement iter(self).
 __len__(self)¶
Return len(self).
 keys(self)¶
An iterator over the effect (outcome) labels of this POVM.
 values(self)¶
An iterator over the effect POVM effect vectors of this POVM.
 items(self)¶
An iterator over the (effect_label, effect_vector) items in this POVM.
 __getitem__(self, key)¶
For lazy creation of effect vectors
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 simplify_effects(self, prefix='')¶
Creates a dictionary of simplified effect vectors.
Returns a dictionary of effect POVMEffects that belong to the POVM’s parent Model  that is, whose gpindices are set to all or a subset of this POVM’s gpindices. Such effect vectors are used internally within computations involving the parent Model.
 Parameters
prefix (str) – A string, usually identitying this POVM, which may be used to prefix the simplified gate keys.
 Returns
OrderedDict of POVMEffects
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.POVM(state_space, evotype, items=[])¶
Bases:
pygsti.modelmembers.modelmember.ModelMember
,collections.OrderedDict
A generalized positive operatorvalued measure (POVM).
Meant to correspond to a positive operatorvalued measure, in theory, this class generalizes that notion slightly to include a collection of effect vectors that may or may not have all of the properties associated by a mathematical POVM.
 Parameters
state_space (StateSpace) – The state space of this POVM (and of the effect vectors).
evotype (Evotype) – The evolution type.
items (list or dict, optional) – Initial values. This should only be used internally in deserialization.
 __setitem__(self, key, value)¶
Set self[key] to value.
 __pygsti_reduce__(self)¶
 property num_params(self)¶
Get the number of independent parameters which specify this POVM.
 Returns
int – the number of independent parameters.
 to_vector(self)¶
Extract a vector of the underlying gate parameters from this POVM.
 Returns
numpy array – a 1D numpy array with length == num_params().
 from_vector(self, v, close=False, dirty_value=True)¶
Initialize this POVM using a vector of its parameters.
 Parameters
v (numpy array) – The 1D vector of POVM parameters. Length must == num_params().
close (bool, optional) – Whether v is close to this POVM’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
 set_time(self, t)¶
Sets the current time for a timedependent operator.
For timeindependent operators (the default), this function does absolutely nothing.
 Parameters
t (float) – The current time.
 Returns
None
 transform_inplace(self, s)¶
Update each POVM effect E as s^T * E.
Note that this is equivalent to the transpose of the effect vectors being mapped as E^T > E^T * s.
 Parameters
s (GaugeGroupElement) – A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.
 Returns
None
 depolarize(self, amount)¶
Depolarize this POVM by the given amount.
 Parameters
amount (float or tuple) – The amount to depolarize by. If a tuple, it must have length equal to one less than the dimension of the gate. All but the first element of each spam vector (often corresponding to the identity element) are multiplied by amount (if a float) or the corresponding amount[i] (if a tuple).
 Returns
None
 property num_elements(self)¶
Return the number of total spam vector elements in this povm.
This is in general different from the number of parameters, which are the number of free variables used to generate all of the vector elements.
 Returns
int
 acton(self, state)¶
Compute the outcome probabilities the result from acting on state with this POVM.
 Parameters
state (State) – The state to act on
 Returns
OrderedDict – A dictionary whose keys are the outcome labels (strings) and whose values are the probabilities of seeing each outcome.
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.StaticPOVMEffect(vec, evotype='default', state_space=None)¶
Bases:
pygsti.modelmembers.povms.conjugatedeffect.ConjugatedStatePOVMEffect
A POVM effect vector that is completely fixed, or “static” (i.e. that posesses no parameters).
 Parameters
vec (array_like or POVMEffect) – a 1D numpy array representing the POVM effect. The shape of this array sets the dimension of the POVM effect.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.
 set_dense(self, vec)¶
Set the densevector 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
 class pygsti.modelmembers.povms.StaticPOVMPureEffect(vec, basis='pp', evotype='default', state_space=None)¶
Bases:
pygsti.modelmembers.povms.conjugatedeffect.ConjugatedStatePOVMEffect
TODO: docstring A state vector that is completely fixed, or “static” (i.e. that posesses no parameters).
 Parameters
vec (array_like or POVMEffect) – a 1D numpy array representing the state. The shape of this array sets the dimension of the state.
basis (Basis or {'pp','gm','std'}, optional) – The basis used to construct the HilbertSchmidt space representation of this state as a superbra.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.
state_space (StateSpace, optional) – The state space for this operation. If None a default state space with the appropriate number of qubits is used.
 class pygsti.modelmembers.povms.TensorProductPOVMEffect(factors, povm_effect_lbls, state_space)¶
Bases:
pygsti.modelmembers.povms.effect.POVMEffect
A state vector that is a tensorproduct of other state vectors.
 Parameters
factors (list of POVMs) – a list of “reference” POVMs into which povm_effect_lbls indexes.
povm_effect_lbls (arraylike) – The effect label of each factor POVM which is tensored together to form this effect vector.
state_space (StateSpace, optional) – The state space for this operation.
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 property parameter_labels(self)¶
An array of labels (usually strings) describing this model member’s parameters.
 to_dense(self, on_space='minimal', scratch=None)¶
Return this POVM effect vector as a (dense) numpy array.
The memory in scratch maybe used when it is notNone.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
scratch (numpy.ndarray, optional) – scratch space available for use.
 Returns
numpy.ndarray
 taylor_order_terms(self, order, max_polynomial_vars=100, return_coeff_polys=False)¶
Get the orderth order Taylorexpansion terms of this POVM effect vector.
This function either constructs or returns a cached list of the terms at the given order. Each term is “rank1”, 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 POVMEffect’s parameters, where the polynomial’s variable indices index the global parameters of the POVMEffect’s parent (usually a
Model
) , not the POVMEffect’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 locallyindexed (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) 2tuple formed by concatenating together the output of :method:`Polynomial.compact`.
 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 elementwise 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 nonzero Hessian with respect to its parameters.
 Returns
bool
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.TensorProductPOVM(factor_povms, evotype='auto', state_space=None)¶
Bases:
pygsti.modelmembers.povms.povm.POVM
A POVM that is effectively the tensor product of several other POVMs (which can be TP).
 Parameters
factor_povms (list of POVMs) – POVMs that will be tensorproducted together.
evotype (Evotype or str, optional) – The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype. The special value “auto” uses the evolution type of the first factor if there are more than zero factors.
state_space (StateSpace, optional) – The state space for this POVM. This should be a space description compatible with the product of all the factors’ state spaces. If None a default compatible space will be chosen.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 submembers(self)¶
Get the ModelMemberderived objects contained in this one.
 Returns
list
 __contains__(self, key)¶
For lazy creation of effect vectors
 __iter__(self)¶
Implement iter(self).
 __len__(self)¶
Return len(self).
 keys(self)¶
An iterator over the effect (outcome) labels of this POVM.
 values(self)¶
An iterator over the effect SPAM vectors of this POVM.
 items(self)¶
An iterator over the (effect_label, effect_vector) items in this POVM.
 __getitem__(self, key)¶
For lazy creation of effect vectors
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 simplify_effects(self, prefix='')¶
Creates a dictionary of simplified effect vectors.
Returns a dictionary of effect POVMEffects that belong to the POVM’s parent Model  that is, whose gpindices are set to all or a subset of this POVM’s gpindices. Such effect vectors are used internally within computations involving the parent Model.
 Parameters
prefix (str) – A string, usually identitying this POVM, which may be used to prefix the simplified gate keys.
 Returns
OrderedDict of POVMEffects
 property parameter_labels(self)¶
An array of labels (usually strings) describing this model member’s parameters.
 property num_params(self)¶
Get the number of independent parameters which specify this POVM.
 Returns
int – the number of independent parameters.
 to_vector(self)¶
Extract a vector of the underlying gate parameters from this POVM.
 Returns
numpy array – a 1D numpy array with length == num_params().
 from_vector(self, v, close=False, dirty_value=True)¶
Initialize this POVM using a vector of its parameters.
 Parameters
v (numpy array) – The 1D vector of POVM parameters. Length must == num_params().
close (bool, optional) – Whether v is close to this POVM’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
 depolarize(self, amount)¶
Depolarize this POVM by the given amount.
 Parameters
amount (float or tuple) – The amount to depolarize by. If a tuple, it must have length equal to one less than the dimension of the gate. All but the first element of each spam vector (often corresponding to the identity element) are multiplied by amount (if a float) or the corresponding amount[i] (if a tuple).
 Returns
None
 __str__(self)¶
Return str(self).
 class pygsti.modelmembers.povms.TPPOVM(effects, evotype=None, state_space=None)¶
Bases:
pygsti.modelmembers.povms.basepovm._BasePOVM
A POVM whose sumofeffects is constrained to what, by definition, we call the “identity”.
 Parameters
effects (dict of POVMEffects or arraylike) – A dict (or list of key,value pairs) of the effect vectors. The final effect vector will be stripped of any existing parameterization and turned into a ComplementPOVMEffect which has no additional parameters and is always equal to identity  sum(other_effects, where identity is the sum of effects when this __init__ call is made.
evotype (Evotype or str, optional) – The evolution type. If None, the evotype is inferred from the first effect vector. If len(effects) == 0 in this case, an error is raised.
state_space (StateSpace, optional) – The state space for this POVM. If None, the space is inferred from the first effect vector. If len(effects) == 0 in this case, an error is raised.
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 class pygsti.modelmembers.povms.UnconstrainedPOVM(effects, evotype=None, state_space=None)¶
Bases:
pygsti.modelmembers.povms.basepovm._BasePOVM
A POVM that just holds a set of effect vectors, parameterized individually however you want.
 Parameters
effects (dict of POVMEffects or arraylike) – A dict (or list of key,value pairs) of the effect vectors.
evotype (Evotype or str, optional) – The evolution type. If None, the evotype is inferred from the first effect vector. If len(effects) == 0 in this case, an error is raised.
state_space (StateSpace, optional) – The state space for this POVM. If None, the space is inferred from the first effect vector. If len(effects) == 0 in this case, an error is raised.
 __reduce__(self)¶
Needed for OrderedDictderived classes (to set dict items)
 pygsti.modelmembers.povms.create_from_pure_vectors(pure_vectors, povm_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn')¶
TODO: docstring – create a POVM from a list/dict of (key, purevector) pairs
 pygsti.modelmembers.povms.create_from_dmvecs(superket_vectors, povm_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn')¶
TODO: docstring – create a POVM from a list/dict of (key, purevector) pairs
 pygsti.modelmembers.povms.create_effect_from_pure_vector(pure_vector, effect_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn')¶
TODO: docstring – create a State from a state vector
 pygsti.modelmembers.povms.create_effect_from_dmvec(superket_vector, effect_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn')¶
 pygsti.modelmembers.povms.povm_type_from_op_type(op_type)¶
Decode an op type into an appropriate povm type.
 pygsti.modelmembers.povms.convert(povm, to_type, basis, extra=None)¶
Convert a POVM to a new type of parameterization.
This potentially creates a new object. Raises ValueError for invalid conversions.
 Parameters
povm (POVM) – POVM to convert
to_type ({"full","full TP","static","static unitary","H+S terms",) – “H+S clifford terms”,”clifford”} The type of parameterizaton to convert to. See :method:`Model.set_all_parameterizations` for more details. TODO docstring: update the options here.
basis ({'std', 'gm', 'pp', 'qt'} or Basis object) – The basis for povm. Allowed values are Matrixunit (std), GellMann (gm), Pauliproduct (pp), and Qutrit (qt) (or a custom basis object).
extra (object, optional) – Unused.
 Returns
POVM – The converted POVM vector, usually a distinct object from the object passed as input.
 pygsti.modelmembers.povms.convert_effect(effect, to_type, basis, extra=None)¶
TODO: update docstring Convert POVM effect vector to a new type of parameterization.
This potentially creates a new POVMEffect object. Raises ValueError for invalid conversions.
 Parameters
effect (POVMEffect) – POVM effect vector to convert
to_type ({"full","TP","static","static unitary","clifford",LINDBLAD}) – The type of parameterizaton to convert to. “LINDBLAD” is a placeholder for the various Lindblad parameterization types. See :method:`Model.set_all_parameterizations` for more details.
basis ({'std', 'gm', 'pp', 'qt'} or Basis object) – The basis for spamvec. Allowed values are Matrixunit (std), GellMann (gm), Pauliproduct (pp), and Qutrit (qt) (or a custom basis object).
extra (object, optional) – Additional information for conversion.
 Returns
POVMEffect – The converted POVM effect vector, usually a distinct object from the object passed as input.
 pygsti.modelmembers.povms.optimize_effect(vec_to_optimize, target_vec)¶
Optimize the parameters of vec_to_optimize.
The optimization is performed so that the the resulting POVM effect is as close as possible to target_vec.
 Parameters
vec_to_optimize (POVMEffect) – The effect vector to optimize. This object gets altered.
target_vec (POVMEffect) – The effect vector used as the target.
 Returns
None