Lesson 6 of 15
Controlled-Phase Gate
The Controlled-Phase Gate
The controlled-phase gate is fundamental to the Quantum Fourier Transform. It applies a phase to the component only, leaving all other basis states unchanged:
The state vector for a 2-qubit system is represented as a 4-element list ordered by basis state:
So the list [c00, c01, c10, c11] maps index 0 → , index 1 → , index 2 → , index 3 → .
Special Cases
- : phase (a gate on the target, conditioned on control)
- : phase (the gate, conditioned)
- : phase (the gate, conditioned)
import cmath, math
def cphase(k, state):
phase = cmath.exp(2j * math.pi / (2**k))
result = list(state)
result[3] = state[3] * phase
return result
# k=1 applies e^(iπ) = -1 to |11⟩ amplitude
result = cphase(1, [0, 0, 0, 1.0])
print(round(abs(result[3]), 4)) # 1.0
print(round(result[3].real, 4)) # -1.0
Why CR_k Matters
In the QFT circuit, gates with increasing build up finer phase increments. The -th gate contributes a phase of radians, so larger values give smaller phase kicks — encoding higher-frequency information into the transform.
Your Task
Implement cphase(k, state) where:
kis a positive integer (the phase order)stateis a 4-element list representing amplitudes
The function returns a new list with the amplitude multiplied by .
Python runtime loading...
Loading...
Click "Run" to execute your code.