Recall that multi-solution oracle with solutions is just a product of the single-solution oracles:

To implement Grover search for multiple solutions, we will just plop this new multi-solution oracle into the original circuit for a single Grover step:

Let's start by coding up this new oracle. Create an oracle for a random solution set of a given size using the MultiControlledX gate. Remember that this takes a string for control_values (e.g.,"11011") as a parameter rather than a list of bits.

n_bits = 5
query_register = list(range(n_bits))
aux = [n_bits]
all_wires = query_register + aux
dev = qml.device("default.qubit", wires=all_wires)


def oracle_multi(combos):
"""Implement multi-solution oracle using sequence of multi-controlled X gates.

Args:
combos (list[list[int]]): A list of solutions.
"""
for combo in combos:
combo_str = "".join(str(j) for j in combo)
##################
# YOUR CODE HERE #
##################
pass

or to submit your code

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

Learning Objectives:

  • Describe the geometry of Grover search for multiple solutions.
  • Compute the scaling of Grover search for multiple solutions.