qml.math.trace_distance

trace_distance(state0, state1, check_state=False, c_dtype='complex128')[source]

Compute the trace distance between two quantum states.

\[T(\rho, \sigma)=\frac12\|\rho-\sigma\|_1 =\frac12\text{Tr}\left(\sqrt{(\rho-\sigma)^{\dagger}(\rho-\sigma)}\right)\]

where \(\|\cdot\|_1\) is the Schatten \(1\)-norm.

The trace distance measures how close two quantum states are. In particular, it upper-bounds the probability of distinguishing two quantum states.

Parameters
  • state0 (tensor_like) – (2**N, 2**N) or (batch_dim, 2**N, 2**N) density matrix.

  • state1 (tensor_like) – (2**N, 2**N) or (batch_dim, 2**N, 2**N) density matrix.

  • check_state (bool) – If True, the function will check the states’ validity (shape and norm).

  • c_dtype (str) – Complex floating point precision type.

Returns

Trace distance between state0 and state1

Return type

float

Examples

The trace distance between two equal states is always zero:

>>> x = np.array([[1, 0], [0, 0]])
>>> qml.math.trace_distance(x, x)
0.0

It is possible to use state vectors by first transforming them into density matrices via the reduce_statevector() function:

>>> y = qml.math.reduce_statevector(np.array([0.2, np.sqrt(0.96)]), [0])
>>> qml.math.trace_distance(x, y)
0.9797958971132713

The quantum states can also be provided as batches of density matrices:

>>> batch0 = np.array([np.eye(2) / 2, np.ones((2, 2)) / 2, np.array([[1, 0],[0, 0]])])
>>> batch1 = np.array([np.ones((2, 2)) / 2, np.ones((2, 2)) / 2, np.array([[1, 0],[0, 0]])])
>>> qml.math.trace_distance(batch0, batch1)
array([0.5, 0. , 0. ])

If only one of the two states represent a single element, then the trace distances are taken with respect to that element:

>>> rho = np.ones((2, 2)) / 2
>>> qml.math.trace_distance(rho, batch0)
array([0.5       , 0.        , 0.70710678])

Contents

Using PennyLane

Development

API

Internals