Let's implement the same Hadamard-oracle-Hadamard circuit, but now for multiple solutions:

Since seemed to be the interesting state, we can plot how the probability of observing changes with the number of solutions.

Implement the circuit above for a set of solutions combos, and return probabilities. As before, you are given multisol_oracle_matrix(combos), which returns the associated oracle in matrix form.

Hitting submit will plot the probability of observing as a function of the size of the solution set; as for a single solution, this does not depend on the secret combinations themselves. What pattern do you observe?

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

@qml.qnode(dev)
def multisol_hoh_circuit(combos):
"""A circuit which applies Hadamard, multi-solution oracle, then Hadamard.
Args:
combos (list[list[int]]): A list of secret bit strings.

Returns:
array[float]: Probabilities for observing different outcomes.
"""

##################
# 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:

  • Implement the Deutsch–Jozsa algorithm.
  • Compare the algorithmic performance of Deutsch–Jozsa to deterministic and classically random strategies.