A3: Generate State 13(∣100⟩+∣010⟩+∣001⟩)\frac{1}{\sqrt{3}}\lparen\ket{100}+\ket{010}+\ket{001}\rparen

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 300 points

Writer:ST12

Editorial

The desired state is a superposition of the computational basis states ∣100⟩, ∣010⟩, ∣001⟩\ket{100},\ \ket{010},\ \ket{001}, each with the same probability amplitude.

To generate such a superposition of multiple computational basis states with equal probability amplitudes, we can use the RyR_y gate, a rotation gate around the yy-axis. For more on rotation gates, please refer to the QPC001 A5.

First, apply the XX gate to the zero state ∣000⟩\ket{000}.

∣000⟩→X(0)∣100⟩\begin{equation} \ket{000} \xrightarrow{X(0)} \ket{100} \end{equation}

Next, apply a controlled RyR_y gate to this quantum state ∣100⟩\ket{100} to generate a superposition of ∣100⟩\ket{100} and ∣110⟩\ket{110}. Considering that the amplitude of ∣100⟩\ket{100} should match the target amplitude 1/31/\sqrt{3}, the rotation angle θ1\theta_1 can be determined by solving the following simultaneous equations.

{ cos⁡(θ12)=13sin⁡(θ12)=23\begin{equation} \left\{ \, \begin{aligned} & \cos\left(\frac{\theta_1}{2}\right) = \frac{1}{\sqrt{3}} \\ & \sin\left(\frac{\theta_1}{2}\right) = \sqrt{\frac{2}{3}} \end{aligned} \right. \end{equation}

Solving this, we obtain the following solution within the range 0≤θ1≤2π0 \leq \theta_1 \leq 2\pi.

θ1=2arctan⁡(2)\begin{equation} \theta_1 = 2 \arctan{(\sqrt{2})} \end{equation}

Thus, we apply a controlled RyR_y gate with rotation angle θ1\theta_1, with the first qubit as the control bit and the second as the target bit.

∣100⟩→CRy(θ1,0,1)13∣100⟩+23∣110⟩\begin{equation} \ket{100} \xrightarrow{CRy(\theta_1, 0, 1)} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}} \ket{110} \end{equation}

Next, apply a controlled XX gate, using the second qubit as the control bit and the first qubit as the target, to transform the state ∣110⟩\ket{110} into ∣010⟩\ket{010}.

13∣100⟩+23∣110⟩→CX(0,1)13∣100⟩+23∣010⟩\begin{equation} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}} \ket{110} \xrightarrow{CX(0, 1)} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}}\ket{010} \end{equation}

Repeating this operation with a controlled RyR_y gate and a controlled XX gate once more generates 13∣010⟩+13∣001⟩\frac{1}{\sqrt{3}} \ket{010} + \frac{1}{\sqrt{3}} \ket{001} from 23∣010⟩\sqrt{\frac{2}{3}}\ket{010}.

The required rotation angle θ2\theta_2 can be determined to halve the amplitude of 23∣010⟩\sqrt{\frac{2}{3}}\ket{010} by solving the following equations.

{ cos⁡(θ22)=12sin⁡(θ22)=12\begin{equation} \left\{ \, \begin{aligned} & \cos\left(\frac{\theta_2}{2}\right) = \frac{1}{\sqrt{2}} \\ & \sin\left(\frac{\theta_2}{2}\right) = \frac{1}{\sqrt{2}} \end{aligned} \right. \end{equation}

Solving this, we obtain the following solution within the range 0≤θ2≤2π0 \leq \theta_2 \leq 2\pi.

θ2=2arctan⁡(1)=π2\begin{equation} \theta_2 = 2 \arctan{(1)} = \frac{\pi}{2} \end{equation}

We then apply a controlled RyR_y gate with this rotation angle θ2\theta_2, using the second qubit as the control bit and the third as the target.

13∣100⟩+23∣010⟩→CRy(θ2,1,2)13(∣100⟩+∣010⟩+∣011⟩)\begin{equation} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}}\ket{010} \xrightarrow{CRy(\theta_2,1, 2)} \frac{1}{\sqrt{3}} (\ket{100} + \ket{010} + \ket{011}) \end{equation}

Finally, apply a controlled XX gate with the third qubit as the target and the second as the control bit.

13(∣100⟩+∣010⟩+∣011⟩)→CX(2,1)13(∣100⟩+∣010⟩+∣001⟩)\begin{equation} \frac{1}{\sqrt{3}} (\ket{100} + \ket{010} + \ket{011}) \xrightarrow{CX(2, 1)} \frac{1}{\sqrt{3}} (\ket{100} + \ket{010} + \ket{001}) \end{equation}

Summing up these operations, we get the following transformation.

∣000⟩→X(0)∣100⟩→CRy(θ1,0,1)13∣100⟩+23∣110⟩→CX(1,0)13∣100⟩+23∣010⟩→CRy(θ2,1,2)13(∣100⟩+∣010⟩+∣011⟩)→CX(2,1)13(∣100⟩+∣010⟩+∣001⟩)\begin{align} \ket{000} &\xrightarrow{X(0)} \ket{100} \nonumber\\ &\xrightarrow{CRy(\theta_1, 0, 1)} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}} \ket{110} \nonumber\\ &\xrightarrow{CX(1, 0)} \frac{1}{\sqrt{3}} \ket{100} + \sqrt{\frac{2}{3}} \ket{010} \nonumber\\ &\xrightarrow{CRy(\theta_2, 1, 2)} \frac{1}{\sqrt{3}} (\ket{100} + \ket{010} + \ket{011}) \nonumber \\ &\xrightarrow{CX(2, 1)} \frac{1}{\sqrt{3}} (\ket{100} + \ket{010} + \ket{001}) \end{align}

The corresponding quantum circuit is shown as follows.

Sample Code

Below is a sample program:

import math
 
from qiskit import QuantumCircuit
 
 
def solve() -> QuantumCircuit:
    qc = QuantumCircuit(3)
 
    theta1 = 2 * math.atan(math.sqrt(2))
    theta2 = 2 * math.atan(1)
 
    qc.x(0)
    qc.cry(theta1, 0, 1)
    qc.cx(1, 0)
    qc.cry(theta2, 1, 2)
    qc.cx(2, 1)
 
    return qc