:py:mod:`pygsti.modelmembers.povms` =================================== .. py:module:: pygsti.modelmembers.povms .. autoapi-nested-parse:: Sub-package holding model POVM and POVM effect objects. Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 basepovm/index.rst complementeffect/index.rst composedeffect/index.rst composedpovm/index.rst computationaleffect/index.rst computationalpovm/index.rst conjugatedeffect/index.rst effect/index.rst fulleffect/index.rst fullpureeffect/index.rst marginalizedpovm/index.rst povm/index.rst staticeffect/index.rst staticpureeffect/index.rst tensorprodeffect/index.rst tensorprodpovm/index.rst tppovm/index.rst unconstrainedpovm/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: pygsti.modelmembers.povms.ComplementPOVMEffect pygsti.modelmembers.povms.ComposedPOVMEffect pygsti.modelmembers.povms.ComposedPOVM pygsti.modelmembers.povms.ComputationalBasisPOVMEffect pygsti.modelmembers.povms.ComputationalBasisPOVM pygsti.modelmembers.povms.ConjugatedStatePOVMEffect pygsti.modelmembers.povms.POVMEffect pygsti.modelmembers.povms.FullPOVMEffect pygsti.modelmembers.povms.FullPOVMPureEffect pygsti.modelmembers.povms.MarginalizedPOVM pygsti.modelmembers.povms.POVM pygsti.modelmembers.povms.StaticPOVMEffect pygsti.modelmembers.povms.StaticPOVMPureEffect pygsti.modelmembers.povms.TensorProductPOVMEffect pygsti.modelmembers.povms.TensorProductPOVM pygsti.modelmembers.povms.TPPOVM pygsti.modelmembers.povms.UnconstrainedPOVM pygsti.modelmembers.povms.Basis Functions ~~~~~~~~~ .. autoapisummary:: pygsti.modelmembers.povms.sum_of_negative_choi_eigenvalues_gate pygsti.modelmembers.povms.create_from_pure_vectors pygsti.modelmembers.povms.create_from_dmvecs pygsti.modelmembers.povms.create_effect_from_pure_vector pygsti.modelmembers.povms.create_effect_from_dmvec pygsti.modelmembers.povms.povm_type_from_op_type pygsti.modelmembers.povms.convert pygsti.modelmembers.povms.convert_effect pygsti.modelmembers.povms.optimize_effect .. py:class:: ComplementPOVMEffect(identity, other_effects, called_from_reduce=False) Bases: :py:obj:`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 :class:`POVM`. This only *partially* implements the model-member 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 a :class:`POVM` 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. Initialize a new POVM effect Vector .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:attribute:: identity .. py:attribute:: other_effects .. py:method:: to_memoized_dict(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. .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: to_vector() Get the POVM effect vector parameters as an array of values. Returns ------- numpy array The parameters as a 1D array with length num_params(). .. py:method:: from_vector(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 .. py:method:: deriv_wrt_params(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) .. py:method:: has_nonzero_hessian() Whether this POVM effect vector has a non-zero Hessian with respect to its parameters. Returns ------- bool .. py:class:: ComposedPOVMEffect(static_effect, errormap) Bases: :py:obj:`pygsti.modelmembers.povms.effect.POVMEffect` TODO: update docstring A Lindblad-parameterized POVMEffect (that is also expandable into terms). Parameters ---------- pure_vec : numpy array or POVMEffect An array or POVMEffect in the *full* density-matrix space (this vector will have dimension 4 in the case of a single qubit) which represents a pure-state preparation or projection. This is used as the "base" preparation or projection that is followed or preceded by, respectively, the parameterized Lindblad-form 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 :class:`LindbladOp` or :class:`ComposedOp` object. (This argument is *not* copied, to allow ComposedPOVMEffects to share error generator parameters with other gates and spam vectors.) Initialize a new POVM effect Vector .. py:property:: hilbert_schmidt_size Return the number of independent elements in this effect as a dense Hilbert-Schmidt super-bra. Returns ------- int .. py:property:: total_term_magnitude 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 absolute-coefficients of all the Taylor terms (at all orders!) you get from expanding this POVM effect vector in a Taylor series. Returns ------- float .. py:property:: total_term_magnitude_deriv 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 .. py:property:: parameter_labels An array of labels (usually strings) describing this model member's parameters. .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:attribute:: effect_vec .. py:attribute:: error_map .. py:attribute:: terms .. py:attribute:: local_term_poly_coeffs .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: set_gpindices(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 .. py:method:: to_dense(on_space: pygsti.SpaceT = 'minimal', scratch=None) Return this POVM effect vector as a (dense) numpy array. The memory in `scratch` maybe used when it is not-None. 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 super-bra/super-ket 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 .. py:method:: taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False) Get the `order`-th order Taylor-expansion 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 "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 POVMEffect's parameters, where the polynomial's variable indices index the *global* parameters of the POVMEffect's parent (usually a :class:`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 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 :class:`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 :meth:`Polynomial.compact`. .. py:method:: taylor_order_terms_above_mag(order, max_polynomial_vars, min_term_mag) Get the `order`-th order Taylor-expansion 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 :meth:`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 .. py:method:: deriv_wrt_params(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) .. py:method:: hessian_wrt_params(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) .. py:method:: to_vector() Extract a vector of the underlying gate parameters from this gate. Returns ------- numpy array a 1D numpy array with length == num_params(). .. py:method:: from_vector(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 .. py:method:: transform_inplace(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 .. py:method:: depolarize(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 .. py:class:: ComposedPOVM(errormap, povm=None, mx_basis=None) Bases: :py:obj:`pygsti.modelmembers.povms.povm.POVM` TODO: update docstring A POVM that is effectively a *single* Lindblad-parameterized gate followed by a computational-basis POVM. Parameters ---------- errormap : MapOperator The error generator action and parameterization, encapsulated in a gate object. Usually a :class:`LindbladOp` or :class:`ComposedOp` object. (This argument is *not* copied, to allow ComposedPOVMEffects to share error generator parameters with other gates and spam vectors.) povm : POVM, optional A sub-POVM 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 :class:`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 Matrix-unit (std), Gell-Mann (gm), Pauli-product (pp), and Qutrit (qt) (or a custom basis object). If None, then this is extracted (if possible) from `errormap`. Creates a new LindbladPOVM object. Parameters ---------- errormap : MapOperator The error generator action and parameterization, encapsulated in a gate object. Usually a :class:`LindbladOp` or :class:`ComposedOp` object. (This argument is *not* copied, to allow ComposedPOVMEffects to share error generator parameters with other gates and spam vectors.) povm : POVM, optional A sub-POVM 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 :class:`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 Matrix-unit (std), Gell-Mann (gm), Pauli-product (pp), and Qutrit (qt) (or a custom basis object). If None, then this is extracted (if possible) from `errormap`. .. py:property:: parameter_labels An array of labels (usually strings) describing this model member's parameters. .. py:property:: num_params Get the number of independent parameters which specify this POVM. Returns ------- int the number of independent parameters. .. py:attribute:: error_map .. py:attribute:: matrix_basis .. py:attribute:: base_povm :value: 'None' .. py:method:: to_memoized_dict(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. .. py:method:: keys() An iterator over the effect (outcome) labels of this POVM. .. py:method:: values() An iterator over the effect effect vectors of this POVM. .. py:method:: items() An iterator over the (effect_label, effect_vector) items in this POVM. .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: set_gpindices(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 .. py:method:: simplify_effects(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 .. py:method:: to_vector() Extract a vector of the underlying gate parameters from this POVM. Returns ------- numpy array a 1D numpy array with length == num_params(). .. py:method:: from_vector(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 .. py:method:: transform_inplace(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 .. py:method:: depolarize(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 .. py:method:: errorgen_coefficient_labels(label_type='global') The elementary error-generator labels corresponding to the elements of :meth:`errorgen_coefficients_array`. Parameters ---------- label_type : str, optional (default 'global') String specifying which type of `ElementaryErrorgenLabel` to use as the keys for the returned dictionary. Allowed options are 'global' for `GlobalElementaryErrorgenLabel` and 'local' for `LocalElementaryErrorgenLabel`. Returns ------- tuple A tuple of (, [,)` 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 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a *diagonal* term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian 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. .. py:method:: set_errorgen_coefficients(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 tuple-keys 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, )` 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 2-tuple) whereas Stochastic tuples have 1 basis label to indicate a *diagonal* term and otherwise have 2 basis labels to specify off-diagonal non-Hamiltonian Lindblad terms. Values are the coefficients of these error generators, and should be real except for the 2-basis-label case. action : {"update","add","reset"} How the values in `lindblad_term_dict` should be combined with existing error-generator coefficients. logscale_nonham : bool, optional Whether or not the values in `lindblad_term_dict` for non-hamiltonian error generators should be interpreted as error *rates* (of an "equivalent" depolarizing channel, see :meth:`errorgen_coefficients`) instead of raw coefficients. If True, then the non-hamiltonian 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 :meth:`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 .. py:method:: errorgen_coefficients_array_deriv_wrt_params() The jacobian of :meth:`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. .. py:class:: ComputationalBasisPOVMEffect(zvals, basis='pp', evotype='default', state_space=None) Bases: :py:obj:`pygsti.modelmembers.povms.effect.POVMEffect` A static POVM effect that is tensor product of 1-qubit Z-eigenstates. 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 Hilbert-Schmidt space representation of this state as a super-ket. 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. Initialize a new POVM effect Vector .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:method:: from_state_vector(vec, basis='pp', evotype='default', state_space=None) :classmethod: 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 super-ket. 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 .. py:method:: from_pure_vector(purevec, basis='pp', evotype='default', state_space=None) :classmethod: TODO: update docstring Create a new StabilizerEffectVec from a pure-state vector. Currently, purevec must be a single computational basis state (it cannot be a superpostion of multiple of them). Parameters ---------- purevec : numpy.ndarray A complex-valued 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 super-ket. 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 .. py:method:: to_memoized_dict(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. .. py:method:: to_dense(on_space: pygsti.SpaceT = 'minimal', scratch=None) Return this POVM effect vector as a (dense) numpy array. The memory in `scratch` maybe used when it is not-None. 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 super-bra/super-ket 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 .. py:method:: taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False) Get the `order`-th order Taylor-expansion 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 "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 POVMEffect's parameters, where the polynomial's variable indices index the *global* parameters of the POVMEffect's parent (usually a :class:`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 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 :class:`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 :meth:`Polynomial.compact`. .. py:method:: to_vector() Get the POVM effect vector parameters as an array of values. Returns ------- numpy array The parameters as a 1D array with length num_params(). .. py:method:: from_vector(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 .. py:class:: ComputationalBasisPOVM(nqubits, evotype='default', qubit_filter=None, state_space=None) Bases: :py:obj:`pygsti.modelmembers.povms.povm.POVM`, :py:obj:`pygsti.modelmembers.errorgencontainer.NoErrorGeneratorInterface` 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. Initialize a new ModelMember .. py:attribute:: nqubits .. py:attribute:: qubit_filter :value: 'None' .. py:method:: from_pure_vectors(pure_vectors, evotype, state_space) :classmethod: .. py:method:: keys() An iterator over the effect (outcome) labels of this POVM. .. py:method:: values() An iterator over the effect vectors of this POVM. .. py:method:: items() An iterator over the (effect_label, effect_vector) items in this POVM. .. py:method:: simplify_effects(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 .. py:method:: to_memoized_dict(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. .. py:class:: ConjugatedStatePOVMEffect(state, called_from_reduce=False) Bases: :py:obj:`DenseEffectInterface`, :py:obj:`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. Attributes ---------- _base_1d : numpy.ndarray Direct access to the underlying 1D array. base : numpy.ndarray Direct access the the underlying data as column vector, i.e, a (dim,1)-shaped array. Initialize a new POVM effect Vector .. py:property:: parameter_labels An array of labels (usually strings) describing this model member's parameters. .. py:property:: hilbert_schmidt_size Return the number of independent elements in this effect as a dense Hilbert-Schmidt super-bra. Returns ------- int .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:attribute:: state .. py:method:: to_dense(on_space: pygsti.SpaceT = 'minimal', scratch=None) Return this POVM effect vector as a (dense) numpy array. The memory in `scratch` maybe used when it is not-None. 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 super-bra/super-ket 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 .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: to_vector() Get the POVM effect vector parameters as an array of values. Returns ------- numpy array The parameters as a 1D array with length num_params(). .. py:method:: from_vector(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 .. py:method:: deriv_wrt_params(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 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) .. py:method:: has_nonzero_hessian() Whether this POVM effect vector has a non-zero Hessian with respect to its parameters. Returns ------- bool .. py:method:: hessian_wrt_params(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) .. py:method:: taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False) Get the `order`-th order Taylor-expansion terms of this state 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 :class:`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 :class:`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 :meth:`Polynomial.compact`. .. py:class:: POVMEffect(rep, evotype) Bases: :py:obj:`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. Attributes ---------- size : int The number of independent elements in this POVM effect vector (when viewed as a dense array). Initialize a new POVM effect Vector .. py:property:: outcomes :abstractmethod: The z-value outcomes corresponding to this effect POVM effect vector. (Used in the context of a stabilizer-state simulation.) Returns ------- numpy.ndarray .. py:property:: dim Return the dimension of this effect (when viewed as a dense array) Returns ------- int .. py:property:: hilbert_schmidt_size Return the number of independent elements in this effect as a dense Hilbert-Schmidt super-bra. Returns ------- int .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:method:: set_dense(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 .. py:method:: set_time(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 .. py:method:: transform_inplace(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 .. py:method:: to_vector() Get the POVM effect vector parameters as an array of values. Returns ------- numpy array The parameters as a 1D array with length num_params(). .. py:method:: from_vector(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 .. py:method:: deriv_wrt_params(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) .. py:method:: has_nonzero_hessian() Whether this POVM effect vector has a non-zero Hessian with respect to its parameters. Returns ------- bool .. py:method:: hessian_wrt_params(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) .. py:method:: taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False) :abstractmethod: 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 :class:`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 :class:`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 :meth:`Polynomial.compact`. .. py:method:: highmagnitude_terms(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). .. py:method:: taylor_order_terms_above_mag(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 :meth:`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 .. py:class:: FullPOVMEffect(vec, basis=None, evotype='default', state_space=None) Bases: :py:obj:`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. Initialize a new POVM effect Vector .. py:method:: set_dense(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 .. py:method:: depolarize(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 .. py:class:: FullPOVMPureEffect(vec, basis='pp', evotype='default', state_space=None) Bases: :py:obj:`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`. Initialize a new POVM effect Vector .. py:method:: set_dense(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 .. py:class:: MarginalizedPOVM(povm_to_marginalize, all_sslbls, sslbls_after_marginalizing) Bases: :py:obj:`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. Create a MarginalizedPOVM. Create a marginalized POVM by adding together sets of effect vectors whose labels have the same *character* at marginalized indices. This assumes that the POVM being marginalized has a particular (though common) effect-label structure whereby each state-space sector corresponds to a single character, e.g. "0010" for a 4-qubt POVM. 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. .. py:attribute:: povm_to_marginalize .. py:attribute:: sslbls_to_marginalize .. py:attribute:: sslbls_after_marginalizing .. py:attribute:: indices_to_keep .. py:method:: to_memoized_dict(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. .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: marginalize_effect_label(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. .. py:method:: keys() An iterator over the effect (outcome) labels of this POVM. .. py:method:: values() An iterator over the effect POVM effect vectors of this POVM. .. py:method:: items() An iterator over the (effect_label, effect_vector) items in this POVM. .. py:method:: simplify_effects(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 .. py:class:: POVM(state_space, evotype, rep=None, items=None) Bases: :py:obj:`pygsti.modelmembers.modelmember.ModelMember`, :py:obj:`collections.OrderedDict` A generalized positive operator-valued measure (POVM). Meant to correspond to a positive operator-valued 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 de-serialization. Initialize a new ModelMember .. py:property:: num_params Get the number of independent parameters which specify this POVM. Returns ------- int the number of independent parameters. .. py:property:: num_elements 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 .. py:method:: to_vector() Extract a vector of the underlying gate parameters from this POVM. Returns ------- numpy array a 1D numpy array with length == num_params(). .. py:method:: from_vector(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 .. py:method:: set_time(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 .. py:method:: transform_inplace(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 .. py:method:: depolarize(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 .. py:method:: acton(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. .. py:class:: StaticPOVMEffect(vec, basis=None, evotype='default', state_space=None) Bases: :py:obj:`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. Initialize a new POVM effect Vector .. py:method:: set_dense(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 .. py:class:: StaticPOVMPureEffect(vec, basis='pp', evotype='default', state_space=None) Bases: :py:obj:`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 Hilbert-Schmidt space representation of this state as a super-bra. 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. Initialize a new POVM effect Vector .. py:class:: TensorProductPOVMEffect(factors, povm_effect_lbls, state_space) Bases: :py:obj:`pygsti.modelmembers.povms.effect.POVMEffect` A state vector that is a tensor-product of other state vectors. Parameters ---------- factors : list of POVMs a list of "reference" POVMs into which `povm_effect_lbls` indexes. povm_effect_lbls : array-like 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. Initialize a new POVM effect Vector .. py:property:: parameter_labels An array of labels (usually strings) describing this model member's parameters. .. py:property:: num_params Get the number of independent parameters which specify this POVM effect vector. Returns ------- int the number of independent parameters. .. py:attribute:: factors .. py:attribute:: effectLbls .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: to_memoized_dict(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. .. py:method:: to_dense(on_space: pygsti.SpaceT = 'minimal', scratch=None) Return this POVM effect vector as a (dense) numpy array. The memory in `scratch` maybe used when it is not-None. 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 super-bra/super-ket 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 .. py:method:: taylor_order_terms(order, max_polynomial_vars=100, return_coeff_polys=False) Get the `order`-th order Taylor-expansion 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 "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 POVMEffect's parameters, where the polynomial's variable indices index the *global* parameters of the POVMEffect's parent (usually a :class:`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 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 :class:`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 :meth:`Polynomial.compact`. .. py:method:: to_vector() Get the POVM effect vector parameters as an array of values. Returns ------- numpy array The parameters as a 1D array with length num_params(). .. py:method:: from_vector(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 .. py:method:: deriv_wrt_params(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) .. py:method:: has_nonzero_hessian() Whether this POVM effect vector has a non-zero Hessian with respect to its parameters. Returns ------- bool .. py:class:: TensorProductPOVM(factor_povms, evotype='auto', state_space=None) Bases: :py:obj:`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 tensor-producted 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. Initialize a new ModelMember .. py:property:: parameter_labels An array of labels (usually strings) describing this model member's parameters. .. py:property:: num_params Get the number of independent parameters which specify this POVM. Returns ------- int the number of independent parameters. .. py:attribute:: factorPOVMs .. py:method:: submembers() Get the ModelMember-derived objects contained in this one. Returns ------- list .. py:method:: keys() An iterator over the effect (outcome) labels of this POVM. .. py:method:: values() An iterator over the effect SPAM vectors of this POVM. .. py:method:: items() An iterator over the (effect_label, effect_vector) items in this POVM. .. py:method:: simplify_effects(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 .. py:method:: to_vector() Extract a vector of the underlying gate parameters from this POVM. Returns ------- numpy array a 1D numpy array with length == num_params(). .. py:method:: from_vector(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 .. py:method:: depolarize(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 .. py:class:: TPPOVM(effects, evotype=None, state_space=None, called_from_reduce=False) Bases: :py:obj:`pygsti.modelmembers.povms.basepovm._BasePOVM`, :py:obj:`pygsti.modelmembers.torchable.Torchable` A POVM whose sum-of-effects is constrained to what, by definition, we call the "identity". Parameters ---------- effects : dict of POVMEffects or array-like 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. Notes ----- Just like TPState, we're restricted to the Pauli-product or Gell-Mann basis. We inherit from BasePOVM, which inherits from POVM, which inherits from OrderedDict. A TPPOVM "p" has an attribute p.complement_label that's set during construction. This label is such that e = p[p.complement_label] is a ComplementPOVMEffect, with an associated FullState object given in e.identity. If v = e.identity.to_vector(), then e's vector representation is v - sum(all non-complement effects in p). Under typical conditions v will be proportional to the first standard basis vector, and, in fact, if v is length "d," then we'll have v[0] == d ** 0.25. However, neither of these conditions is strictly required by the API. Creates a new BasePOVM object. Parameters ---------- effects : dict of POVMEffects or array-like 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. preserve_sum : bool, optional If true, the sum of `effects` is taken to be a constraint and so the final effect vector is made into a :class:`ComplementPOVMEffect`. .. py:property:: dim .. py:method:: to_vector() Extract a vector of the underlying gate parameters from this POVM. Returns ------- numpy array a 1D numpy array with length == num_params(). .. py:method:: stateless_data() -> Tuple[int, numpy.ndarray] Return this ModelMember's data that is considered constant for purposes of model fitting. Note: the word "stateless" here is used in the sense of object-oriented programming. .. py:method:: torch_base(sd: Tuple[int, numpy.ndarray], t_param: torch.Tensor) -> torch.Tensor :staticmethod: Suppose "obj" is an instance of some Torchable subclass. If we compute vec = obj.to_vector() t_param = torch.from_numpy(vec) sd = obj.stateless_data() t = type(obj).torch_base(sd, t_param) then t will be a PyTorch Tensor that represents "obj" in a canonical numerical way. The meaning of "canonical" is implementation dependent. If type(obj) implements the ``.base`` attribute, then a reasonable implementation will probably satisfy np.allclose(obj.base, t.numpy()). .. py:class:: UnconstrainedPOVM(effects, evotype=None, state_space=None, called_from_reduce=False) Bases: :py:obj:`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 array-like 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. Creates a new BasePOVM object. Parameters ---------- effects : dict of POVMEffects or array-like 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. preserve_sum : bool, optional If true, the sum of `effects` is taken to be a constraint and so the final effect vector is made into a :class:`ComplementPOVMEffect`. .. py:function:: sum_of_negative_choi_eigenvalues_gate(op_mx, op_mx_basis) Compute the sum of the negative Choi eigenvalues of a process matrix. Parameters ---------- op_mx : np.array op_mx_basis : Basis Returns ------- float the sum of the negative eigenvalues of the Choi representation of op_mx .. py:class:: Basis(name: str, longname: str, real: bool, sparse: bool) Bases: :py:obj:`pygsti.baseobjs.nicelyserializable.NicelySerializable` An ordered set of labeled matrices/vectors. The base class for basis objects. A basis in pyGSTi is an abstract notion of a set of labeled elements, or "vectors". Each basis has a certain size, and has .elements, .labels, and .ellookup members, the latter being a dictionary mapping of labels to elements. An important point to note that isn't immediately intuitive is that while Basis object holds *elements* (in its `.elements` property) these are not the same as its *vectors* (given by the object's `vector_elements` property). Often times, in what we term a "simple" basis, the you just flatten an element to get the corresponding vector-element. This works for bases where the elements are either vectors (where flattening does nothing) and matrices. By storing `elements` as distinct from `vector_elements`, the Basis can capture additional structure of the elements (such as viewing them as matrices) that can be helpful for their display and interpretation. The elements are also sometimes referred to as the "natural elements" because they represent how to display the element in a natrual way. A non-simple basis occurs when vector_elements need to be stored as elements in a larger "embedded" way so that these elements can be displayed and interpeted naturally. A second important note is that there is assumed to be some underlying "standard" basis underneath all the bases in pyGSTi. The elements in a Basis are *always* written in this standard basis. In the case of the "std"-named basis in pyGSTi, these elements are just the trivial vector or matrix units, so one can rightly view the "std" pyGSTi basis as the "standard" basis for a that particular dimension. The arguments below describe the basic properties of all basis objects in pyGSTi. It is important to remember that the `vector_elements` of a basis are different from its `elements` (see the :class:`Basis` docstring), and that `dim` refers to the vector elements whereas elshape refers to the elements. For example, consider a 2-element Basis containing the I and X Pauli matrices. The `size` of this basis is `2`, as there are two elements (and two vector elements). Since vector elements are the length-4 flattened Pauli matrices, the dimension (`dim`) is `4`. Since the elements are 2x2 Pauli matrices, the `elshape` is `(2, 2)`. As another example consider a basis which spans all the diagonal 2x2 matrices. The elements of this basis are the two matrix units with a 1 in the (0, 0) or (1, 1) location. The vector elements, however, are the length-2 [1, 0] and [0, 1] vectors obtained by extracting just the diagonal entries from each basis element. Thus, for this basis, `size=2`, `dim=2`, and `elshape=(2, 2)` - so the dimension is not just the product of `elshape` entries (equivalently, `elsize`). Parameters ---------- name : string The name of the basis. This can be anything, but is usually short and abbreviated. There are several types of bases built into pyGSTi that can be constructed by this name. longname : string A more descriptive name for the basis. real : bool Elements and vector elements are always allowed to have complex entries. This argument indicates whether the coefficients in the expression of an arbitrary vector in this basis must be real. For example, if `real=True`, then when pyGSTi transforms a vector in some other basis to a vector in *this* basis, it will demand that the values of that vector (i.e. the coefficients which multiply this basis's elements to obtain a vector in the "standard" basis) are real. sparse : bool Whether the elements of `.elements` for this Basis are stored (when they are stored at all) as sparse matrices or vectors. Attributes ---------- dim : int The dimension of the vector space this basis fully or partially spans. Equivalently, the length of the `vector_elements` of the basis. size : int The number of elements (or vector-elements) in the basis. elshape : int The shape of each element. Typically either a length-1 or length-2 tuple, corresponding to vector or matrix elements, respectively. Note that *vector elements* always have shape `(dim, )` (or `(dim, 1)` in the sparse case). elndim : int The number of element dimensions, i.e. `len(self.elshape)` elsize : int The total element size, i.e. `product(self.elshape)` vector_elements : list The "vectors" of this basis, always 1D (sparse or dense) arrays. .. py:property:: dim :abstractmethod: The dimension of the vector space this basis fully or partially spans. Equivalently, the length of the `vector_elements` of the basis. .. py:property:: size :abstractmethod: The number of elements (or vector-elements) in the basis. .. py:property:: elshape :abstractmethod: The shape of each element. Typically either a length-1 or length-2 tuple, corresponding to vector or matrix elements, respectively. Note that *vector elements* always have shape `(dim, )` (or `(dim, 1)` in the sparse case). .. py:property:: elndim The number of element dimensions, i.e. `len(self.elshape)` Returns ------- int .. py:property:: elsize The total element size, i.e. `product(self.elshape)` Returns ------- int .. py:property:: first_element_is_identity True if the first element of this basis is *proportional* to the identity matrix, False otherwise. .. py:property:: vector_elements The "vectors" of this basis, always 1D (sparse or dense) arrays. Returns ------- list A list of 1D arrays. .. py:property:: to_std_transform_matrix Retrieve the matrix that transforms a vector from this basis to the standard basis of this basis's dimension. Returns ------- numpy array or scipy.sparse.lil_matrix An array of shape `(dim, size)` where `dim` is the dimension of this basis (the length of its vectors) and `size` is the size of this basis (its number of vectors). .. py:property:: from_std_transform_matrix Retrieve the matrix that transforms vectors from the standard basis to this basis. Returns ------- numpy array or scipy sparse matrix An array of shape `(size, dim)` where `dim` is the dimension of this basis (the length of its vectors) and `size` is the size of this basis (its number of vectors). .. py:property:: to_elementstd_transform_matrix Get transformation matrix from this basis to the "element space". Get the matrix that transforms vectors in this basis (with length equal to the `dim` of this basis) to vectors in the "element space" - that is, vectors in the same standard basis that the *elements* of this basis are expressed in. Returns ------- numpy array An array of shape `(element_dim, size)` where `element_dim` is the dimension, i.e. size, of the elements of this basis (e.g. 16 if the elements are 4x4 matrices) and `size` is the size of this basis (its number of vectors). .. py:property:: from_elementstd_transform_matrix Get transformation matrix from "element space" to this basis. Get the matrix that transforms vectors in the "element space" - that is, vectors in the same standard basis that the *elements* of this basis are expressed in - to vectors in this basis (with length equal to the `dim` of this basis). Returns ------- numpy array An array of shape `(size, element_dim)` where `element_dim` is the dimension, i.e. size, of the elements of this basis (e.g. 16 if the elements are 4x4 matrices) and `size` is the size of this basis (its number of vectors). .. py:attribute:: name .. py:attribute:: longname .. py:attribute:: real .. py:attribute:: sparse .. py:method:: cast_from_name_and_statespace(name: str, state_space: pygsti.baseobjs.statespace.StateSpace, sparse: Optional[bool] = None) -> Basis :classmethod: .. py:method:: cast_from_name_and_dims(name: str, dim: Union[int, list, tuple], sparse: Optional[bool] = None) -> Basis :classmethod: .. py:method:: cast_from_basis(basis: Basis, dim=None, sparse: Optional[bool] = None) -> Basis :classmethod: .. py:method:: cast_from_arrays(arrays: numpy.ndarray, dim=None, sparse: Optional[bool] = None) -> Basis :classmethod: .. py:method:: cast(arg, dim=None, sparse: Optional[bool] = None) -> Basis :classmethod: .. py:method:: is_simple() -> bool Whether the flattened-element vector space is the *same* space as the space this basis's vectors belong to. Returns ------- bool .. py:method:: is_complete() -> bool Whether this is a complete basis, i.e. this basis's vectors span the entire space that they live in. Returns ------- bool .. py:method:: is_partial() -> bool The negative of :meth:`is_complete`, effectively "is_incomplete". Returns ------- bool .. py:method:: copy() -> Basis Make a copy of this Basis object. Returns ------- Basis .. py:method:: with_sparsity(desired_sparsity: bool) -> Basis Returns either this basis or a copy of it with the desired sparsity. If this basis has the desired sparsity it is simply returned. If not, this basis is copied to one that does. Parameters ---------- desired_sparsity : bool The sparsity (`True` for sparse elements, `False` for dense elements) that is desired. Returns ------- Basis .. py:method:: is_equivalent(other, sparseness_must_match: bool = True) -> bool Tests whether this basis is equal to another basis, optionally ignoring sparseness. Parameters ----------- other : Basis or str The basis to compare with. sparseness_must_match : bool, optional If `False` then comparison ignores differing sparseness, and this function returns `True` when the two bases are equal except for their `.sparse` values. Returns ------- bool .. py:method:: create_transform_matrix(to_basis) Get the matrix that transforms a vector from this basis to `to_basis`. Parameters ---------- to_basis : Basis or string The basis to transform to or a built-in basis name. In the latter case, a basis to transform to is built with the same structure as this basis but with all components constructed from the given name. Returns ------- numpy.ndarray (even if basis is sparse) .. py:method:: reverse_transform_matrix(from_basis) Get the matrix that transforms a vector from `from_basis` to this basis. The reverse of :meth:`create_transform_matrix`. Parameters ---------- from_basis : Basis or string The basis to transform from or a built-in basis name. In the latter case, a basis to transform from is built with the same structure as this basis but with all components constructed from the given name. Returns ------- numpy.ndarray (even if basis is sparse) .. py:method:: is_normalized() Check if a basis is normalized, meaning that Tr(Bi Bi) = 1.0. Available only to bases whose elements are *matrices* for now. Returns ------- bool .. py:method:: create_equivalent(builtin_basis_name) Create an equivalent basis with components of type `builtin_basis_name`. Create a :class:`Basis` that is equivalent in structure & dimension to this basis but whose simple components (perhaps just this basis itself) is of the builtin basis type given by `builtin_basis_name`. Parameters ---------- builtin_basis_name : str The name of a builtin basis, e.g. `"pp"`, `"gm"`, or `"std"`. Used to construct the simple components of the returned basis. Returns ------- Basis .. py:method:: create_simple_equivalent(builtin_basis_name=None) Create a basis of type `builtin_basis_name` whose elements are compatible with this basis. Create a simple basis *and* one without components (e.g. a :class:`TensorProdBasis`, is a simple basis w/components) of the builtin type specified whose dimension is compatible with the *elements* of this basis. This function might also be named "element_equivalent", as it returns the `builtin_basis_name`-analogue of the standard basis that this basis's elements are expressed in. Parameters ---------- builtin_basis_name : str, optional The name of the built-in basis to use. If `None`, then a copy of this basis is returned (if it's simple) or this basis's name is used to try to construct a simple and component-free version of the same builtin-basis type. Returns ------- Basis .. py:method:: is_compatible_with_state_space(state_space: pygsti.baseobjs.statespace.StateSpace) -> bool Checks whether this basis is compatible with a given state space. Parameters ---------- state_space : StateSpace the state space to check. Returns ------- bool .. py:function:: create_from_pure_vectors(pure_vectors, povm_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn') Creates a Positive Operator-Valued Measure (POVM) from a list or dictionary of (key, pure-vector) pairs. Parameters ---------- pure_vectors : list or dict A list of (key, pure-vector) pairs or a dictionary where keys are labels and values are pure state vectors. povm_type : str or tuple The type of POVM to create. This can be a single string or a tuple of strings indicating the preferred types. Supported types include 'computational', 'static pure', 'full pure', 'static', 'full', 'full TP', and any valid Lindblad parameterization type. basis : str, optional The basis in which the pure vectors are expressed. Default is 'pp'. evotype : str, optional The evolution type. Default is 'default'. state_space : StateSpace, optional The state space in which the POVM operates. Default is None. on_construction_error : str, optional Specifies the behavior when an error occurs during POVM construction. Options are 'raise' to raise the error, 'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'. Returns ------- POVM The constructed POVM object. .. py:function:: create_from_dmvecs(superket_vectors, povm_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn') Creates a Positive Operator-Valued Measure (POVM) from a list or dictionary of (key, superket) pairs. Parameters ---------- superket_vectors : list or dict A list of (key, pure-vector) pairs or a dictionary where keys are labels and values are superket vectors. i.e. vectorized density matrices. povm_type : str or tuple The type of POVM to create. This can be a single string or a tuple of strings indicating the preferred types. Supported types include 'full', 'static', 'full TP', 'computational', 'static pure', 'full pure', and any valid Lindblad parameterization type. basis : str or `Basis`, optional The basis in which the density matrix vectors are expressed. Default is 'pp'. evotype : str, optional The evolution type. Default is 'default'. state_space : StateSpace, optional The state space in which the POVM operates. Default is None. on_construction_error : str, optional Specifies the behavior when an error occurs during POVM construction. Options are 'raise' to raise the error, 'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'. Returns ------- POVM The constructed POVM object. .. py:function:: create_effect_from_pure_vector(pure_vector, effect_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn') Creates a POVM effect from a pure state vector. Parameters ---------- pure_vector : array-like The pure state vector from which to create the POVM effect. effect_type : str or tuple The type of effect to create. This can be a single string or a tuple of strings indicating the preferred types. Supported types include 'computational', 'static pure', 'full pure', 'static', 'full', 'static clifford', and any valid Lindblad parameterization type. basis : str or `Basis` optional The basis in which the pure vector is expressed. Default is 'pp'. evotype : str, optional The evolution type. Default is 'default'. state_space : StateSpace, optional The state space in which the effect operates. Default is None. on_construction_error : str, optional Specifies the behavior when an error occurs during effect construction. Options are 'raise' to raise the error, 'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'. Returns ------- POVMEffect The constructed POVM effect object. .. py:function:: create_effect_from_dmvec(superket_vector, effect_type, basis='pp', evotype='default', state_space=None, on_construction_error='warn') Creates a POVM effect from a density matrix vector (superket). Parameters ---------- superket_vector : array-like The density matrix vector (superket) from which to create the POVM effect. effect_type : str or tuple The type of effect to create. This can be a single string or a tuple of strings indicating the preferred types. Supported types include 'static', 'full', and any valid Lindblad parameterization type. For other types we first try to convert to a pure state vector and then utilize `create_effect_from_pure_vector` basis : str or `Basis` optional The basis in which the superket vector is expressed. Default is 'pp'. evotype : str, optional The evolution type. Default is 'default'. state_space : StateSpace, optional The state space in which the effect operates. Default is None. on_construction_error : str, optional Specifies the behavior when an error occurs during effect construction. Options are 'raise' to raise the error, 'warn' to print a warning message, or any other value to silently ignore the error. Default is 'warn'. Returns ------- POVMEffect The constructed POVM effect object. .. py:function:: povm_type_from_op_type(op_type) Decode an op type into an appropriate povm type. Parameters: ----------- op_type: str or list of str Operation parameterization type (or list of preferences) Returns ------- povm_type_preferences: tuple of str POVM parameterization types .. py:function:: convert(povm, to_type, basis, ideal_povm=None, flatten_structure=False, cp_penalty=1e-07) TODO: update docstring 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 pure","H+S terms", "H+S clifford terms","clifford"} The type of parameterizaton to convert to. See :meth:`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 Matrix-unit (std), Gell-Mann (gm), Pauli-product (pp), and Qutrit (qt) (or a custom basis object). ideal_povm : POVM, optional The ideal version of `povm`, potentially used when converting to an error-generator type. flatten_structure : bool, optional When `False`, the sub-members of composed and embedded operations are separately converted, leaving the original POVM's structure unchanged. When `True`, composed and embedded operations are "flattened" into a single POVM of the requested `to_type`. cp_penalty : float, optional (default 1e-7) Converting SPAM operations to an error generator representation may introduce trivial gauge degrees of freedom. These gauge degrees of freedom are called trivial because they quite literally do not change the dense representation (i.e. Hilbert-Schmidt vectors) at all. Despite being trivial, error generators along this trivial gauge orbit may be non-CP, so this cptp penalty is used to favor channels within this gauge orbit which are CPTP. Returns ------- POVM The converted POVM vector, usually a distinct object from the object passed as input. .. py:function:: convert_effect(effect, to_type, basis, ideal_effect=None, flatten_structure=False) 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 pure","clifford",LINDBLAD} The type of parameterizaton to convert to. "LINDBLAD" is a placeholder for the various Lindblad parameterization types. See :meth:`Model.set_all_parameterizations` for more details. basis : {'std', 'gm', 'pp', 'qt'} or Basis object The basis for `spamvec`. Allowed values are Matrix-unit (std), Gell-Mann (gm), Pauli-product (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. .. py:function:: 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