A2: Generate Uniform Superposition State

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Writer: admin

Editorial

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

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

When measuring one qubit, we observe either of the computational basis states 0\ket{0} or 1\ket{1} with equal probabiliy. 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...0n+...+1...1n)=12ni=02n1i.\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 an nn-qubit uniform superposition by applying a Hadamard gate to each of the nn qubits:

0...0nHn12n(0...0n+...+1...1n)\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 nn 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