QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
  1. Docs
  2. All gates, with the math
Learn
  • Quantum basics
  • OpenQASM 3 cheat sheet
  • All gates, with the math
  • Every gate, interactive
  • Entanglement: how CNOT connects qubits
Circuits
  • Dynamic circuits: if/else, loops and conditions
Lessons
  • Learning path: from one qubit to algorithms
  • Quantum machine learning by hand
Run
  • Compile (transpile): levels, basis gates, topology
  • Simulators, noise, T1/T2 and fake backends
  • Python in the Playground
  • GitHub and git in the Playground
  • Articles and sharing
Analyze
  • Metrics: comparing distributions
  • Q-sphere and Bloch spheres
Hardware
  • Real IBM Quantum hardware
  • Device topology and calibration heat maps
  • Benchmark circuits: MQT Bench and QASMBench
Advanced
  • Circuit cutting, in depth
Story
  • The story of quantum computing
  • The Hamiltonian: where gates come from
  • What to expect next
Documentation/Learn/All gates, with the math

All gates, with the math

Every gate in the palette, its matrix, what it does to a state, and when to use it. Matrices act on column vectors (|0⟩ = (1,0)ᵀ, |1⟩ = (0,1)ᵀ).

Single-qubit Clifford gates

IIdentity
id q[0];
I=(10​01​)

Does nothing to the state. On hardware it is a wait of one gate time, during which T1/T2 noise still acts.

When to use: Padding to line up timing, noise experiments (watch the fidelity drop in Debug mode with a fake backend), placeholders in templates.

HHadamard
h q[0];
H=2​1​(11​1−1​)

Maps |0⟩ → (|0⟩+|1⟩)/√2 and |1⟩ → (|0⟩−|1⟩)/√2: creates an equal superposition. Swaps the X and Z axes of the Bloch sphere.

When to use: Start of almost every algorithm; before and after oracles (Deutsch–Jozsa, Grover, Bernstein–Vazirani).

XPauli-X
x q[0];
X=(01​10​)

Bit flip: |0⟩ ↔ |1⟩. A rotation of π about the X axis.

When to use: Prepare |1⟩ inputs, build oracles, the target of CNOT is an X controlled by another qubit.

YPauli-Y
y q[0];
Y=(0i​−i0​)

Bit flip plus phase: |0⟩ → i|1⟩, |1⟩ → −i|0⟩. Rotation of π about Y. Y = iXZ.

When to use: Rare on its own; appears in Pauli observables and error models.

ZPauli-Z
z q[0];
Z=(10​0−1​)

Phase flip: leaves |0⟩, multiplies |1⟩ by −1. Invisible in Z-basis probabilities, visible after an H.

When to use: Marks states in Grover; measurement observables (⟨Z⟩) in cutting and VQE.

SX√X
sx q[0];
X​=21​(1+i1−i​1−i1+i​)

Half of an X: a π/2 rotation about X. Applying it twice gives X.

When to use: Native gate on IBM hardware; every single-qubit gate is compiled into RZ and √X.

Phase gates

SS
s q[0];
S=(10​0i​)=Z​

Adds a phase of π/2 to |1⟩. S·S = Z.

When to use: Changes between the X and Y bases; part of the Clifford group used in error correction.

SdgS†
sdg q[0];
S†=(10​0−i​)

Inverse of S: phase −π/2 on |1⟩.

When to use: Undo an S; measure in the Y basis with S†·H before measuring.

TT
t q[0];
T=(10​0eiπ/4​)=4Z​

Phase π/4 on |1⟩. T·T = S. It is not a Clifford gate, which is what makes universal computation possible.

When to use: Toffoli decompositions, fault-tolerant algorithms (T-count is a cost metric).

TdgT†
tdg q[0];
T†=(10​0e−iπ/4​)

Inverse of T: phase −π/4.

When to use: Appears with T in Toffoli decompositions.

Rotation gates (parameterized)

RXRX(θ)
rx(pi/2) q[0];
RX​(θ)=(cos2θ​−isin2θ​​−isin2θ​cos2θ​​)=e−iθX/2

Rotates the Bloch vector by θ about the X axis. RX(π) = X up to a global phase.

When to use: QAOA mixers, variational ansätze, preparing arbitrary real superpositions.

RYRY(θ)
ry(0.6) q[0];
RY​(θ)=(cos2θ​sin2θ​​−sin2θ​cos2θ​​)

