C2: Generate Uniform Amplitude Superposition State II

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 600

Problem Statement

You are given integers nn and LL. Implement the operation of preparing the state ψ\ket{\psi} on a quantum circuit qc\mathrm{qc} with nn qubits such that the states 0, 1, ... L1\ket{0},\ \ket{1},\ ...\ \ket{L-1} are observed with equal probabilities, and the sum of these probabilities equals 11.

The error in the sum of probabilities can be up to 5.0×1035.0 \times 10^{-3}.

More Precise Problem Statement

Define the state ψ\ket{\psi} prepared by qc\mathrm{qc} as

ψ=i=02n1aii,\begin{equation} \ket{\psi} = \sum_{i=0}^{2^n-1} a_i\ket{i}, \nonumber \end{equation}

where aia_i denotes the probability amplitude of the computational basis state i\ket{i}.

Implement qc\mathrm{qc} satisfying following conditions:

  • a0=a1==aL1|a_0| = |a_1| = \cdots = |a_{L-1}|
  • i=0L1ai2>15.0×103\sum_{i=0}^{L-1} |a_i|^2 > 1 - 5.0 \times 10^{-3}

Constraints

  • 1n101 \leq n \leq 10
  • 1L2n1 \leq L \leq 2^n
  • The circuit depth must not exceed 10001000.
  • Integers must be encoded by little-endian notation, i.e., 100=1001\ket{100} = 1 \neq \ket{001}.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=3, L=3n = 3,\ L=3: Implemented circuit qc\mathrm{qc} should perform the following transformation.
000qc13(000+100+010)\ket{000} \xrightarrow{\mathrm{qc}} \frac{1}{\sqrt{3}} (\ket{000} + \ket{100} + \ket{010})

Hints

Open
  • You can solve the problem using the solution from problem B4.
  • You can define additional functions other than the solve function.

Please sign in to submit your answer.