qiskit-quantum-gates
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
- Pauli gates: X (NOT), Y, Z; they flip or phase-flip qubits
- Hadamard (H): creates equal superposition from $\lvert 0 \rangle$ to $\frac{1}{\sqrt{2}}(\lvert 0 \rangle + \lvert 1 \rangle)$
- Phase gates: S ($\pi/2$ phase), T ($\pi/4$ phase)
- Rotation gates: RX($\theta$), RY($\theta$), RZ($\theta$); rotate around x, y, z axes by angle $\theta$
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
- CNOT (CX): control-NOT; flips target qubit if control is $\lvert 1 \rangle$. Creates entanglement.
- CZ: control-Z; applies Z to target if control is $\lvert 1 \rangle$
- SWAP: swaps two qubits
- iSWAP: SWAP with an additional $i$ phase
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')
qiskit-quantum-gates.md · Last modified: by 127.0.0.1
