A4: Generate state 13(∣0⟩+∣1⟩+∣2⟩))\frac{1}{\sqrt{3}} (\ket{0} + \ket{1} + \ket{2})) I

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

Writer:admin

Editorial

The objective is to prepare a superposition state of the three computational basis states ∣00⟩, ∣10⟩, ∣01⟩\ket{00},\ \ket{10},\ \ket{01}. Note we are treating the leftmost qubit as the least significant.

A superposition state involving a non-power-of-two number of computational basis states can be prepared by using controlled-Hadamard (CHCH) gates.

First, applying a Hadamard gate to the 11st qubit effects the transformation

∣00⟩→H(0)12(∣00⟩+∣10⟩)\begin{equation} \ket{00} \xrightarrow{H(0)} \frac{1}{\sqrt{2}} (\ket{00} + \ket{10}) \end{equation}

Subsequently applying a controlled-Hadamard gate with the 11st qubit as the control qubit and the 22nd as the target qubit effects

12(∣00⟩+∣10⟩)→CH(0,1)12∣00⟩+12(∣10⟩+∣11⟩)\begin{equation} \frac{1}{\sqrt{2}} (\ket{00} + \ket{10}) \xrightarrow{CH(0, 1)} \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{2}(\ket{10} + \ket{11}) \end{equation}

Finally, applying a controlled-XX gate with the 11st qubit as the target qubit and the 22nd as the control qubit effects

12∣00⟩+12(∣10⟩+∣11⟩)→CX(1,0)12∣00⟩+12(∣10⟩+∣01⟩)\begin{equation} \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{2}(\ket{10} + \ket{11}) \xrightarrow{CX(1, 0)} \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{2}(\ket{10} + \ket{01}) \end{equation}

In this way, a superposition state of the three computational basis states ∣00⟩, ∣10⟩, ∣01⟩\ket{00},\ \ket{10},\ \ket{01} is prepared.

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
 
def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
 
    qc.h(0)
    qc.ch(0, 1)
    qc.cx(1, 0)
 
    return qc