qit.state.State

class qit.state.State(s: Union[str, int, array_like, State], dim: Optional[Sequence[int]] = None)

Class for quantum states.

Describes the state (pure or mixed) of a discrete, possibly composite quantum system. The subsystem dimensions can be obtained with the dims method (big-endian ordering).

State class instances are special cases of Lmap. They have exactly two indices. If self.dim[1] == (1,), it is a ket representing a pure state. Otherwise both indices must have equal dimensions and the object represents a state operator.

Does not require the state to be physical (it does not have to be trace-1, Hermitian, or nonnegative).

By default, all State methods leave the object unchanged and instead return a modified copy.

Utilities

check()

Checks the validity of the state.

subsystems()

Number of subsystems in the state.

dims()

Dimensions of the subsystems of the state.

clean_selection(sys)

Make a subsystem set unique and sorted.

invert_selection(sys)

Invert and sort a subsystem index set.

fix_phase([inplace])

Apply a global phase convention to a ket state.

normalize([inplace])

Normalize the state to unity.

to_ket([inplace])

Convert the state representation into a ket (if possible).

to_op([inplace])

Convert state representation into a state operator.

trace()

Trace of the state operator.

ptrace(sys[, inplace])

Partial trace.

ptranspose(sys[, inplace])

Partial transpose.

reorder(perm[, inplace])

Change the relative order of subsystems in a state.

tensor(*arg)

Tensor product of states.

plot([fig, symbols])

State tomography plot.

Physics

ev(A)

Expectation value of an observable in the state.

var(A)

Variance of an observable in the state.

prob()

Measurement probabilities of the state in the computational basis.

projector()

Projection operator defined by the state.

u_propagate(U)

Propagate the state using a unitary.

propagate(G, t[, out_func])

Propagate the state continuously in time.

kraus_propagate(E)

Apply a quantum operation to the state.

measure([M, do])

Quantum measurement.

Quantum information

fidelity(r)

Fidelity of two states.

trace_dist(r)

Trace distance of two states.

purity()

Purity of the state.

schmidt([sys, full])

Schmidt decomposition.

entropy([sys, alpha])

Von Neumann or Renyi entropy of the state.

concurrence([sys])

Concurrence of the state.

negativity(sys)

Negativity of the state.

lognegativity(sys)

Logarithmic negativity of the state.

scott(m)

Scott’s average bipartite entanglement measure.

locc_convertible(t, sys)

LOCC convertibility of states.

Other state representations

bloch_vector()

Generalized Bloch vector.

bloch_state(A[, dim])

State corresponding to a generalized Bloch vector.

Named states

werner(p[, d])

Werner states.

isotropic(p[, d])

Isotropic states.

Parameters
  • s (Union[str, int, 'array_like', State]) – state description, see below

  • dim (Optional[Sequence[int]]) – Dimensions of the subsystems comprising the state. If dim is None, the dimensions are inferred from s.

calling syntax            result
==============            ======
State('00101')            standard basis ket |00101> in a five-qubit system
State('02', (2, 3))       standard basis ket |02> in a qubit+qutrit system
State('GHZ', (2, 2, 2))   named states (in this case the three-qubit GHZ state)
State(k, (2, 3))          linearized standard basis ket |k> in a qubit+qutrit system, k must be a nonnegative integer
State(rand(4))            ket, infer dim = (4,)
State(rand(4), (2, 2))    ket, two qubits
State(rand(4,4))          state operator, infer dim = (4,)
State(rand(6,6), (3, 2))  state operator, qutrit+qubit

State(s)                  (s is a State) copy constructor
State(s, dim)             (s is a State) copy constructor, redefine the dimensions
The currently supported named states are

GHZ (Greenberger-Horne-Zeilinger), W, Bell1, Bell2, Bell3, Bell4

Attributes

Methods

bloch_state(A[, dim])

State corresponding to a generalized Bloch vector.

bloch_vector()

Generalized Bloch vector.

check()

Checks the validity of the state.

clean_selection(sys)

Make a subsystem set unique and sorted.

concurrence([sys])

Concurrence of the state.

dims()

