Gates and Circuits
Single-qubit gates as matrices
X, Z, H: unitary rotations of the Bloch vector
A classical gate is a lookup table: feed it bits, read bits back. A quantum gate cannot be a table, because a qubit is not a bit, it is a unit vector. So a gate has to be the one thing that moves a unit vector without ever stretching it off the unit circle: a rotation. This lesson turns five named gates into five small matrices, and shows you they are all just turns of the same arrow.
The one rule a gate must obey
Before any matrices, one probe. In the reversible-gates lesson we saw that a gate that throws information away has no place in a quantum circuit. Keep that in mind here.
You want a one-qubit gate that sends both |0> and |1> to |0>. Can it exist as a quantum gate?
That constraint has a precise name. A one-qubit gate is a matrix that is , meaning . Read that condition twice, because it is the whole story:
The first consequence, , says every gate can be run backward just by taking its conjugate-transpose, so quantum circuits are always reversible. The second says lengths never change, so a state that started with still sums to one after the gate. Probabilities stay probabilities. A matrix that keeps every length is exactly a rotation (possibly with a reflection), which is why every gate you meet is a turn of the Bloch arrow.[2]
Play the gates before you read them
Below, the qubit starts at , the north pole. Click a gate and watch the arrow sweep; the panel shows the gate as a matrix and keeps the running product of your whole chain. Try the two preset chains, then read on to see why they land where they do.[1]
- theta
- 0 deg
- phi
- 0 deg
- alpha
- 1
- beta
- 0
- P(0)
- 1
- P(1)
- 0
Drag the ball to steer the state, or focus it and use the arrow keys (hold shift for finer steps).
Composed matrix = I (identity)
Each gate is one 2x2 matrix multiply on the state vector.
Five gates, five matrices
Here are the workhorses. Each acts on the state vector by ordinary matrix multiplication.
is the bit flip: it swaps the two amplitudes, so and . It is the quantum NOT. is the phase flip: it leaves alone and multiplies by . It touches no probability at all (both amplitudes keep their magnitude) yet it is far from nothing, as the next lesson on phase will make loud. and are gentler cousins of : they rotate the phase of by a quarter and an eighth of a turn instead of a half.
The star is the gate . Multiply it against :
One matrix multiply turns a definite into the equal superposition , the state that is half zero and half one. That is building superposition out of a plain bit. Feed it instead and you get , the same split but with a minus sign hiding in it.
Chaining gates is just multiplying matrices
Applying gate then gate is the single matrix (the second gate sits on the left, the way matrix multiplication composes linear transformations). Two facts fall straight out of this, and the lab drew both.
First, is its own undo. Multiply it by itself:
So a Hadamard followed by a Hadamard is the identity: it does nothing. The superposition creates, a second uncreates. This is derived, not asserted, and it is the whole reason interference can work: you can spread a state out, let phases do something, then fold it back.
Second, and more surprising, a phase flip sandwiched between two Hadamards is a bit flip:
Nothing in ever mentions swapping bits, yet the product is exactly . A flip in one basis is a flip in another once you rotate into it and back. In the lab, chaining H, Z, H walked the arrow from out to the equator and down to , which is precisely where a single sends it. Same destination, different route.
import numpy as np
H = (1/np.sqrt(2)) * np.array([[1, 1], [1, -1]])
Z = np.array([[1, 0], [0, -1]])
X = np.array([[0, 1], [1, 0]])
np.allclose(H @ H, np.eye(2)) # True -> H is its own inverse
np.allclose(H @ Z @ H, X) # True -> HZH is a bit flip
# In Qiskit you would just write the gates onto a wire:
# qc.h(0); qc.z(0); qc.h(0) is the same unitary as qc.x(0)Lock it in
- A one-qubit gate is a 2x2 unitary matrix (U-dagger U = I); unitarity makes it reversible and length-preserving, so probabilities stay probabilities.
- X flips the bit, Z flips the phase of |1>, and H turns a definite bit into an equal superposition (H|0> = |+>) and back.
- Chaining gates is multiplying their matrices, with the later gate on the left.
- HH = I (Hadamard undoes itself) and HZH = X (a phase flip between two Hadamards is a bit flip) both fall straight out of that product.
Recall: what does unitarity guarantee about a gate, and what is H|0>?
The one constraint plus the one calculation you will reuse constantly. Try to state it, then check.
Reading the H matrix, what is H|0>?
A proposed one-qubit operation is a valid gate exactly when its matrix is:
Match each gate to what it does.
Bit flip: swaps |0> and |1>.
Phase flip: multiplies |1> by -1, leaves |0>.
Makes and unmakes an equal superposition.
The gate condition: reversible and norm-preserving.
Where this goes next
Primary source
IBM Quantum Learning, Basics of quantum informationThe single- and multi-qubit gate chapters build every gate as a matrix and let you run them on a real backend. The clearest hands-on path from these matrices to circuits you can actually execute.
Sources