Editorial
In this problem, you will implement an oracle O that performs the state transition expressed as
∣x⟩nOexp(2m2πif(x))∣x⟩n.
Here, the resulting state after the transition can be decomposed independently for each qubit as follows:
exp(2m2πif(x))∣x⟩n=exp(2m2πi(S0x0+⋯+Sn−1xn−1))∣x0⋯xn−1⟩=exp(2m2πiS0x0)∣x0⟩⊗exp(2m2πiS1x1)∣x1⟩⊗⋯⊗exp(2m2πiSn−1xn−1)∣xn−1⟩
Thus, by applying a phase shift gate with a phase of θ=2πSi/2m to each qubit xi, you can solve this problem.
The circuit diagram for the case where n=3 is shown as follows.
The circuit depth is 1.
Sample Code
Below is a sample program:
import math
from qiskit import QuantumCircuit
def solve(n: int, m: int, S: list[int]) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range(n):
theta = 2 * math.pi * S[i] / 2**m
qc.p(theta, i)
return qc