Dimensions of the subsystems of the state.

entropy([sys, alpha])

Von Neumann or Renyi entropy of the state.

ev(A)

Expectation value of an observable in the state.

fidelity(r)

Fidelity of two states.

fix_phase([inplace])

Apply a global phase convention to a ket state.

invert_selection(sys)

Invert and sort a subsystem index set.

isotropic(p[, d])

Isotropic states.

kraus_propagate(E)

Apply a quantum operation to the state.

locc_convertible(t, sys)

LOCC convertibility of states.

lognegativity(sys)

Logarithmic negativity of the state.

measure([M, do])

Quantum measurement.

negativity(sys)

Negativity of the state.

normalize([inplace])

Normalize the state to unity.

plot([fig, symbols])

State tomography plot.

prob()

Measurement probabilities of the state in the computational basis.

projector()

Projection operator defined by the state.

propagate(G, t[, out_func])

Propagate the state continuously in time.

ptrace(sys[, inplace])

Partial trace.

ptranspose(sys[, inplace])

Partial transpose.

purity()

Purity of the state.

reorder(perm[, inplace])

Change the relative order of subsystems in a state.

schmidt([sys, full])

Schmidt decomposition.

scott(m)

Scott’s average bipartite entanglement measure.

subsystems()

Number of subsystems in the state.

tensor(*arg)

Tensor product of states.

to_ket([inplace])

Convert the state representation into a ket (if possible).

to_op([inplace])

Convert state representation into a state operator.

trace()

Trace of the state operator.

trace_dist(r)

Trace distance of two states.

u_propagate(U)

Propagate the state using a unitary.

var(A)

Variance of an observable in the state.

werner(p[, d])

Werner states.

check()

Checks the validity of the state.

Makes sure it is normalized, and if an operator, Hermitian and semipositive.

subsystems()

Number of subsystems in the state.

Returns

number of subsystems

Return type

int

dims()

Dimensions of the subsystems of the state.

Returns

dimensions of the subsystems

Return type

tuple[int]

clean_selection(sys)

Make a subsystem set unique and sorted.

Parameters

sys (Iterable[int]) – set of subsystem indices

Returns

same set made unique and sorted, invalid indices removed

Return type

array[int]

invert_selection(sys)

Invert and sort a subsystem index set.

fix_phase(inplace=False)

Apply a global phase convention to a ket state.

Returns

Copy of the state. If the state is represented with

a ket, the copy has a global phase such that the first nonzero element in the state vector is real and positive.

Return type

State

normalize(inplace=False)

Normalize the state to unity.

Returns

Copy of the state normalized to unity.

Return type

State

purity()

Purity of the state.

Returns

Purity of a normalized state, \(p = \mathrm{Tr}(\rho^2)\).

Equivalent to linear entropy, \(S_l = 1-p\).

Return type

float

to_ket(inplace=False)

Convert the state representation into a ket (if possible).

Returns

If the state is pure, returns a copy for which the

internal representation (self.data) is a ket vector.

Return type

State

Raises

ValueError – state is not pure

to_op(inplace=False)

Convert state representation into a state operator.

Returns

Copy of the state for which the internal representation (self.data) is a state operator.

Return type

State

trace()

Trace of the state operator.

Returns

Trace of the state operator. For a pure state this is equal to the squared norm of the state vector.

Return type

float

ptrace(sys, inplace=False)

Partial trace.

Parameters

sys (Sequence[int]) – subsystems over which to take a partial trace

Returns

Partial trace of the state over the given subsystems.

Return type

State

ptranspose(sys, inplace=False)

Partial transpose.

Parameters

sys (Sequence[int]) – subsystems wrt. which to take a partial transpose

Returns

Partial transpose of the state wrt. the given subsystems.

Return type

State

reorder(perm, inplace=False)

Change the relative order of subsystems in a state.

reorder([2, 1, 0])    reverse the order of three subsystems
reorder([2, 5])       swap subsystems 2 and 5
Parameters

perm (array[int]) – permutation vector, may consist of either exactly two subsystem indices (to be swapped), or a full permutation of subsystem indices.

Returns

