Defines the TPInstrument class

Module Contents



A trace-preservng quantum instrument.

class pygsti.modelmembers.instruments.tpinstrument.TPInstrument(op_matrices, evotype='default', state_space=None, called_from_reduce=False, items=None)

Bases: pygsti.modelmembers.modelmember.ModelMember, collections.OrderedDict

A trace-preservng quantum instrument.

This is essentially a collection of operations whose sum is a trace-preserving map. The instrument’s elements may or may not have all of the properties associated by a mathematical quantum instrument.

If M1,M2,…Mn are the elements of the instrument, then we parameterize

  1. MT = (M1+M2+…Mn) as a TPParmeterizedGate

  2. Di = Mi - MT for i = 1..(n-1) as FullyParameterizedGates

So to recover M1…Mn we compute: Mi = Di + MT for i = 1…(n-1) = -(n-2)*MT-sum(Di) = -(n-2)*MT-[(MT-Mi)-n*MT] for i == (n-1)


op_matricesdict of numpy arrays

A dict (or list of key,value pairs) of the operation matrices whose sum must be a trace-preserving (TP) map.

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 Instrument. If None, the space is inferred from the first effect vector. If len(effects) == 0 in this case, an error is raised.

itemslist or dict, optional

Initial values. This should only be used internally in de-serialization.

Initialize a new ModelMember

property parameter_labels

An array of labels (usually strings) describing this model member’s parameters.

property num_elements

Return the number of total gate elements in this instrument.

This is in general different from the number of parameters, which are the number of free variables used to generate all of the matrix elements.



property num_params

Get the number of independent parameters which specify this Instrument.


the number of independent parameters.


Get the ModelMember-derived objects contained in this one.




Create a serializable dict with references to other objects in the memo.

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

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.


Creates a dictionary of simplified instrument operations.

Returns a dictionary of operations that belong to the Instrument’s parent Model - that is, whose gpindices are set to all or a subset of this instruments’s gpindices. These are used internally within computations involving the parent Model.


A string, usually identitying this instrument, which may be used to prefix the simplified gate keys.


OrderedDict of Gates


Extract a vector of the underlying gate parameters from this Instrument.

numpy array

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

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

Initialize the Instrument using a vector of its parameters.

vnumpy array

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

closebool, optional

Whether v is close to this Instrument’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.




Update each Instrument element matrix O with inv(s) * O * s.


A gauge group element which specifies the “s” matrix (and it’s inverse) used in the above similarity transform.




Depolarize this Instrument by the given amount.

amountfloat 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).



rotate(amount, mx_basis='gm')

Rotate this instrument by the given amount.

amounttuple of floats, optional

Specifies the rotation “coefficients” along each of the non-identity Pauli-product axes. The gate’s matrix G is composed with a rotation operation R (so G -> dot(R, G) ) where R is the unitary superoperator corresponding to the unitary operator U = exp( sum_k( i * rotate[k] / 2.0 * Pauli_k ) ). Here Pauli_k ranges over all of the non-identity un-normalized Pauli operators.

mx_basis{‘std’, ‘gm’, ‘pp’, ‘qt’} or Basis object

The source and destination basis, respectively. Allowed values are Matrix-unit (std), Gell-Mann (gm), Pauli-product (pp), and Qutrit (qt) (or a custom basis object).