pygsti.modelmembers.operations.denseop
¶
The DenseOperator class and supporting functionality.
Module Contents¶
Classes¶
Adds a numpyarraymimicing interface onto an operation object. 

TODO: update docstring 

TODO: update docstring 
Functions¶

Computes a finitedifference Jacobian for a LinearOperator object. 

Checks the deriv_wrt_params method of a LinearOperator object. 
 pygsti.modelmembers.operations.denseop.finite_difference_deriv_wrt_params(operation, wrt_filter, eps=1e07)¶
Computes a finitedifference Jacobian for a LinearOperator object.
The returned value is a matrix whose columns are the vectorized derivatives of the flattened operation matrix with respect to a single operation parameter, matching the format expected from the operation’s deriv_wrt_params method.
 Parameters
operation (LinearOperator) – The operation object to compute a Jacobian for.
wrt_filter (list or numpy.ndarray) – List of parameter indices to filter the result by (as though derivative is only taken with respect to these parameters).
eps (float, optional) – The finite difference step to use.
 Returns
numpy.ndarray – An M by N matrix where M is the number of operation elements and N is the number of operation parameters.
 pygsti.modelmembers.operations.denseop.check_deriv_wrt_params(operation, deriv_to_check=None, wrt_filter=None, eps=1e07)¶
Checks the deriv_wrt_params method of a LinearOperator object.
This routine is meant to be used as an aid in testing and debugging operation classes by comparing the finitedifference Jacobian that should be returned by operation.deriv_wrt_params with the one that actually is. A ValueError is raised if the two do not match.
 Parameters
operation (LinearOperator) – The operation object to test.
deriv_to_check (numpy.ndarray or None, optional) – If not None, the Jacobian to compare against the finite difference result. If None, operation.deriv_wrt_parms() is used. Setting this argument can be useful when the function is called within a LinearOperator class’s deriv_wrt_params() method itself as a part of testing.
wrt_filter (list or numpy.ndarray) – List of parameter indices to filter the result by (as though derivative is only taken with respect to these parameters).
eps (float, optional) – The finite difference step to use.
 Returns
None
 class pygsti.modelmembers.operations.denseop.DenseOperatorInterface¶
Bases:
object
Adds a numpyarraymimicing interface onto an operation object.
 property _ptr(self)¶
 _ptr_has_changed(self)¶
Derived classes should override this function to handle rep updates when the _ptr property is changed.
 to_array(self)¶
Return the array used to identify this operation within its range of possible values.
For instance, if the operation is a unitary operation, this returns a unitary matrix regardless of the evolution type. The related :method:`to_dense` method, in contrast, returns the dense representation of the operation, which varies by evolution type.
Note: for efficiency, this doesn’t copy the underlying data, so the caller should copy this data before modifying it.
 Returns
numpy.ndarray
 to_sparse(self, on_space='minimal')¶
Return the operation as a sparse matrix.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
 Returns
scipy.sparse.csr_matrix
 __copy__(self)¶
 __deepcopy__(self, memo)¶
 __getitem__(self, key)¶
 __getslice__(self, i, j)¶
 __setitem__(self, key, val)¶
 __getattr__(self, attr)¶
 __str__(self)¶
Return str(self).
 __pos__(self)¶
 __neg__(self)¶
 __abs__(self)¶
 __add__(self, x)¶
 __radd__(self, x)¶
 __sub__(self, x)¶
 __rsub__(self, x)¶
 __mul__(self, x)¶
 __rmul__(self, x)¶
 __truediv__(self, x)¶
 __rtruediv__(self, x)¶
 __floordiv__(self, x)¶
 __rfloordiv__(self, x)¶
 __pow__(self, x)¶
 __eq__(self, x)¶
Return self==value.
 __len__(self)¶
 __int__(self)¶
 __long__(self)¶
 __float__(self)¶
 __complex__(self)¶
 class pygsti.modelmembers.operations.denseop.DenseOperator(mx, evotype, state_space=None)¶
Bases:
DenseOperatorInterface
,pygsti.modelmembers.operations.linearop.LinearOperator
TODO: update docstring An operator that behaves like a dense superoperator matrix.
This class is the common base class for more specific dense operators.
 Parameters
