Editorial
In problem A1, we prepared the "uniform superposition" state on a single qubit.
Now, how can we express the state of qubits when each qubit is in a uniform superposition?
When measuring one qubit, we observe either of the computational basis states or with equal probabiliy. Therefore, when measuring qubits in sequence, we can observe any one of the possible computational basis states — from to — with equal probabilities of .
Consequently, the state of the uniform superposition state of all computational basis states can be expressed as
As a result, we can prepare an -qubit uniform superposition by applying a Hadamard gate to each of the qubits:
Sample Code
Below is a sample program:
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.h(range(n))
return qc
Alternatively, you can use a for-loop to apply Hadamard gates in-turn.
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range(n):
qc.h(i)
return qc