Skip to main content

Rotation Gates

Rotation gates are parameterized single-qubit gates that perform rotations around the X, Y, or Z axes of the Bloch sphere by an angle θ. These gates are fundamental for variational quantum algorithms and quantum control.

RX Gate (X-Rotation)

The RX gate performs a rotation around the X-axis of the Bloch sphere by angle θ.

Mathematical Definition

Rx(θ) = exp(-i × θ/2 × X)
      = cos(θ/2)×I - i×sin(θ/2)×X

Matrix Representation

Rx(θ) = [[cos(θ/2),  -i×sin(θ/2)],
         [-i×sin(θ/2),  cos(θ/2)]]

Implementation

From quantum_computer.py:947-961:
class RxGate(IQuantumGate):
    """Rx(theta) = exp(-i*theta/2 * X)."""
    
    def apply(self, state, backend, targets, params):
        theta = (params or {}).get("theta", 0.0)
        c, s = math.cos(theta / 2.0), math.sin(theta / 2.0)
        u = torch.tensor([[c, -1j * s], [-1j * s, c]], dtype=torch.complex64)
        for t in targets:
            state = _single_qubit_unitary(state, t, u, backend)
        return state

Usage Example

from quantum_computer import QuantumCircuit, QuantumComputer
import math

circuit = QuantumCircuit(n_qubits=1)
circuit.rx(0, theta=math.pi/2)  # 90-degree rotation around X-axis

qc = QuantumComputer()
result = qc.run(circuit)
# Result: |0⟩ → (|0⟩ - i|1⟩)/√2

Special Cases

  • Rx(0) = I (identity)
  • Rx(π) = -iX (equivalent to Pauli-X up to global phase)
  • Rx(π/2) = (I - iX)/√2 (quarter rotation)

RY Gate (Y-Rotation)

The RY gate performs a rotation around the Y-axis of the Bloch sphere by angle θ.

Mathematical Definition

Ry(θ) = exp(-i × θ/2 × Y)
      = cos(θ/2)×I - i×sin(θ/2)×Y

Matrix Representation

Ry(θ) = [[cos(θ/2),  -sin(θ/2)],
         [sin(θ/2),   cos(θ/2)]]
Note: RY is the only rotation gate with a real-valued matrix (no imaginary components).

Implementation

From quantum_computer.py:963-977:
class RyGate(IQuantumGate):
    """Ry(theta) = exp(-i*theta/2 * Y)."""
    
    def apply(self, state, backend, targets, params):
        theta = (params or {}).get("theta", 0.0)
        c, s = math.cos(theta / 2.0), math.sin(theta / 2.0)
        u = torch.tensor([[c, -s], [s, c]], dtype=torch.complex64)
        for t in targets:
            state = _single_qubit_unitary(state, t, u, backend)
        return state

Usage Example

circuit = QuantumCircuit(n_qubits=1)
circuit.ry(0, theta=math.pi/4)  # 45-degree rotation around Y-axis

result = qc.run(circuit)
# Smoothly interpolates between |0⟩ and |1⟩

Special Cases

  • Ry(0) = I (identity)
  • Ry(π) = -iY (equivalent to Pauli-Y up to global phase)
  • Ry(π/2) = (|0⟩ + |1⟩)/√2 (creates equal superposition, similar to Hadamard)

RZ Gate (Z-Rotation)

The RZ gate performs a rotation around the Z-axis of the Bloch sphere by angle θ, applying a phase shift.

Mathematical Definition

Rz(θ) = exp(-i × θ/2 × Z)
      = [[e^(-iθ/2),     0    ],
         [    0,      e^(+iθ/2)]]

Matrix Representation

Rz(θ) = [[cos(θ/2) - i×sin(θ/2),           0          ],
         [          0,            cos(θ/2) + i×sin(θ/2)]]

      = [[e^(-iθ/2),     0    ],
         [    0,      e^(+iθ/2)]]

Implementation

From quantum_computer.py:979-994:
class RzGate(IQuantumGate):
    """Rz(theta) = exp(-i*theta/2 * Z)."""
    
    def apply(self, state, backend, targets, params):
        theta = (params or {}).get("theta", 0.0)
        e_neg = complex(math.cos(theta / 2.0), -math.sin(theta / 2.0))
        e_pos = complex(math.cos(theta / 2.0), math.sin(theta / 2.0))
        u = torch.tensor([[e_neg, 0], [0, e_pos]], dtype=torch.complex64)
        for t in targets:
            state = _single_qubit_unitary(state, t, u, backend)
        return state

Usage Example