The state with the subsystems in the given order.

Return type

State

ev(A)

Expectation value of an observable in the state.

Parameters

A (array) – hermitian observable

Returns

expectation value of the observable A in the state

Return type

float

var(A)

Variance of an observable in the state.

Parameters

A (array) – hermitian observable

Returns

variance of the observable A in the state

Return type

float

prob()

Measurement probabilities of the state in the computational basis.

Returns

vector of probabilities of finding a system in each of the different states of the computational basis

Return type

array[float]

projector()

Projection operator defined by the state.

Returns the projection operator P defined by the state.

u_propagate(U)

Propagate the state using a unitary.

Parameters

U (array, Lmap) – unitary propagator

Returns

propagated state

Return type

State

propagate(G, t, out_func=<function State.<lambda>>, **kwargs)

Propagate the state continuously in time.

propagate(H, t)                     # Hamiltonian
propagate(L, t)                     # Liouvillian
propagate([H, A_1, A_2, ...], t)    # Hamiltonian and Lindblad ops

Propagates the state using the generator G for the time t, returns the resulting state.

Parameters
  • G (array, callable, list[array]) – generator, see below

  • t (float, array[float]) – single time duration, or a vector of increasing time instants

  • out_func (callable) – if given, for each time instance t return out_func(s(t), G(t)).

Keyword args are passed on to the ODE solver.

Returns

propagated state for each time instant given in t

Return type

State, list[State]

The generator G can either be a

  • Hamiltonian H: \(\text{out} = \exp(-i H t) \ket{s}\) (or \(\exp(-i H t) \rho_s \exp(i H t)\))

  • Liouvillian superoperator L: \(\text{out} = \text{inv_vec}(\exp(L t) \text{vec}(\rho_s))\)

  • list consisting of a Hamiltonian followed by Lindblad operators.

For time-dependent cases, G can be a function G(t) which takes a time instance t as input and returns the corresponding generator(s).

kraus_propagate(E)

Apply a quantum operation to the state.

Applies the quantum operation E to the state. \(E = [E_1, E_2, \ldots]\) is a set of Kraus operators.

measure(M=None, do='R')

Quantum measurement.

p, res, c
  = measure()                 # measure the entire system projectively
  = measure((1, 4))           # measure subsystems 1 and 4 projectively
  = measure([M_1, M_2, ...])  # perform a general measurement
  = measure(A)                # measure a Hermitian observable A

Performs a quantum measurement on the state.

  • If no M is given, a full projective measurement in the computational basis is performed.

  • If a list/tuple of subsystems is given as the second parameter, only those subsystems are measured, projectively, in the computational basis.

  • A general measurement may be performed by giving a complete set of measurement operators \([M_1, M_2, \ldots]\) as the second parameter. A POVM can be emulated using \(M_i = \sqrt{P_i}\) and discarding the collapsed state.

  • Finally, if the second parameter is a single Hermitian matrix A, the corresponding observable is measured. In this case the second column of p contains the eigenvalue of A corresponding to each measurement result.

p = measure(..., do='P') returns the vector p, where p[k] is the probability of obtaining result k in the measurement. For a projective measurement in the computational basis this corresponds to the ket \(\ket{k}\).

p, res = measure(...) additionally returns the index of the result of the measurement, res, chosen at random from the probability distribution p.

p, res, c = measure(..., do='C') additionally gives c, the collapsed state corresponding to the measurement result res.

fidelity(r)

Fidelity of two states.

Fidelity of two state operators rho and sigma is defined as \(F(\rho, \sigma) = \mathrm{Tr} \sqrt{\sqrt{\rho} \sigma \sqrt{\rho}}\). For state vectors this is equivalent to the overlap, \(F = |\braket{a|b}|\).

Fidelity is symmetric in its arguments and bounded in the interval [0,1].

Todo

Uhlmann’s theorem, Bures metric, monotonicity under TP maps

Todo

quantiki defines fidelity as NC-fidelity^2

See [4], chapter 9.2.2.

Parameters

r (state) – another state

Returns

Fidelity of r and the state itself.

Return type

float

trace_dist(r)

