Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 39 ยท Gates and Circuits

Single-Qubit Gates

Meet the essential single-qubit gates X, Y, Z, Hadamard, S and T. See their matrices, what they do to states and the Bloch sphere, and the identities that connect them.

A quantum gate is a unitary matrix applied to qubits. Single-qubit gates are 2 by 2 matrices, and a small family of them does most of the work in practice. In this lesson you will learn each one, what it does geometrically, and the identities that let you simplify circuits by hand. You can run every matrix in NumPy and check the claims yourself.

All of these are unitary, and all except S and T (and their daggers) are Hermitian.

Gate Matrix Effect on the Bloch sphere
I [[1, 0], [0, 1]] Nothing
X [[0, 1], [1, 0]] Half turn about x (quantum NOT)
Y [[0, -i], [i, 0]] Half turn about y
Z [[1, 0], [0, -1]] Half turn about z (phase flip)
H [[1, 1], [1, -1]] / sqrt(2) Half turn about the x+z diagonal
S [[1, 0], [0, i]] Quarter turn about z
T [[1, 0], [0, e^(i*pi/4)]] Eighth turn about z

X, Y and Z are the Pauli gates (named after Wolfgang Pauli). H is the Hadamard gate (Jacques Hadamard). S is also written sqrt(Z) and T is sqrt(S), the fourth root of Z.

The Pauli gates

X swaps the amplitudes: a|0> + b|1> becomes b|0> + a|1>. On basis states it is the classical NOT, but it also acts on superpositions. |+> is left unchanged (it is an eigenvector), while |-> picks up a minus sign.

Z leaves |0> alone and multiplies the |1> amplitude by -1. It flips the phase: |+> becomes |-> and vice versa. It does nothing to measurement results in the 0/1 basis, but it changes everything in the X basis.

Y is a combination of both: Y = i X Z. It takes |0> to i|1> and |1> to -i|0>.

Python The gate gallery acting on basis states

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The Hadamard gate

H is the workhorse that creates superpositions. It maps |0> to |+> and |1> to |->, and, because H is its own inverse, also maps |+> to |0> and |-> to |1>. In other words H switches between the Z basis and the X basis, which is why it appears at the start of nearly every algorithm (to spread weight across all inputs) and again at the end (to convert phase information into a bit you can measure).

On n qubits, applying H to each in turn takes the all-zero state to a uniform superposition of all 2^n bit strings. You will do that explicitly in the simulator lesson.

The phase gates S and T

S and T change only the phase of the |1> amplitude: S by 90 degrees and T by 45 degrees. They do not change measurement outcomes in the 0/1 basis, but they move states around the equator of the Bloch sphere. Together with H and a two-qubit gate they form the standard set of gates for fault-tolerant machines (see Universal Gate Sets and Circuit Identities). The T gate is notable because it is the expensive one in error-corrected computing.

Useful relations: S*S = Z, T*T = S, and T repeated eight times is the identity.

Python Phase gates: S, S-dagger and T powers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Four applications of S to |+> walk once around the equator and return to |+>.

Identities worth knowing

Gates satisfy a small set of algebraic relationships that let you simplify circuits without simulating them:

  • Self-inverse: X X = Y Y = Z Z = H H = I.
  • Pauli product: X Y = i Z, Y Z = i X, Z X = i Y (and reversed order gives a minus sign: they anticommute).
  • Basis change: H X H = Z and H Z H = X. Sandwiching a gate between Hadamards swaps the roles of the x and z axes.
  • Phase gate family: Z = S^2 = T^4.
  • Global phases drop out: Y = i X Z, and the i can be ignored if the gate is not controlled.
Python Verifying circuit identities numerically

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Using gates: a mini circuit by hand

Circuits are read left to right, matrices multiply right to left. For the circuit "H, then Z, then H" the matrix is H Z H, which equals X. So the circuit flips |0> to |1> even though it contains no X gate, a tiny demonstration of interference: H spreads, Z marks the |1> branch with a minus sign, and the second H makes the branches interfere into a definite outcome.

flowchart LR
    A["|0>"] --> B["H"] --> C["Z"] --> D["H"] --> E["|1>"]

The circuit H, Z, H acts as X.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the Z gate do to the state |+>?

    Z multiplies the |1> amplitude by -1, so (|0> + |1>)/sqrt(2) becomes (|0> - |1>)/sqrt(2).
  2. 2. Which identity is correct?

    Conjugating by H swaps the x and z axes, so HXH = Z.
  3. 3. What is S applied twice?

    S is a quarter turn about z, so two applications give a half turn: Z.
  4. 4. A circuit applies H, then Z, then H to |0>. What is measured?

    HZH = X, so |0> becomes |1>.

Summary

  • Single-qubit gates are 2 by 2 unitary matrices; each is a rotation of the Bloch sphere.
  • X flips bits, Z flips phase, Y does both, H switches between Z and X bases.
  • S and T add 90 and 45 degree phases; T^2 = S, S^2 = Z.
  • Pauli gates anticommute, and H X H = Z.
  • Identities let you simplify circuits without simulating them.

Next: Rotation Gates and Phase