A6: Generate One-hot Superposition State III

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Writer: ST12

Editorial

In the intended solution for problem A5, the depth of the quantum circuit would be n+2n + 2, which does not solve this problem. So, how can we improve the quantum circuit?

Let's examine the following example with 6 qubits:

Wstate_log

This quantum circuit generates the quantum state 16(100000+010000+001000+000100+000010+000001)\frac{1}{\sqrt{6}} (\ket{100000} + \ket{010000} + \ket{001000} + \ket{000100} + \ket{000010} + \ket{000001}). We will explain each block of the quantum circuit separated by barriers 1.

In the 1st block, we apply an XX gate to the first qubit.

000000X(0)100000\begin{equation} \ket{000000} \xrightarrow{X(0)} \ket{100000} \end{equation}

In the 2nd block, we create an equal superposition of 100000\ket{100000} and 010000\ket{010000}.

100000CRy(θ1,0,1)CX(1,0)36100000+36010000\begin{equation} \ket{100000} \xrightarrow{CRy(\theta_1,0,1)} \xrightarrow{CX(1,0)} \sqrt{\frac{3}{6}} \ket{100000} + \sqrt{\frac{3}{6}} \ket{010000} \end{equation}

In the 3rd block, we further split 100000\ket{100000} and 010000\ket{010000}.

36100000+36010000CRy(θ2,0,2)CX(2,0)CRy(θ3,1,3)CX(3,1)16100000+16010000+26001000+26000100\begin{align} &\sqrt{\frac{3}{6}} \ket{100000} + \sqrt{\frac{3}{6}} \ket{010000} \nonumber\\ &\xrightarrow{CRy(\theta_2,0,2)} \xrightarrow{CX(2,0)} \xrightarrow{CRy(\theta_3,1,3)} \xrightarrow{CX(3,1)} \sqrt{\frac{1}{6}} \ket{100000} + \sqrt{\frac{1}{6}} \ket{010000} + \sqrt{\frac{2}{6}} \ket{001000} + \sqrt{\frac{2}{6}} \ket{000100} \end{align}

Finally, the transition in the 4th block is expressed as follows:

16100000+16010000+26001000+26000100CRy(θ4,2,4)CX(4,2)CRy(θ5,3,5)CX(5,3)16(100000+010000+001000+000100+000010+000001)\begin{align} &\sqrt{\frac{1}{6}} \ket{100000} + \sqrt{\frac{1}{6}} \ket{010000} + \sqrt{\frac{2}{6}} \ket{001000} + \sqrt{\frac{2}{6}} \ket{000100} \xrightarrow{CRy(\theta_4,2,4)} \xrightarrow{CX(4,2)} \nonumber\\ &\xrightarrow{CRy(\theta_5,3,5)} \xrightarrow{CX(5,3)} \frac{1}{\sqrt{6}} (\ket{100000} + \ket{010000} + \ket{001000} + \ket{000100} + \ket{000010} + \ket{000001}) \end{align}

The rotation angles θi\theta_i are given by:

θ1=2arctan(1)θ2=θ3=2arctan(1)θ4=θ5=2arctan(1)\begin{align} \theta_1 &= 2 \arctan{(\sqrt{1})}\\ \theta_2 &= \theta_3 = 2 \arctan{(\sqrt{1})}\\ \theta_4 &= \theta_5 = 2 \arctan{(\sqrt{1})}\\ \end{align}

This quantum circuit has a depth of 4, which is much smaller than the intended solution for A5.

Next, let's generalize these operations. The problem is the way to determine the rotation angles.

For the case with 6 qubits, consider the following tree structure:

Wstate_log

Each node (a,b)(i,j)(a, b)^{(i, j)} represents an operation where a portion of the ii-th qubit's amplitude, specifically a/n\sqrt{a/n} out of b/n\sqrt{b/n}, is transferred to the jj-th qubit. Thus, the rotation angle θ\theta of the controlled RyR_y gate with control on qubit ii and target on qubit jj can be determined by solving the following simultaneous equations:

{cos(θ2)=ansin(θ2)=ban\begin{equation} \left\{ \, \begin{aligned} & \cos\left(\frac{\theta}{2}\right) = \sqrt{\frac{a}{n}} \\ & \sin\left(\frac{\theta}{2}\right) = \sqrt{\frac{b-a}{n}} \end{aligned} \right. \end{equation}

Solving this equation yields the following solution within the range 0θ2π0 \leq \theta \leq 2\pi:

θ=2arctan(baa)\begin{equation} \theta = 2 \arctan{\left(\sqrt{\frac{b-a}{a}}\right)} \end{equation}

In this tree structure, for the parent node (a,b)(i,j)(a, b)^{(i, j)}, the child nodes above and below are represented by (b/2/2,b/2)(i,?)(\lfloor\lfloor b/2 \rfloor/2\rfloor,\lfloor b/2 \rfloor)^{(i, ?)} and (b/2/2,b/2)(j,?)(\lfloor \lceil b/2 \rceil/2 \rfloor,\lceil b/2 \rceil)^{(j, ?)}, respectively. If a=0a = 0, such an operation is not defined. The target qubit index jj is assigned to each node in the order from 2 to nn, starting from nodes closest to the tree root.

By designing the quantum circuit based on this algorithm, the circuit depth can be reduced to 2log2n+12 \lceil \log_{2}{n} \rceil + 1, solving this problem.

For implementation, methods like breadth-first search can be used for constructing the tree structure.

Sample Code

Below is a sample program:

import math
 
from qiskit import QuantumCircuit
 
 
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(0)
 
    count = 1
 
    # queue = [(a, b, control bit of CRy), ...]
    queue = [(n // 2, n, 0)]
 
    # breadth first search
    while len(queue):
        a, b, control = queue.pop(0)
 
        if a == 0:
            continue
 
        theta = 2 * math.atan(math.sqrt((b - a) / a))
 
        qc.cry(theta, control, count)
        qc.cx(count, control)
 
        queue.append(((b // 2) // 2, b // 2, control))
        queue.append((math.ceil(b / 2) // 2, math.ceil(b / 2), count))
 
        count += 1
 
    return qc

Footnotes

  1. In Qiskit, barriers (qc.barrier()) are counted towards the depth, so please be careful not to include them in the code you submit.