B2: Phase Shift Oracle

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given integers n, Ln,\ L, and a real number θ\theta. Implement the oracle OO on a quantum circuit qc\mathrm{qc} with nn qubits acting on computational basis states as

ynO{eiθyny=LeiθynyL\begin{equation} \ket{y}_n \xrightarrow{O} \begin{cases} e^{i\theta} \ket{y}_n & y = L \\ \phantom{e^{i\theta}} \ket{y}_n & y \neq L \end{cases} \nonumber \end{equation}

for any integer yy such that 0y<2n0 \leq y < 2^n.

Constraints

  • 1n101 \leq n \leq 10
  • 0L<2n0 \leq L < 2^n
  • 0θ<2π0 \leq \theta < 2\pi
  • Integers must be encoded by little-endian notation, i.e., 100=1001\ket{100} = 1 \neq \ket{001}.
  • Global phase is ignored in judge.
  • The submitted code must follow the specified format:
from qiskit import QuantumCircuit
 
 
def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=2, L=1, θ=π/2n = 2,\ L = 1,\ \theta = \pi/2: Implemented circuit qc\mathrm{qc} should perform the following transformation.
14(00+10+01+11)qc14(00+i10+01+11)\frac{1}{\sqrt{4}} (\ket{00} + \ket{10} + \ket{01} + \ket{11}) \xrightarrow{\mathrm{qc}} \frac{1}{\sqrt{4}} (\ket{00} + i\ket{10} + \ket{01} + \ket{11})

Please sign in to submit your answer.