Trace distance of two states.

Trace distance between state operators r and s is defined as \(D(r, s) = \frac{1}{2} \mathrm{Tr}(\sqrt{A^\dagger A})\), where A = r-s.

Equivalently \(D(r, s) = \frac{1}{2} \sum_k |\lambda_k|\), where \(\lambda_k\) are the eigenvalues of A (since A is Hermitian).

Todo

stuff in NC

See [4], chapter 9.2.1.

Parameters

r (state) – another state

Returns

Trace distance between r and the state itself.

Return type

float

schmidt(sys=None, full=False)

Schmidt decomposition.

lambda       = schmidt(sys)
lambda, u, v = schmidt(sys, full=True)

Calculates the Schmidt decomposition of the (pure) state. Subsystems listed in sys constitute part A, the rest forming part B. Vector lambda will contain the Schmidt coefficients.

If required, matrices u and v will contain the corresponding orthonormal Schmidt bases for A and B, respectively, as column vectors, i.e. \(\ket{k}_A = u[:, k], \quad \ket{k}_B = v[:, k]\).

The state is then given by \(\sum_k \lambda_k \ket{k}_A \otimes \ket{k}_B\).

See [4], chapter 2.5.

Parameters
  • sys (Sequence[int]) – subsystem indices

  • full (bool) – if True, returns also the Schmidt bases u and v

Returns

Schmidt coefficients

Return type

array[float]

entropy(sys=None, alpha=1)

Von Neumann or Renyi entropy of the state.

The Renyi entropy of order \(\alpha\), \(S_\alpha(\rho) = \frac{1}{1-\alpha} \log_2 \mathrm{Tr}(\rho^\alpha)\). When \(\alpha = 1\), this coincides with the von Neumann entropy \(S(\rho) = -\mathrm{Tr}(\rho \log_2(\rho))\).

Parameters
  • sys (None, Sequence[int]) – If None, returns the entropy of the state. If a vector of subsystem indices, returns the entropy of entanglement of the state wrt. the partitioning defined by sys. Entropy of entanglement is only defined for pure states.

  • alpha (float) – Renyi entropy order, >= 0.

Returns

Renyi entropy

Return type

float

concurrence(sys=None)

Concurrence of the state.

See [20], [21].

Parameters

sys (Sequence[int]) – subsystem indices

Returns

Concurrence of the state wrt. the given partitioning.

Return type

float

negativity(sys)

Negativity of the state.

See [22], [23]

Parameters

sys (Sequence[int]) – subsystem indices

Returns

Negativity of the state wrt. the given partitioning.

Return type

float

lognegativity(sys)

Logarithmic negativity of the state.

Parameters

sys (Sequence[int]) – subsystem indices

Returns

Logarithmic negativity of the state wrt. the given partitioning, \(\log_2(2 N(\rho) +1)\).

Return type

float

scott(m)

Scott’s average bipartite entanglement measure.

See [24], [25], [26].

Parameters

m (int) – partition size

Returns

Terms of the Scott entanglement measure of the system for the given partition size. When m = 1 this is coincides with the Meyer-Wallach entanglement measure.

Return type

array[float]

locc_convertible(t, sys)

LOCC convertibility of states.

For bipartite pure states s and t, returns True iff self can be converted to t using local operations and classical communication (LOCC). See [4], chapter 12.5.1

Parameters
  • t (state) – another state

  • sys (Sequence[int]) – vector of subsystem indices defining the partition

Returns

True iff s can be LOCC-converted to t

Return type

bool

plot(fig=None, symbols=3)

State tomography plot.

Plots the probabilities of finding a system in this state in the different computational basis states upon measurement. Relative phases are represented by the colors of the bars.

If the state is nonpure, also plots the coherences using a 3D bar plot.

Todo

Matplotlib 2.0 handles 2d and 3d axes differently, so just passing an Axes instance won’t work, hence Figure

Parameters
  • fig (Figure) – figure to plot the state into

  • symbols (int) – how many subsystem labels to show in the tickmarks

Returns

the plot

Return type

Axes, Axes3D

bloch_vector()

Generalized Bloch vector.

