To implement the behaviour of an oracle, the query qubits can be used to trigger a phase flip on the auxiliary qubit when they are in the solution state. More concretely, we can do this using a multi-controlled gate with control string , and the auxiliary register in the state:

This method is called the phase kickback trick, since the phase is "kicked back" to the query register. Here is a picture of the implementation of :

(Recall that white dots indicate the control bit is "0" and black dots "1". The combination here is simply meant to illustrate an arbitrary control string.)

Define the oracle operator using the MultiControlledX gate from PennyLane.

Tip. MultiControlledX(control_wires, wires, control_values) has a specified set of control_wires, a single target wire given by wires, and a string of control values, e.g., control_values = "1011" rather than a list of bits [1,0,1,1].

or to submit your code

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

Learning Objectives:

  • Explain how the phase kickback trick works and why it is useful for Grover search.
  • Implement the diffusion and oracle operators using multi-controlled-X gates.