Rotation about Y. Keeps amplitudes real, so RY(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩.

When to use: The workhorse of VQE and W-state preparation; set θ to control the probability of 1 exactly: p(1) = sin²(θ/2).

RZRZ(φ)
rz(pi/4) q[0];
RZ​(φ)=(e−iφ/20​0eiφ/2​)

Rotation about Z: a relative phase e^{iφ} between |0⟩ and |1⟩. Does not change Z-basis probabilities.

When to use: Native and virtually free on IBM hardware (implemented as a frame change, zero duration, no error).

PP(λ)
p(pi/8) q[0];
P(λ)=(10​0eiλ​)

Phase gate: multiplies |1⟩ by e^{iλ}. P(π) = Z, P(π/2) = S, P(π/4) = T. Equal to RZ(λ) up to global phase.

When to use: Controlled versions (CP) build the quantum Fourier transform.

UU(θ,φ,λ)
U(pi/2, 0, pi) q[0];
U(θ,φ,λ)=(cos2θ​eiφsin2θ​​−eiλsin2θ​ei(φ+λ)cos2θ​​)

The most general single-qubit gate: every 1-qubit unitary is a U up to a global phase. H = U(π/2, 0, π), X = U(π, 0, π), RZ(φ) ≈ U(0, 0, φ).

When to use: Variational circuits (VQE, QAOA) where the angles are the parameters you optimise; the OpenQASM 3 built-in gate every other gate is defined from.

Multi-qubit gates

CXCNOT (CX)
cx q[0], q[1];
CX=​1000​0100​0001​0010​​

Flips the target when the control is |1⟩: |c,t⟩ → |c, t⊕c⟩. With H on the control first it creates the Bell state.

When to use: The standard entangling gate. On hardware it costs about 10× more error than a single-qubit gate, so the transpiler counts it.

CZCZ
cz q[0], q[1];
CZ=diag(1,1,1,−1)

Adds a −1 phase only to |11⟩. Symmetric: it does not matter which qubit is the control. CZ = (I⊗H)·CX·(I⊗H).

When to use: Grover's oracle for |11⟩; native two-qubit gate on some IBM Heron processors.

CYCY
cy q[0], q[1];
CY=diag(I,Y)

Applies Y to the target when the control is |1⟩.

When to use: Pauli-controlled operations in error-correction and oracle constructions.

CHCH
ch q[0], q[1];
CH=diag(I,H)

Puts the target in superposition only when the control is |1⟩.

When to use: Building W states and controlled state preparation.

CPControlled-phase CP(λ)
cp(pi/2) q[0], q[1];
CP(λ)=diag(1,1,1,eiλ)

Adds the phase e^{iλ} only to |11⟩. CP(π) = CZ. Symmetric: either qubit can be called the control.

When to use: The rotations R_k of the quantum Fourier transform; phase kickback.

CRXCRX / CRY / CRZ
cry(pi/4) q[0], q[1];
CRX​(θ)=diag(I,RX​(θ))

Controlled rotations: the target rotates by θ about X, Y or Z only when the control is |1⟩.

When to use: Quantum phase estimation (CRZ), amplitude encoding of data (CRY), hardware-efficient ansätze.

CUCU(θ,φ,λ,γ)
cu(pi/2, 0, pi, 0) q[0], q[1];
CU=diag(I,eiγU(θ,φ,λ))

The general controlled single-qubit gate; γ adds a phase to the controlled branch.

When to use: Any controlled unitary in one gate: phase kickback demonstrations, controlled-Rk in the QFT.

SWAPSWAP
swap q[0], q[1];
SWAP=​1000​0010​0100​0001​​

Exchanges two qubit states. Costs three CNOTs, which is why routing on hardware is expensive.

When to use: Inserted by the transpiler when two qubits that must interact are not neighbours on the chip. The Compile tab counts them.

CCXToffoli (CCX)
ccx q[0], q[1], q[2];
CCX∣a,b,t⟩=∣a,b,t⊕ab⟩

Flips the target when both controls are |1⟩: a reversible AND gate. Decomposes into 6 CNOTs and 7 T/T† gates.

When to use: Classical arithmetic (adders), oracles, error correction.

CSWAPFredkin (CSWAP)
cswap q[0], q[1], q[2];
CSWAP∣c,a,b⟩=∣c,b,a⟩ if c=1

Swaps the two targets when the control is |1⟩.

When to use: The SWAP test for comparing two states, reversible classical logic.

Non-unitary operations

MMeasure
c[0] = measure q[0];
p(x)=∣⟨x∣ψ⟩∣2

Projects the qubit onto |0⟩ or |1⟩ and writes the result to a classical bit. Irreversible.

When to use: End of every circuit you want counts from. Simulators add it automatically if you forget.

|0⟩Reset
reset q[0];
ρ↦∣0⟩⟨0∣

Forces the qubit back to |0⟩ regardless of its state (measure, then flip if 1).

When to use: Reusing ancilla qubits mid-circuit.

|Barrier
barrier q;
I

Does nothing to the state. It is a fence for the transpiler: gates are not moved or merged across it.

When to use: Keep a state-preparation block separate from an oracle so the drawing stays readable.

← Previous
OpenQASM 3 cheat sheet
Next →
Every gate, interactive
On this page
  • Single-qubit Clifford gates
  • Phase gates
  • Rotation gates (parameterized)
  • Multi-qubit gates
  • Non-unitary operations
Try it in the IDE →
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in