qml.math.fidelity_statevector

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

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

The fidelity for two pure states given by state vectors \(\ket{\psi}\) and \(\ket{\phi}\) is defined as

\[F( \ket{\psi} , \ket{\phi}) = \left|\braket{\psi, \phi}\right|^2\]

This is faster than calling pennylane.math.fidelity() on the density matrix representation of pure states.

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) or (batch_dim, 2**N) state vector.

  • state1 (tensor_like) – (2**N) or (batch_dim, 2**N) state vector.

  • check_state (bool) – If True, the function will check the validity of both states; that is, the shape and the norm

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

Returns

Fidelity between the two quantum states.

Return type

float

Example

Two state vectors can be used as arguments and the fidelity (overlap) is returned, e.g.:

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

Contents

Using PennyLane

Release news

Development

API

Internals