qml.math.fidelity

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

Compute the fidelity for two states (given as density matrices) acting on quantum systems with the same size.

The fidelity for two mixed states given by density matrices \(\rho\) and \(\sigma\) is defined as

\[F( \rho , \sigma ) = \text{Tr}( \sqrt{\sqrt{\rho} \sigma \sqrt{\rho}})^2\]

Note

It supports all interfaces (NumPy, Autograd, Torch, TensorFlow and Jax). The second state is coerced to the type and dtype of the first state. The fidelity is returned in the type of the interface of the first state.

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 validity of both states; that is, (shape, trace, positive-definitiveness) for density matrices.

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

Returns

Fidelity between the two quantum states.

Return type

float

Example

To find the fidelity between two state vectors, call dm_from_state_vector() on the inputs first, e.g.:

>>> state0 = qml.math.dm_from_state_vector([0.98753537-0.14925137j, 0.00746879-0.04941796j])
>>> state1 = qml.math.dm_from_state_vector([0.99500417+0.j, 0.09983342+0.j])
>>> qml.math.fidelity(state0, state1)
0.9905158135644924

To find the fidelity between two density matrices, they can be passed directly:

>>> state0 = [[1, 0], [0, 0]]
>>> state1 = [[0, 0], [0, 1]]
>>> qml.math.fidelity(state0, state1)
0.0

Contents

Using PennyLane

Release news

Development

API

Internals