Editorial
For general n, you can solve this problem by appropriately transforming the expressions.
By expressing ∣a⟩ as ∣a0⟩∣a1⟩...∣an−1⟩ where ai∈{0,1}, the following transformation holds:
QFT(k′)=2n10≤a<2n∑ωak′∣a⟩=2n10≤a<2n∑ωa(k+kconst)∣a⟩=2n10≤a<2n∑ω(a0+2a1+...+2n−1)kconstωak∣a0⟩∣a1⟩...∣an−1⟩=2n10≤a<2n∑ωkconsta0ω(2kconst)a1...ω(2n−1kconst)an−1ωak∣a0⟩∣a1⟩...∣an−1⟩=2n10≤a<2n∑ωakωkconsta0∣a0⟩ω(2kconst)a1∣a1⟩... ω(2n−1kconst)an−1∣an−1⟩=2n10≤a<2n∑ωakP(2n2πkconst)∣a0⟩P(2n2π2kconst)∣a1⟩... P(2n2π2n−1kconst)∣an−1⟩=P(2n2πkconst)⊗P(2n2π2kconst)⊗...⊗P(2n2π2n−1kconst)2n10≤a<2n∑ωak∣a⟩=P(2n2πkconst)⊗P(2n2π2kconst)⊗...⊗P(2n2π2n−1kconst)QFT(k).
Therefore, by applying the phase shift gate P(θi) with rotation angle
θi=2n2π⋅2i⋅kconst
to the i-th qubit, we can obtain the desired quantum state.
The circuit diagram for n=4 is as follows.
The circuit depth is 1.
Sample Code
Below is a sample program:
import math
from qiskit import QuantumCircuit
def solve(n: int, k_const: int) -> QuantumCircuit:
qc = QuantumCircuit(n)
for i in range(n):
theta = (2 * math.pi / 2 ** n) * (2 ** i) * k_const
qc.p(theta, i)
return qc