The objective of this codercise is to observe the outputs of the QPE subroutine when arbitrary states are prepared on the target wire. Prepare the target wires in a superposition of the -gate eigenvectors and and run the quantum phase estimation algorithm on estimation wires to observe the results. For this the prepare_eigenvector_superposition function has been given to you. You can test it out by uncommenting the examples given in the code or prepare your own state on the target wires by modifying alpha and beta arguments to observe changes on the measurement probabilities of the estimation wires. Change the value of the variable done to True once you have finished testing out the code. Recall that

where we expect to observe the eigenphases and (i.e., the states and respectively) on the estimation wires.

dev = qml.device("default.qubit", wires=5)
estimation_wires = [0, 1, 2]
target_wires = [3]

def prepare_eigenvector_superposition(alpha, beta):
# Normalize alpha and beta
norm_squared = np.abs(alpha) ** 2 + np.abs(beta) ** 2
norm = np.sqrt(norm_squared)
state = np.array([alpha/norm, beta/norm])
# Prepare the state
qml.MottonenStatePreparation(state, wires=target_wires)


@qml.qnode(dev)
def qpe(unitary):
"""Estimate the phase for a given unitary.
Args:
unitary (array[complex]): A unitary matrix.

Returns:
array[float]: Probabilities on the estimation wires.
"""
# MODIFY ALPHA, BETA TO PREPARE EIGENVECTOR
prepare_eigenvector_superposition(0, 1)
# prepare_eigenvector_superposition(1, 0)
# prepare_eigenvector_superposition(1/np.sqrt(2), 1/np.sqrt(2))
# OR UNCOMMENT LINES ABOVE TO PREPARE THE STATE OF YOUR CHOICE

qml.QuantumPhaseEstimation(
unitary,
target_wires=target_wires,
estimation_wires=estimation_wires,
)

or to submit your code

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

Learning Objectives:

  • Analyze the outcomes of the QPE subroutine when the target wires are prepared in an arbitrary state.