Returns

Generalized Bloch vector corresponding to the state.

Return type

array[float]

For an n-subsystem state the generalized Bloch vector is an order-n correlation tensor defined in terms of the standard Hermitian tensor basis B corresponding to state dimensions:

\[A_{ijk\ldots} = \sqrt{D} \: \mathrm{Tr}(\rho B_{ijk\ldots}),\]

where D = prod(self.dims()). A is always real since \(\rho\) is Hermitian. For valid, normalized states

  • self.purity() \(\le 1 \implies\) norm(A, 'fro') \(\le \sqrt{D}\)

  • self.trace() \(= 1 \implies\) A[0, 0, ..., 0] \(= 1\)

E.g. for a single-qubit system norm(A, 'fro') <= sqrt(2).

tensor(*arg)

Tensor product of states.

Returns the tensor product state of states s1, s2, …

static bloch_state(A: array[float], dim: Optional[Sequence[int]] = None)

State corresponding to a generalized Bloch vector.

Parameters
  • A (array[float]) – generalized Bloch vector

  • dim (Optional[Sequence[int]]) – dimension vector. If None, we use dim = np.sqrt(A.shape).astype(int).

Returns

State corresponding to the given generalized Bloch vector.

Return type

state

The inverse operation of bloch_vector. A is defined in terms of the standard hermitian tensor basis B corresponding to the dimension vector dim.

\[\rho = \sum_{ijk\ldots} A_{ijk\ldots} B_{ijk\ldots} / \sqrt{D},\]

where D = prod(dim). For valid states norm(A, 'fro') <= sqrt(D).

static werner(p, d=2)

Werner states.

Parameters
  • p (float) – symmetric part weight, \(p \in [0,1]\)

  • d (int) – dimension

Returns

Werner state

Return type

State

For every \(d \ge 2\), Werner states [27] are a linear family of bipartite \(d \times d\) dimensional quantum states that are invariant under all local unitary rotations of the form \(U \otimes U\), where \(U \in SU(d)\).

Every Werner state is a linear combination of the identity and SWAP operators. Alternatively, they can be understood as convex combinations of the appropriately scaled symmetric and antisymmetric projectors \(P_\text{sym} = \frac{1}{2}(\I+\text{SWAP})\) and \(P_\text{asym} = \frac{1}{2}(\I-\text{SWAP})\):

\[\rho_\text{Werner} = p \frac{2 P_\text{sym}}{d(d+1)} +(1-p) \frac{2 P_\text{asym}}{d(d-1)}.\]

p is the weight of the symmetric part of the state. The state is entangled iff p < 1/2, and pure only when d = 2 and p = 0, at which point it becomes the 2-qubit singlet state.

For every d, the Werner family of states includes the fully depolarized state \(\frac{\I}{d^2}\), obtained with \(p = \frac{d+1}{2d}\).

The Werner states are partial-transpose dual to isotropic states with the parameter \(p' = \frac{2p-1}{d}\).

static isotropic(p, d=2)

Isotropic states.

Parameters
  • p (float) – maximally entangled part weight, \(p \in [0,1]\)

  • d (int) – dimension

Returns

isotropic state

Return type

State

For every \(d \ge 2\), isotropic states [27] are a linear family of bipartite \(d \times d\) dimensional quantum states that are invariant under all local unitary rotations of the form \(U \otimes U^*\), where \(U \in SU(d)\).

Every isotropic state is a linear combination of the identity operator and the projector to the maximally entangled state \(\ket{\cup} = \sum_{k=0}^{d-1} \ket{k, k}\):

\[\rho_\text{Iso} = \frac{p}{d}\ket{\cup}\bra{\cup} +\frac{1-p}{d^2-1} (\I-\frac{1}{d}\ket{\cup}\bra{\cup}).\]

p is the weight of the cup state projectorin the mixture. The state is entangled iff p > 1/d, and pure and fully entangled iff p = 1.

For every d, the isotropic family of states includes the fully depolarized state \(\frac{\I}{d^2}\), obtained with \(p = \frac{1}{d^2}\).

Isotropic states are partial-transpose dual to Werner states.