A4: Generate State 12(∣0⟩−∣2n−1⟩)\frac{1}{\sqrt{2}}\lparen\ket{0}-\ket{2^{n}-1}\rparen II

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 100 points

Writer:ST12

Editorial

The expected solution for Problem A3 has a quantum circuit depth of n+1n+1, which exceeds the depth limit of this problem. So, how should we design the quantum circuit?

To reduce the depth of the quantum circuit, it's essential to avoid continuously applying quantum gates to the same qubit. Let’s take a look at the example of a 44-qubit quantum circuit below:

The difference from the expected solution for Problem A3 is that the control qubit of the rightmost controlled XX gate has been changed from the 11st qubit to the 22nd qubit.

In this case, the rightmost controlled gate acts on the 22nd and 44th qubits, while the adjacent gate to the left operates on the 11st and 33rd qubits. Since these operations involve different qubit pairs, they can be executed simultaneously, reducing the quantum circuit depth by one.

Let’s examine the transition of the quantum states. Until the application of the second controlled XX gate, it is the same as the expected solution for Problem A3.

∣0000⟩→H(0)→CX(0,1)→CX(0,2)12(∣0000⟩+∣1110⟩)\begin{equation} \ket{0000} \xrightarrow{H(0)} \xrightarrow{CX(0,1)}\xrightarrow{CX(0,2)} \frac{1}{\sqrt{2}} \lparen \ket{0000} + \ket{1110} \rparen \end{equation}

Next, apply a controlled XX gate with the 22nd qubit as the control qubit and the 44th qubit as the target qubit.

12(∣0000⟩+∣1110⟩)→CX(1,3)12(∣0000⟩+∣1111⟩)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0000} + \ket{1110} \rparen \xrightarrow{CX(1,3)} \frac{1}{\sqrt{2}} \lparen \ket{0000} + \ket{1111} \rparen \end{equation}

Finally, by applying a ZZ gate, the phase of ∣11⋯11⟩\ket{11 \cdots 11} is inverted.

12(∣0...0⟩+∣1...1⟩)→Z(0)12(∣0...0⟩−∣1...1⟩)\begin{equation} \frac{1}{\sqrt{2}} \lparen \ket{0...0} + \ket{1...1} \rparen \xrightarrow{Z(0)} \frac{1}{\sqrt{2}} \lparen \ket{0...0} - \ket{1...1} \rparen \end{equation}

When generalizing this idea to a quantum circuit with nn qubits, first apply a Hadamard gate to the 11st qubit and a controlled XX gate with the 11st qubit as the control qubit and the 22nd as the target qubit. Then, for i=1,2,…i = 1, 2, \ldots, repeat the following operations while the target qubit does not exceed nn:

  • Apply a controlled XX gate with the 11st qubit as the control qubit and the 2i+12i + 1-th qubit as the target qubit.
  • Apply a controlled XX gate with the 22nd qubit as the control qubit and the 2i+22i + 2-th qubit as the target qubit.

For example, when n=7n = 7, the following quantum circuit can be constructed.

With the above operations, the depth of the quantum circuit becomes ⌊n/2⌋+3\lfloor n/2 \rfloor + 3 or less, which satisfies the given constraint.

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
 
 
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
 
    qc.h(0)
    qc.cx(0, 1)
 
    for i in range(2, n - 1, 2):
        qc.cx(0, i)
        qc.cx(1, i + 1)
 
    if n % 2 != 0:
        qc.cx(0, n - 1)
 
    qc.z(0)
 
    return qc