In this module, our main objective will be to discover the secret combination that opens a lock. Suppose that such combination is described by bits. The naive method would be to try all combinations one by one. Would a quantum computer make this task easier? Naively, it looks as if we could create a uniform superposition over all -bit strings and immediately determine the correct combination. After all, the uniform superposition encodes all possible combinations in a single state!

To create a uniform superposition over all possible -qubit basis states, we can apply

where we use bold letters for strings of bits, In particular, the string of zeros will be denoted by . Thus, we can write the uniform superposition , where is the -fold tensor product of Hadamard gates. As a circuit:

This will prepare a state that includes the correct combination (or "solution") , so if we measure, we should find it.

Fill in the following code to create the uniform superposition over qubits. It will also plot the probability of observing different outcomes. Does putting the circuit in a uniform superposition help us break the lock?

Note. The pass is a placeholder you will replace with your code.

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

@qml.qnode(dev)
def naive_circuit():
"""Create a uniform superposition and return the probabilities.

Returns:
array[float]: Probabilities for observing different outcomes.
"""
for wire in range(n_bits):

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

pass # REPLACE PASS

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:

  • Explain why quantum superposition does not automatically imply exponential speedups.
  • Write a uniform superposition over multiple qubits as a tensor product.