We can measure the similarity between two quantum states using the fidelity. Given two states and , it is defined as

This expression becomes much simpler if we have pure states involved. Consider two pure states and . The fidelity then reduces to the absolute value of their overlap:

In other words, the fidelity between two pure states is equivalent to their inner product, which is super easy to compute!

Fill in the code to calculate the fidelity between two pure states.

Hint

You may find the functions np.inner and np.abs quite useful!


def pure_states_fidelity(psi,phi):
"""Compute the fidelity between two pure states of the same size.
Args:
psi (tensor[complex]): The vector representation of a quantum state.
phi (tensor[complex]): The vector representation of a quantum state.
Returns:
(float): A number that represents the fidelity.
"""

##################
# YOUR CODE HERE #
##################

# RETURN THE FIDELITY
pass


or to submit your code

To interact with codercises, please switch to a larger screen size.

Learning Objectives:

  • Define and calculate the fidelity between two quantum states.
  • Write down the relation between fidelity and trace distance.