circuit = QuantumCircuit(n_qubits=1)
circuit.h(0)  # Create superposition
circuit.rz(0, theta=math.pi/2)  # Apply phase rotation

result = qc.run(circuit)
# Adjusts relative phase between |0⟩ and |1⟩ components

Special Cases

  • Rz(0) = I (identity)
  • Rz(π) = -iZ (equivalent to Pauli-Z up to global phase)
  • Rz(π/2) = S gate (phase gate)
  • Rz(π/4) = T gate

Parameter Passing

Rotation gates require the theta parameter to be passed via the params dictionary:
# Direct circuit builder API (recommended)
circuit.rx(qubit=0, theta=1.5708)  # π/2 radians
circuit.ry(qubit=1, theta=math.pi/4)
circuit.rz(qubit=2, theta=3.14159)

# Manual instruction construction
from quantum_computer import CircuitInstruction
instruction = CircuitInstruction(
    gate_name="Rx",
    targets=[0],
    params={"theta": math.pi/2}
)

Parameterized Circuit Example

Rotation gates are essential for variational quantum algorithms:
import numpy as np

def create_variational_circuit(params):
    """Create a parameterized quantum circuit.
    
    Args:
        params: List of rotation angles [θ0, θ1, θ2, ...]
    """
    circuit = QuantumCircuit(n_qubits=2)
    
    # Layer 1: Y rotations
    circuit.ry(0, theta=params[0])
    circuit.ry(1, theta=params[1])
    
    # Entangling layer
    circuit.cnot(0, 1)
    
    # Layer 2: X and Z rotations
    circuit.rx(0, theta=params[2])
    circuit.rz(1, theta=params[3])
    
    return circuit

# Run with specific parameters
theta_values = [np.pi/4, np.pi/3, np.pi/6, np.pi/2]
circuit = create_variational_circuit(theta_values)

qc = QuantumComputer()
result = qc.run(circuit, backend="schrodinger")
print(result)

Relationship to Pauli Gates

Rotation gates generalize the Pauli gates:
# Pauli-X as a rotation
circuit.rx(0, theta=math.pi)  # Equivalent to X gate (up to global phase)

# Pauli-Y as a rotation  
circuit.ry(0, theta=math.pi)  # Equivalent to Y gate

# Pauli-Z as a rotation
circuit.rz(0, theta=math.pi)  # Equivalent to Z gate

Bloch Sphere Interpretation

Each rotation gate moves a qubit state on the Bloch sphere:
  • RX(θ): Rotates around the X-axis (left-right)
  • RY(θ): Rotates around the Y-axis (front-back)
  • RZ(θ): Rotates around the Z-axis (vertical)

Example: Creating an arbitrary state

# Prepare state on Bloch sphere at (θ, φ)
# |ψ⟩ = cos(θ/2)|0⟩ + e^(iφ)sin(θ/2)|1⟩

def prepare_bloch_state(qubit, theta, phi):
    circuit = QuantumCircuit(n_qubits=qubit+1)
    circuit.ry(qubit, theta=theta)
    circuit.rz(qubit, theta=phi)
    return circuit

# Prepare state at θ=π/3, φ=π/4
circuit = prepare_bloch_state(0, theta=math.pi/3, phi=math.pi/4)
result = qc.run(circuit)

# Check Bloch vector
bx, by, bz = result.bloch_vectors[0]
print(f"Bloch vector: ({bx:.3f}, {by:.3f}, {bz:.3f})")

Gate Registry

Rotation gates are registered in _GATE_REGISTRY (quantum_computer.py:1157-1174):
_GATE_REGISTRY: Dict[str, IQuantumGate] = {
    "Rx":     RxGate(),
    "Ry":     RyGate(),
    "Rz":     RzGate(),
    # ... other gates
}

Technical Notes

Angle Convention

All rotation gates use the half-angle convention:
  • Matrix elements use θ/2, not θ
  • This matches the standard quantum computing convention
  • A rotation of θ = 2π returns to the original state

Continuous Parameters

Unlike discrete gates (H, X, Y, Z), rotation gates accept continuous angle parameters:
# Sweep through rotation angles
for angle in np.linspace(0, 2*np.pi, 20):
    circuit = QuantumCircuit(1)
    circuit.ry(0, theta=angle)
    result = qc.run(circuit)
    p1 = result.marginal_p1[0]
    print(f"θ={angle:.2f}, P(|1⟩)={p1:.3f}")

Default Parameter Value

If theta is not provided in params, it defaults to 0.0 (identity operation):
theta = (params or {}).get("theta", 0.0)

See Also

Build docs developers (and LLMs) love