This quantum gates reference translates the most common circuit operations into three views: what the gate does to a qubit, how it is represented mathematically, and how to write it in Qiskit, Cirq, and PennyLane. Use it while reading quantum algorithms, translating circuits between frameworks, or checking whether a gate is changing a qubit's value, phase, or entanglement structure.
Overview
A quantum gate is a reversible operation represented by a unitary matrix. Unlike a classical assignment such as x = 1, a gate does not generally select one output value. It transforms a state vector and preserves the total probability of all possible measurement outcomes.
Unless stated otherwise, the examples below use the computational basis |0⟩ and |1⟩, with matrices written in the order (|0⟩, |1⟩). A single-qubit state can be written as |ψ⟩ = α|0⟩ + β|1⟩, where the probabilities of measuring zero or one are |α|² and |β|². Gates change the amplitudes, including their complex phases.
Bloch-sphere descriptions are useful shorthand. The X, Y, and Z gates rotate a qubit by 180 degrees around the x, y, and z axes respectively. The H gate creates or removes a particular kind of superposition. Phase gates rotate around the z axis. This geometric view complements, rather than replaces, matrix multiplication.
Framework syntax changes more often than the underlying mathematics. Treat the code below as a compact reference and verify imports and method names against the SDK version used by your project. The matrix and circuit behavior are the stable part of the explanation.
What to track
Core single-qubit gates
| Gate | Matrix | Effect | Inverse |
|---|---|---|---|
| X | [[0, 1], [1, 0]] | Bit flip: maps |0⟩ to |1⟩ and |1⟩ to |0⟩. A 180° rotation around x. | X |
| Y | [[0, -i], [i, 0]] | Bit and phase flip. It maps |0⟩ to i|1⟩ and |1⟩ to -i|0⟩. | Y |
| Z | [[1, 0], [0, -1]] | Leaves |0⟩ unchanged and adds a minus phase to |1⟩. A 180° z rotation. | Z |
| H | 1/√2 [[1, 1], [1, -1]] | Maps a basis state to a balanced superposition with a relative phase. It exchanges the computational and Hadamard bases. | H |
| S | [[1, 0], [0, i]] | Applies a 90° phase rotation around z. | S† = [[1, 0], [0, -i]] |
| T | [[1, 0], [0, e^(iπ/4)]] | Applies a 45° phase rotation around z. | T† = [[1, 0], [0, e^(-iπ/4)]] |
The distinction between a bit flip and a phase change is essential. Z has no visible effect when applied to |0⟩ or |1⟩ and measured immediately in the computational basis, but it changes interference when the qubit is in a superposition. This is why phase gates appear frequently between H gates in quantum circuit examples.
Parameterized rotation gates
Rotation gates accept an angle, usually in radians. The common definitions are:
Rx(θ) = [[cos(θ/2), -i sin(θ/2)], [-i sin(θ/2), cos(θ/2)]]Ry(θ) = [[cos(θ/2), -sin(θ/2)], [sin(θ/2), cos(θ/2)]]Rz(θ) = [[e^(-iθ/2), 0], [0, e^(iθ/2)]]
The angle convention matters: a parameter of π represents a half-turn in these definitions. Rotation gates are useful for variational circuits because a classical optimizer can tune their parameters. Their inverses are obtained by negating the angle: Rx(-θ), Ry(-θ), and Rz(-θ).
Controlled and multi-qubit gates
| Gate | Behavior | Typical use |
|---|---|---|
| CX or CNOT | Applies X to the target only when the control is |1⟩. | Conditional logic and creating computational-basis entanglement. |
| CY, CZ | Applies Y or Z to the target when the control is |1⟩. CZ is symmetric in its qubit roles. | Phase relationships and algorithm-specific interactions. |
| Controlled-U | Applies an arbitrary one-qubit unitary U conditionally. In block form, it is [[I, 0], [0, U]], subject to the chosen basis and qubit ordering. | Decomposing algorithms and expressing conditional subroutines. |
| SWAP | Exchanges the states of two qubits. | Moving logical qubits when hardware connectivity or layout requires it. |
| Toffoli or CCX | Applies X when two control qubits are both |1⟩. | Reversible classical logic and oracle construction. |
A controlled gate does not mean that the control qubit is measured. It means the operation is applied to the target component of the joint state when the control component has the required value. If the control is in superposition, the operation can produce entanglement.
SDK syntax reference
The following snippets show representative operation names. Qubit indexing and circuit construction conventions differ between frameworks, so keep the logical control-target order explicit in tests.
# Qiskit
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.rz(theta, 1)
qc.swap(0, 1)
# Cirq
import cirq
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
cirq.H(q0),
cirq.CNOT(q0, q1),
cirq.rz(theta)(q1),
cirq.SWAP(q0, q1),
)
# PennyLane
import pennylane as qml
def circuit(theta):
qml.Hadamard(wires=0)
qml.CNOT(wires=[0, 1])
qml.RZ(theta, wires=1)
qml.SWAP(wires=[0, 1])
For custom gate definitions, compare the framework's matrix convention before composing operations. A reversed wire order can make a mathematically correct circuit appear incorrect when translated between Qiskit, Cirq, and PennyLane.
Short quantum circuit examples
Superposition: Apply H to |0⟩ to obtain (|0⟩ + |1⟩)/√2. Measuring immediately should produce two possible outcomes according to the equal probabilities of this state.
Phase change: Apply H, then Z, then H. The sequence is equivalent to X, because the basis change exposes the phase difference as a bit change. This is a useful unit test for understanding interference.
Entanglement: Start with two qubits in |00⟩, apply H to qubit 0, then CNOT with qubit 0 as control and qubit 1 as target. The resulting Bell state is (|00⟩ + |11⟩)/√2.
Conditional logic: Use CNOT when a target should flip conditionally. Use CZ when the desired effect is a conditional phase. If more than one condition is required, consider a Toffoli gate or a decomposition supported by the target backend.
Cadence and checkpoints
For a gate reference, the recurring variables are not experimental measurements; they are the implementation details that can drift across software projects. Review this page quarterly if it supports active development, and review it before starting a framework migration or translating an algorithm to another backend.
- API checkpoint: Confirm gate method names, import paths, parameter order, and whether angles are expected in radians.
- Semantic checkpoint: Run small matrix or statevector tests for X, H, controlled gates, and at least one parameterized rotation.
- Compilation checkpoint: Inspect the transpiled or decomposed circuit. A high-level gate may be rewritten into the native operations supported by a device.
- Documentation checkpoint: Record the SDK version and link to the relevant official API reference in project notes.
These checks are particularly useful when following a Qiskit tutorial, Cirq tutorial, or PennyLane tutorial written for a different release. The mathematics should remain comparable even when the construction API changes.
How to interpret changes
When a circuit's output changes after a gate or SDK update, separate four possible causes: a different gate definition, a changed qubit ordering, a different decomposition, or ordinary sampling variation. First test the circuit with an exact simulator or statevector where appropriate. Then inspect amplitudes before measurement, and finally compare sampled counts.
Check global phase carefully. Two statevectors that differ only by one overall complex factor represent the same physical state, while a relative phase between basis components can change later measurement results. Also distinguish logical behavior from hardware behavior: noise, readout errors, and connectivity constraints may alter results even when the ideal circuit is unchanged.
For controlled operations, write down the control and target explicitly and test basis states such as |00⟩, |01⟩, |10⟩, and |11⟩. This catches reversed-wire bugs faster than inspecting a large algorithm. For rotation gates, test special angles such as zero, π, and -π to verify sign conventions.
Use circuit depth, two-qubit gate count, and inserted SWAP operations as practical review variables. A mathematically equivalent circuit may be less suitable for a particular backend after transpilation. For a deeper treatment, see Quantum Circuit Transpilation Explained and Quantum Circuit Debugging.
When to revisit
Return to this reference when you encounter an unfamiliar symbol, port a circuit between frameworks, or review a new implementation of an algorithm such as QAOA or a variational eigensolver. Revisit it after a major SDK release, when a backend changes its native gate set, or when a circuit produces unexpected results following transpilation.
A practical review workflow is:
- Write the intended operation in plain language: flip, phase shift, rotation, swap, or conditional operation.
- Verify the matrix and inverse, including the angle convention for parameterized gates.
- Build a two- or three-qubit test circuit using known basis states and one superposition state.
- Implement the test in your chosen SDK, then compare the equivalent syntax in another framework if portability matters.
- Inspect the compiled circuit and document any changes in qubit order, decomposition, depth, or two-qubit operations.
Keep this checklist beside your code rather than relying on memorization. For the broader learning path, pair it with the quantum computing roadmap for software engineers, then consult the Qiskit, Cirq, and PennyLane comparison when choosing a working framework. Gate fluency becomes most useful when it is connected to testing, transpilation, and the algorithmic goal of the circuit.