Lesson 2 of 15
Rotation Gates Rx, Ry, Rz
Rotation Gates
The rotation gates , , and rotate the qubit state around the X, Y, and Z axes of the Bloch sphere by an angle .
Rx Gate
Applied to :
Ry Gate
Applied to :
Rz Gate
Applied to :
Special Cases
At , these gates recover familiar Pauli gates (up to global phase):
- (bit flip with imaginary phase)
- (bit flip, real entries)
- (phase flip, no amplitude change)
Note that only changes phases, never measurement probabilities.
Implementation
import cmath, math
def rx(theta, state):
c = math.cos(theta / 2)
s = math.sin(theta / 2)
return [
c * complex(state[0]) + (-1j * s) * complex(state[1]),
(-1j * s) * complex(state[0]) + c * complex(state[1])
]
def ry(theta, state):
c = math.cos(theta / 2)
s = math.sin(theta / 2)
return [
c * complex(state[0]) + (-s) * complex(state[1]),
s * complex(state[0]) + c * complex(state[1])
]
def rz(theta, state):
return [
cmath.exp(-1j * theta / 2) * complex(state[0]),
cmath.exp(1j * theta / 2) * complex(state[1])
]
Your Task
Implement rx(theta, state), ry(theta, state), and rz(theta, state).
Python runtime loading...
Loading...
Click "Run" to execute your code.