In this set of codercises, we will implement the phase kickback technique, introduced in the theory section on the right. We will the use it to calculate the eigenvalues of a unitary operator.

The phase kickback circuit is shown below:

We will implement this circuit to see if we can detect a phase of .

You are given a unitary that is promised to be either the gate or the gate. Write a quantum program using phase kickback that will result in the state with a probability of on the first qubit if is applied and with a probability of on the first qubit if is applied.

Hint.

Use qml.ControlledQubitUnitary or qml.ctrl to apply unitaries with control bits.

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def guess_the_unitary(unitary):
"""Given a unitary that performs a Z or a -Z operation
on a qubit, guess which one it is.
Args:
U (array[complex]): A unitary matrix, guaranteed to be either Z or -Z.
Returns:
array [int]: Probabilities on on the first qubit
using qml.probs()
"""
##################
# YOUR CODE HERE #
##################
pass

# Z gate
U = qml.PauliZ.compute_matrix()

# -Z gate
# U = (-1)*qml.PauliZ.compute_matrix()

print(guess_the_unitary(U))

or to submit your code

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

Learning Objectives:

  • State the motivation behind the quantum phase estimation (QPE) subroutine.
  • List some applications of QPE.
  • Describe and implement the phase kickback technique.
  • Estimate a phase using phase kickback.