Table of Contents

Quantum Gates

Quantum gates are unitary operations that transform qubit states. Like classical logic gates (AND, OR, NOT), quantum gates manipulate qubits—but they preserve superposition and enable entanglement. Every quantum gate is reversible (unitary).

Single-qubit gates act on one qubit; two-qubit gates entangle or correlate pairs; multi-qubit gates generalize further. Qiskit provides dozens of built-in gates, and you can define custom unitary gates.

Common Single-Qubit Gates

from qiskit import QuantumCircuit
 
qc = QuantumCircuit(1)
qc.h(0)         # Hadamard
qc.rx(0.5, 0)   # Rotation around x-axis by 0.5 rad
qc.ry(1.0, 0)   # Rotation around y-axis by 1.0 rad
print(qc.draw())

Common Two-Qubit Gates

Two-qubit gates are expensive on real hardware: they're slow and error-prone. Transpilers reduce two-qubit gate count to minimize errors.

Custom Gates

Define unitary gates from a matrix or decompose them into basic gates:

from qiskit import QuantumCircuit
import numpy as np
 
# Define a custom unitary (e.g., a 2x2 matrix)
U = np.array([[1, 0], [0, 1j]])  # Phase gate
qc = QuantumCircuit(1)
qc.unitary(U, [0], label='custom')