In this set of codercises we implement the (quantum phase estimation) QPE subroutine to find the eigenvalue of a unitary matrix with eigenvector in the following way:

  1. We will implement a helper function that computes .
  2. We will write a subroutine to apply these controlled on a set of estimation wires.
  3. We will implement the circuit end-to-end to obtain the phase and eigenvalue.

Let's get started with step 1. Given a unitary matrix , compute the value of a higher power, . You can use the matrix_power function from NumPy's linear algebra library.

def U_power_2k(unitary, k):
""" Computes U at a power of 2k (U^2^k)
Args:
unitary (array[complex]): A unitary matrix
Returns:
array[complex]: the unitary raised to the power of 2^k
"""
##################
# YOUR CODE HERE #
##################
pass

# Try out a higher power of U
U = qml.T.compute_matrix()
print(U)

U_power_2k(U, 2)

or to submit your code

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

Learning Objectives:

  • Define the controlled-U oracle.
  • Derive the QPE circuit end-to-end.