pygsti.modelmembers.operations.denseop

The DenseOperator class and supporting functionality.

Module Contents

Classes

DenseOperatorInterface

Adds a numpy-array-mimicing interface onto an operation object.

DenseOperator

TODO: update docstring

DenseUnitaryOperator

TODO: update docstring

Functions

finite_difference_deriv_wrt_params(operation, wrt_filter)

Computes a finite-difference Jacobian for a LinearOperator object.

check_deriv_wrt_params(operation[, deriv_to_check, ...])

Checks the deriv_wrt_params method of a LinearOperator object.

pygsti.modelmembers.operations.denseop.finite_difference_deriv_wrt_params(operation, wrt_filter, eps=1e-07)

Computes a finite-difference 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

operationLinearOperator

The operation object to compute a Jacobian for.

wrt_filterlist or numpy.ndarray

List of parameter indices to filter the result by (as though derivative is only taken with respect to these parameters).

epsfloat, 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=1e-07)

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 finite-difference 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

operationLinearOperator

The operation object to test.

deriv_to_checknumpy.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_filterlist or numpy.ndarray

List of parameter indices to filter the result by (as though derivative is only taken with respect to these parameters).

epsfloat, optional

The finite difference step to use.

Returns

None

class pygsti.modelmembers.operations.denseop.DenseOperatorInterface

Bases: object

Adds a numpy-array-mimicing interface onto an operation object.

to_array()

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 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(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 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.

Returns

scipy.sparse.csr_matrix

class pygsti.modelmembers.operations.denseop.DenseOperator(mx, basis, evotype, state_space=None)

Bases: DenseOperatorInterface, pygsti.modelmembers.operations.krausop.KrausOperatorInterface, pygsti.modelmembers.operations.linearop.LinearOperator

TODO: update docstring An operator that behaves like a dense super-operator matrix.

This class is the common base class for more specific dense operators.

Parameters

mxnumpy.ndarray

The operation as a dense process matrix.

basisBasis or {‘pp’,’gm’,’std’} or None

The basis used to construct the Hilbert-Schmidt space representation of this state as a super-operator. If None, certain functionality, such as access to Kraus operators, will be unavailable.

evotypeEvotype or str

The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.

state_spaceStateSpace, optional

The state space for this operation. If None a default state space with the appropriate number of qubits is used.

Attributes

basenumpy.ndarray

Direct access to the underlying process matrix data.

Initialize a new LinearOperator

property kraus_operators

A list of this operation’s Kraus operators as numpy arrays.

classmethod from_kraus_operators(kraus_operators, basis='pp', evotype='default', state_space=None)

Create an operation by specifying its Kraus operators.

Parameters
kraus_operatorslist

A list of numpy arrays, each of which specifyies a Kraus operator.

basisstr or Basis, optional

The basis in which the created operator’s superoperator representation is in.

evotypeEvotype or str, optional

The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.

state_spaceStateSpace, optional

The state space for this operation. If None a default state space with the appropriate number of qubits is used.

to_dense(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 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.

Returns

numpy.ndarray

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.

set_kraus_operators(kraus_operators)

Set the parameters of this operation by specifying its Kraus operators.

Parameters
kraus_operatorslist

A list of numpy arrays, each of which specifies a Kraus operator.

Returns

None

class pygsti.modelmembers.operations.denseop.DenseUnitaryOperator(mx, basis, evotype, state_space)

Bases: DenseOperatorInterface, pygsti.modelmembers.operations.krausop.KrausOperatorInterface, 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

mxnumpy.ndarray

The operation as a dense process matrix.

basisBasis or {‘pp’,’gm’,’std’}, optional

The basis used to construct the Hilbert-Schmidt space representation of this state as a super-operator.

evotypeEvotype or str

The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.

state_spaceStateSpace, optional

The state space for this operation. If None a default state space with the appropriate number of qubits is used.

Attributes

basenumpy.ndarray

Direct access to the underlying process matrix data.

Initialize a new LinearOperator

property kraus_operators

A list of this operation’s Kraus operators as numpy arrays.

classmethod from_kraus_operators(kraus_operators, basis='pp', evotype='default', state_space=None)

Create an operation by specifying its Kraus operators.

Parameters
kraus_operatorslist

A list of numpy arrays, each of which specifyies a Kraus operator.

basisstr or Basis, optional

The basis in which the created operator’s superoperator representation is in.

evotypeEvotype or str, optional

The evolution type. The special value “default” is equivalent to specifying the value of pygsti.evotypes.Evotype.default_evotype.

state_spaceStateSpace, optional

The state space for this operation. If None a default state space with the appropriate number of qubits is used.

classmethod quick_init(unitary_mx, superop_mx, basis, evotype, state_space)
to_dense(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 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.

Returns

numpy.ndarray

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.

set_kraus_operators(kraus_operators)

Set the parameters of this operation by specifying its Kraus operators.

Parameters
kraus_operatorslist

A list of numpy arrays, each of which specifies a Kraus operator.

Returns

None