pygsti.modelmembers.operations.lpdenseop

The LinearlyParamArbitraryOp class and supporting functionality.

Module Contents

Classes

LinearlyParameterizedElementTerm

Encapsulates a single term within a LinearlyParamArbitraryOp.

LinearlyParamArbitraryOp

An operation matrix parameterized such that each element depends only linearly on any parameter.

Attributes

IMAG_TOL

pygsti.modelmembers.operations.lpdenseop.IMAG_TOL = '1e-07'
class pygsti.modelmembers.operations.lpdenseop.LinearlyParameterizedElementTerm(coeff=1.0, param_indices=None)

Bases: object

Encapsulates a single term within a LinearlyParamArbitraryOp.

Parameters

coefffloat, optional

The term’s coefficient

param_indiceslist

A list of integers, specifying which parameters are muliplied together (and finally, with coeff) to form this term.

Create a new LinearlyParameterizedElementTerm

Parameters

coefffloat, optional

The term’s coefficient

param_indiceslist

A list of integers, specifying which parameters are muliplied together (and finally, with coeff) to form this term.

class pygsti.modelmembers.operations.lpdenseop.LinearlyParamArbitraryOp(base_matrix, parameter_array, parameter_to_base_indices_map, left_transform=None, right_transform=None, real=False, basis=None, evotype='default', state_space=None)

Bases: pygsti.modelmembers.operations.denseop.DenseOperator

An operation matrix parameterized such that each element depends only linearly on any parameter.

Parameters

basematrixnumpy array

a square 2D numpy array that acts as the starting point when constructin the operation’s matrix. The shape of this array sets the dimension of the operation.

parameter_arraynumpy array

a 1D numpy array that holds the all the parameters for this operation. The shape of this array sets is what is returned by value_dimension(…).

parameter_to_base_indices_mapdict

A dictionary with keys == index of a parameter (i.e. in parameter_array) and values == list of 2-tuples indexing potentially multiple operation matrix coordinates which should be set equal to this parameter.

left_transformnumpy array or None, optional

A 2D array of the same shape as basematrix which left-multiplies the base matrix after parameters have been evaluated. Defaults to no transform_inplace.

right_transformnumpy array or None, optional

A 2D array of the same shape as basematrix which right-multiplies the base matrix after parameters have been evaluated. Defaults to no transform_inplace.

realbool, optional

Whether or not the resulting operation matrix, after all parameter evaluation and left & right transforms have been performed, should be real. If True, ValueError will be raised if the matrix contains any complex or imaginary elements.

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

Initialize a new LinearOperator

property num_params

Get the number of independent parameters which specify this operation.

Returns
int

the number of independent parameters.

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.

to_vector()

Extract a vector of the underlying operation parameters from this operation.

Returns
numpy array

a 1D numpy array with length == num_params().

from_vector(v, close=False, dirty_value=True)

Initialize the operation using a vector of parameters.

Parameters
vnumpy array

The 1D vector of operation parameters. Length must == num_params()

closebool, optional

Whether v is close to this operation’s current set of parameters. Under some circumstances, when this is true this call can be completed more quickly.

dirty_valuebool, optional

The value to set this object’s “dirty flag” to before exiting this call. This is passed as an argument so it can be updated recursively. Leave this set to True unless you know what you’re doing.

Returns

None

deriv_wrt_params(wrt_filter=None)

The element-wise derivative this operation.

Construct a matrix whose columns are the vectorized derivatives of the flattened operation matrix with respect to a single operation parameter. Thus, each column is of length op_dim^2 and there is one column per operation parameter.

Parameters
wrt_filterlist 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^2, num_params)

has_nonzero_hessian()

Whether this operation has a non-zero Hessian with respect to its parameters.

(i.e. whether it only depends linearly on its parameters or not)

Returns

bool