We can generalize the pair-testing scheme by applying Hadamards to every qubit! Here is the circuit diagram:

The layer of Hadamards is called the Hadamard transform. Let's see what this circuit does in the case of a single solution.

Implement the circuit above, consisting of a Hadamard transform, an oracle, and a Hadamard transform. The oracle is provided as oracle_matrix(combo), which you can invoke using the QubitUnitary() function.

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

@qml.qnode(dev)
def hoh_circuit(combo):
"""A circuit which applies Hadamard-oracle-Hadamard and returns probabilities.
Args:
combo (list[int]): A list of bits representing a secret combination.

Returns:
list[float]: Measurement outcome probabilities.
"""

##################
# YOUR CODE HERE #
##################

return qml.probs(wires=range(n_bits))

or to submit your code

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

Learning Objectives:

  • Define the Hadamard transform.
  • Understand the effect of applying an oracle between Hadamard transforms.