mx (numpy.ndarray) – The operation as a dense process matrix.
evotype (Evotype or str) – 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.
 base¶
Direct access to the underlying process matrix data.
 Type
numpy.ndarray
 property _ptr(self)¶
 _ptr_has_changed(self)¶
Derived classes should override this function to handle rep updates when the _ptr property is changed.
 to_dense(self, on_space='minimal')¶
Return the dense array used to represent this operation within its evolution type.
Note: for efficiency, this doesn’t copy the underlying data, so the caller should copy this data before modifying it.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
 Returns
numpy.ndarray
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _oneline_contents(self)¶
Summarizes the contents of this object in a single line. Does not summarize submembers.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers
 class pygsti.modelmembers.operations.denseop.DenseUnitaryOperator(mx, basis, evotype, state_space)¶
Bases:
DenseOperatorInterface
,pygsti.modelmembers.operations.linearop.LinearOperator
TODO: update docstring An operator that behaves like a dense (unitary) operator matrix.
This class is the common base class for more specific dense operators.
 Parameters
mx (numpy.ndarray) – The operation as a dense process matrix.
basis (Basis or {'pp','gm','std'}, optional) – The basis used to construct the HilbertSchmidt space representation of this state as a superoperator.
evotype (Evotype or str) – 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.
 base¶
Direct access to the underlying process matrix data.
 Type
numpy.ndarray
 property _ptr(self)¶
Gives a handle/pointer to the base numpy array that this object can be accessed as
 _ptr_has_changed(self)¶
Derived classes should override this function to handle rep updates when the _ptr property is changed.
 to_dense(self, on_space='minimal')¶
Return the dense array used to represent this operation within its evolution type.
Note: for efficiency, this doesn’t copy the underlying data, so the caller should copy this data before modifying it.
 Parameters
on_space ({'minimal', 'Hilbert', 'HilbertSchmidt'}) – The space that the returned dense operation acts upon. For unitary matrices and bra/ket vectors, use ‘Hilbert’. For superoperator matrices and superbra/superket vectors use ‘HilbertSchmidt’. ‘minimal’ means that ‘Hilbert’ is used if possible given this operator’s evolution type, and otherwise ‘HilbertSchmidt’ is used.
 Returns
numpy.ndarray
 transform_inplace(self, s)¶
Update operation matrix O with inv(s) * O * s.
Generally, the transform function updates the parameters of the operation such that the resulting operation matrix is altered as described above. If such an update cannot be done (because the operation 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
 spam_transform_inplace(self, s, typ)¶
Update operation matrix O with inv(s) * O OR O * s, depending on the value of typ.
This functions as transform_inplace(…) but is used when this Lindbladparameterized operation is used as a part of a SPAM vector. When typ == “prep”, the spam vector is assumed to be rho = dot(self, <spamvec>), which transforms as rho > inv(s) * rho, so self > inv(s) * self. When typ == “effect”, e.dag = dot(e.dag, self) (not that self is NOT self.dag here), and e.dag > e.dag * s so that self > self * s.
 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 SPAM vector is being transformed (see above).
 Returns
None
 to_memoized_dict(self, mmg_memo)¶
Create a serializable dict with references to other objects in the memo.
 Parameters
mmg_memo (dict) – Memo dict from a ModelMemberGraph, i.e. keys are object ids and values are ModelMemberGraphNodes (which contain the serialize_id). This is NOT the same as other memos in ModelMember (e.g. copy, allocate_gpindices, etc.).
 Returns
mm_dict (dict) – A dict representation of this ModelMember ready for serialization This must have at least the following fields:
module, class, submembers, params, state_space, evotype
Additional fields may be added by derived classes.
 classmethod _from_memoized_dict(cls, mm_dict, serial_memo)¶
For subclasses to implement. Submemberexistence checks are performed, and the gpindices of the return value is set, by the nonunderscored :method:`from_memoized_dict` implemented in this class.
 _oneline_contents(self)¶
Summarizes the contents of this object in a single line. Does not summarize submembers.
 _is_similar(self, other, rtol, atol)¶
Returns True if other model member (which it guaranteed to be the same type as self) has the same local structure, i.e., not considering parameter values or submembers