A2: Generate Uniform Superposition State

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

Writer:admin

Editorial

In problem A1, we prepared the "uniform superposition state" on 11 qubit.

Now, how can we express the state of nn qubits when each of the nn qubits is in a uniform superposition state?

When measuring one qubit, we observe either of the computational basis states ∣0⟩\ket{0} or ∣1⟩\ket{1} with equal probability 1/21/2. Therefore, when measuring nn qubits in sequence, we can observe any one of the 2n2^n possible computational basis states — from ∣0...0⟩\ket{0...0} to ∣1...1⟩\ket{1...1} — with equal probabilities of 1/2n1/2^{n}.

Consequently, the state ∣A⟩\ket{A} of the uniform superposition state of all 2n2^n computational basis states can be expressed as

∣A⟩=12n(∣0...0⟩n+...+∣1...1⟩n)=12n∑i=02n−1∣i⟩\begin{align} \ket{A} & = \frac{1}{\sqrt{2^n}} (\ket{0...0}_n + ... + \ket{1...1}_n) \nonumber\\ &= \frac{1}{\sqrt{2^n}} \sum_{i=0}^{2^n-1} \ket{i} \end{align}

As a result, we can prepare a uniform superposition state by applying a Hadamard gate to each of the nn qubits:

∣0...0⟩n→H⊗n12n(∣0...0⟩n+...+∣1...1⟩n)\begin{equation} \ket{0...0}_n \xrightarrow{H^{\otimes n}} \frac{1}{\sqrt{2^n}} (\ket{0...0}_n + ... + \ket{1...1}_n) \end{equation}

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 the 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