The TPState class and supporting functionality.

Module Contents



A fixed-unit-trace state vector.

class pygsti.modelmembers.states.tpstate.TPState(vec, basis=None, evotype='default', state_space=None)

Bases: pygsti.modelmembers.states.densestate.DenseState

A fixed-unit-trace state vector.

This state vector is fully parameterized except for the first element, which is frozen to be 1/(d**0.25). This is so that, when the state vector is interpreted in the Pauli or Gell-Mann basis, the represented density matrix has trace == 1. This restriction is frequently used in conjuction with trace-preserving (TP) gates, hence its name.


vecarray_like or State

a 1D numpy array representing the state. The shape of this array sets the dimension of the state.

basisBasis or str

The basis that vec 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.

Initialize a new state Vector

property columnvec

Direct access the the underlying data as column vector, i.e, a (dim,1)-shaped array.

property num_params

Get the number of independent parameters which specify this state vector.


the number of independent parameters.


Set the dense-vector value of this state vector.

Attempts to modify this state vector’s parameters so that the raw state vector becomes vec. Will raise ValueError if this operation is not possible.

vecarray_like or State

A numpy array representing a state vector, or a State object.




Get the state vector parameters as an array of values.

numpy array

The parameters as a 1D array with length num_params().

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

Initialize the state vector using a 1D array of parameters.

vnumpy array

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

closebool, optional

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




The element-wise derivative this state vector.

Construct a matrix whose columns are the derivatives of the state vector with respect to a single param. Thus, each column is of length dimension and there is one column per state vector parameter.

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

numpy array

Array of derivatives, shape == (dimension, num_params)


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