Now that we've seen how Grover's search can be formulated using QSP, let's implement it using PennyLane.

Your task is to build a quantum function that implements a QSP sequence for two iterations of Grover's search. Use the same -rotation encoding for the parameter as introduced in section 2.

The required angles for the QSP sequence can be found using qml.poly_to_angles. Recall that for two iterations (), the expected Chebyshev polynomial of the first kind is .

Hint.

Think about what measurement you should use to get the QSP polynomial out of the circuit and be careful with factors of two in the angles for the rotations.

target_poly = [] # Coefficients of the polynomial ordered from lowest to highest power

RZ_angles = qml.poly_to_angles(target_poly, "QSP") # Get the QSP angles from PennyLane

a_array = np.linspace(-1,1,200) # Array of 'a' values (overlaps) to evaluate the polynomial over

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

@qml.qnode(dev)

def qsp():
"""
This quantum function implements a QSP sequence for Grovers search
and returns an array that contains the information to extract the polynomial

"""
# Start from the last element of the tuple of angles k,k-1,k-2,...,1
# iterative process backwards in the tuple of angles
# Z-rotation
# X-rotation
# Last Z-rotation
return # The QSP polynomial is encoded here
P_a_QSP = # Array containing P(a) after two iterations of Grover's search

or to submit your code

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

Learning Objectives:

  • Define quantum signal processing sequences.
  • Implement QSP sequences for amplitude amplification.