Introduction to Quantum Computing

Chapter 5
Quantum Gates and Circuit Model

Diploma in Quantum Computing
Introduction to Quantum Computing   •   Diploma

Quantum Gates and Circuit Model

Introduction

Quantum algorithms are expressed as sequences of operations on quantum bits, or qubits. These operations are called quantum gates. A quantum circuit is a graphical and mathematical model that shows how gates act on qubits over time. Understanding gates and circuits is therefore essential for reading quantum algorithms, designing small programs, and interpreting the output of quantum hardware.

A quantum gate must be reversible. In mathematical terms, a gate is represented by a unitary matrix U satisfying

U†U = UU† = I

where U† is the conjugate transpose of U and I is the identity matrix. Unitarity preserves the total probability of a quantum state. Unlike a classical logic gate, a quantum gate generally does not measure or destroy a state; it transforms amplitudes while preserving quantum information.

This chapter develops the most important single-qubit and multi-qubit gates, explains circuit notation, and demonstrates how to construct, simplify, and trace elementary circuits.

Learning Objectives

By the end of this chapter, you should be able to:

  • represent a qubit using computational-basis vectors and amplitudes;
  • explain the action of Pauli, Hadamard, phase, and rotation gates;
  • describe controlled operations and the SWAP gate;
  • translate a circuit diagram into matrix or state-vector operations;
  • construct simple circuits for superposition, phase transformation, and conditional logic;
  • simplify circuits using gate identities and commutation properties;
  • trace measurement probabilities through elementary circuits;
  • identify practical limitations of circuit execution on real quantum devices.

1. Qubits and the Circuit Model

A classical bit is either 0 or 1. A qubit may occupy a superposition of the computational basis states |0⟩ and |1⟩:

|ψ⟩ = α|0⟩ + β|1⟩

Here α and β are generally complex probability amplitudes. A valid normalized state satisfies

|α|² + |β|² = 1

The quantities |α|² and |β|² are the probabilities of obtaining 0 and 1 when the qubit is measured in the computational basis. Measurement produces one classical result and changes the state to the corresponding basis state.

Using column vectors,

|0⟩ = [1, 0]ᵀ, |1⟩ = [0, 1]ᵀ

A circuit is conventionally read from left to right. Horizontal lines represent qubits, boxes represent gates, and measurement symbols indicate conversion of quantum information into classical information. Gates applied in later time steps multiply the state after earlier gates. Thus, if U₁ is applied first and U₂ second, the final state is

|ψfinal⟩ = U₂U₁|ψinitial⟩

The order is important because matrix multiplication is generally non-commutative: U₂U₁ is not usually equal to U₁U₂.

2. Single-Qubit Gates

2.1 The identity gate

The identity gate I does nothing to a qubit:

I = [[1, 0], [0, 1]]

It is useful when describing unchanged wires, proving circuit identities, and matching the dimensions of operators in multi-qubit systems.

2.2 Pauli gates

The three Pauli gates are X, Y, and Z. They are fundamental both computationally and physically.

GateMatrixAction on basis states
X[[0, 1], [1, 0]]X
Y[[0, −i], [i, 0]]Y
Z[[1, 0], [0, −1]]Z

The X gate is the quantum analogue of a bit flip. The Z gate is a phase flip: it leaves |0⟩ unchanged but changes the sign of the |1⟩ amplitude. The Y gate combines a bit flip and a phase transformation.

For a general state |ψ⟩ = α|0⟩ + β|1⟩,

X|ψ⟩ = β|0⟩ + α|1⟩

and

Z|ψ⟩ = α|0⟩ − β|1⟩

A global phase, such as multiplying the entire state by −1, cannot be observed in measurement. A relative phase between terms, however, affects interference and is physically important.

2.3 Hadamard gate

The Hadamard gate H creates and removes equal superpositions:

H = 1/√2 [[1, 1], [1, −1]]

Its action is

H|0⟩ = (|0⟩ + |1⟩)/√2
H|1⟩ = (|0⟩ − |1⟩)/√2

Applying H to |0⟩ gives equal measurement probabilities of 1/2 for 0 and 1. Applying H again returns the original state because H² = I. This illustrates interference: the second Hadamard recombines amplitudes so that one outcome may cancel and the other may reinforce.

2.4 Phase gates

The phase gate S applies a quarter-turn phase to |1⟩:

S = [[1, 0], [0, i]]

Thus S|0⟩ = |0⟩ and S|1⟩ = i|1⟩. The T gate applies an eighth-turn phase:

T = [[1, 0], [0, eiπ/4]]

The Z gate is also called the phase gate in a broader sense. In the sequence of phase rotations, S² = Z and T² = S, up to the conventional definitions shown here.

2.5 Rotation gates

Continuous rotations provide a parameterized family of operations. Around the x, y, and z axes, the standard definitions are

Rx(θ) = cos(θ/2)I − i sin(θ/2)X
Ry(θ) = cos(θ/2)I − i sin(θ/2)Y
Rz(θ) = cos(θ/2)I − i sin(θ/2)Z

where θ is the rotation angle in radians and I, X, Y, Z are the matrices defined above. The factor θ/2 is a consequence of the mathematical representation of qubit states on the Bloch sphere.

For example,

Ry(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩

At θ = π, R_y(π)|0⟩ = |1⟩, apart from a possible convention-dependent global phase. Rotation gates are especially important in hardware calibration and variational quantum algorithms.

3. Multi-Qubit States and Tensor Products

Two qubits require a four-dimensional state vector. The computational basis is

|00⟩, |01⟩, |10⟩, |11⟩

A general two-qubit state is

|ψ⟩ = a|00⟩ + b|01⟩ + c|10⟩ + d|11⟩

with |a|² + |b|² + |c|² + |d|² = 1. The tensor product, written ⊗, combines systems. For example, applying H to the first qubit and I to the second is represented by H ⊗ I:

(H ⊗ I)|ψ⟩

The ordering convention must be stated. This chapter uses |q₀q₁⟩, with the leftmost symbol written first. Software libraries may use different internal ordering conventions, so professional practice requires checking documentation before interpreting vectors or matrices.

4. Controlled Gates

A controlled gate applies an operation to a target qubit only when a control qubit has a specified value, usually 1. The controlled-NOT, or CNOT, is the most important example.

For control c and target t,

|c,t⟩ → |c, t ⊕ c⟩

where ⊕ denotes addition modulo 2. The mapping is therefore |00⟩ → |00⟩, |01⟩ → |01⟩, |10⟩ → |11⟩, and |11⟩ → |10⟩.

In the basis order |00⟩, |01⟩, |10⟩, |11⟩, the CNOT matrix with the first qubit as control is

CNOT = [[1,0,0,0], [0,1,0,0], [0,0,0,1], [0,0,1,0]]

A controlled-Z gate applies Z to the target when the control is 1. It changes only |11⟩ by a minus sign:

CZ = diag(1, 1, 1, −1)

The controlled-U construction generalizes this idea. If U is a single-qubit operation, then controlled-U acts as I on the target when the control is 0 and as U when the control is 1.

Controlled gates can create entanglement. For example,

CNOT(H ⊗ I)|00⟩ = (|00⟩ + |11⟩)/√2

The resulting Bell state cannot be expressed as a product of two independent single-qubit states.

5. The SWAP Gate

The SWAP gate exchanges two qubit states:

SWAP|a,b⟩ = |b,a⟩

Its matrix in the standard two-qubit basis is

SWAP = [[1,0,0,0], [0,0,1,0], [0,1,0,0], [0,0,0,1]]

A SWAP can be decomposed into three CNOT gates:

SWAP = CNOT₁→₂ CNOT₂→₁ CNOT₁→₂

The rightmost operation acts first. This decomposition matters because many physical processors provide CNOT gates but not a native SWAP gate.

6. Reading and Constructing Circuits

To read a circuit, proceed from left to right and identify:

  1. the initial state and qubit ordering;
  2. the gates acting at each time step;
  3. whether gates act on one qubit or several;
  4. the state after each significant operation;
  5. the measurement basis and resulting probabilities.

Gates on different qubits in the same time layer may often be applied in either order because they act on separate tensor factors. For instance, X ⊗ Z and Z ⊗ X refer to different operations on two wires, but the operations within the same layer commute when each acts on a distinct qubit.

To construct a circuit, begin with the desired state transformation. A useful design pattern is:

  • use H or a rotation to prepare a superposition;
  • use controlled gates to establish correlations or entanglement;
  • use phase gates to encode relative phase;
  • use inverse operations to cause constructive or destructive interference;
  • measure only after the quantum computation is complete.

Worked Example 1: Tracing a single-qubit circuit

Consider the sequence H followed by Z followed by H, starting with |0⟩. The state evolution is

|0⟩ → (|0⟩ + |1⟩)/√2

After Z,

(|0⟩ + |1⟩)/√2 → (|0⟩ − |1⟩)/√2

Applying H again gives |1⟩. Therefore

HZH|0⟩ = |1⟩

This circuit converts a phase difference into a measurable bit value. Without the final H, the relative phase would not be directly visible in computational-basis measurement probabilities.

Worked Example 2: Creating a Bell state

Start with |00⟩. Apply H to the first qubit:

(H ⊗ I)|00⟩ = (|00⟩ + |10⟩)/√2

Next apply CNOT with the first qubit as control:

CNOT(|00⟩ + |10⟩)/√2 = (|00⟩ + |11⟩)/√2

The probabilities are P(00) = 1/2 and P(11) = 1/2, while P(01) = P(10) = 0. The results are correlated even though each individual qubit has no definite computational-basis value before measurement.

7. Circuit Simplification and Identities

Circuit simplification reduces gate count, execution time, and exposure to noise. Important identities include

X² = Y² = Z² = H² = I

and

S² = Z, T² = S

The inverse of a unitary gate U is U†. Applying U† immediately after U gives I. For rotations,

Rk(θ)† = Rk(−θ)

where k is x, y, or z. Thus R_z(θ) followed by R_z(−θ) cancels.

Some gates do not commute. For example, HX is not generally equal to XH. In fact, useful conjugation identities include

HXH = Z

and

HZH = X

CNOT operations may be rearranged only when their control-target relationships and intervening gates permit it. A common error is to cancel two visually similar gates without checking whether another non-commuting gate lies between them.

8. Measurement and Probability Tracing

If a state is

|ψ⟩ = ∑x αx|x⟩

then measurement in the computational basis produces outcome x with probability

P(x) = |αx|²

and the probabilities satisfy ∑ₓ P(x) = 1. Measurement is not merely observation in the classical sense: it projects the state onto the observed basis state. Repeated circuit execution, called sampling or taking shots, estimates the probability distribution.

For example, a state with amplitudes 1/√2 and −1/√2 has the same computational-basis probabilities as a state with amplitudes 1/√2 and 1/√2. The sign difference is nevertheless important because later gates can transform it into a different measurable distribution.

9. Practical Implementation Considerations

The circuit model is idealized. Real quantum processors introduce several constraints:

  • Decoherence: interaction with the environment changes the state.
  • Gate error: physical pulses implement gates imperfectly.
  • Readout error: the classical measurement device may report the wrong value.
  • Connectivity limits: a processor may allow two-qubit gates only between neighboring qubits.
  • Finite coherence time: circuits must usually be completed before useful quantum information is lost.
  • Calibration drift: gate performance can change as hardware conditions vary.

A compiler may decompose abstract gates into a device’s native gate set, route qubits using SWAP operations, and optimize the circuit. Fewer two-qubit gates generally improve reliability because two-qubit operations are often noisier than single-qubit operations.

Quantum error correction addresses noise using additional physical qubits, but it does not make individual gates magically perfect. It requires carefully designed codes, syndrome extraction, and an error rate below relevant fault-tolerance thresholds.

10. Applied Case: A Small Entanglement Demonstration

This is an illustrative case.

Background

A technical team is evaluating whether a two-qubit teaching processor can demonstrate quantum correlations. The processor supports H, X, Z, and CNOT gates and returns computational-basis samples.

Problem

The team must create a circuit whose results distinguish a Bell state from two independently randomized qubits.

Analysis

Independent randomization would produce approximately equal frequencies for 00, 01, 10, and 11. A Bell-state circuit should produce only 00 and 11, ideally with equal frequency.

Approach and solution

The team initializes both qubits to |00⟩, applies H to qubit 0, and then applies CNOT with qubit 0 as control and qubit 1 as target. The ideal final state is

(|00⟩ + |11⟩)/√2

They execute the circuit for many shots. If the device were perfect, about half the results would be 00 and half 11. In practice, a small number of 01 and 10 results may appear because of gate and measurement errors.

Outcome

The strong concentration of results in 00 and 11 demonstrates correlation. It is evidence consistent with the intended entangled state, although finite sampling and noise mean that experimental data will not exactly match ideal probabilities.

Learning points

The case shows how a circuit converts abstract matrix operations into an observable experiment. It also illustrates why circuit depth, two-qubit-gate count, device connectivity, and statistical sampling matter in professional quantum-computing work.

11. Best Practices for Circuit Design

  1. State the qubit-ordering convention before writing multi-qubit vectors.
  2. Track amplitudes symbolically before substituting numerical values.
  3. Distinguish global phase from relative phase.
  4. Verify that every gate is unitary and dimensionally compatible with the state.
  5. Simplify inverse pairs and repeated self-inverse gates only when adjacency or commutation is justified.
  6. Minimize two-qubit gates and unnecessary SWAP operations.
  7. Check both ideal simulation results and noisy hardware results.
  8. Use repeated shots and report sampling uncertainty when interpreting experiments.
  9. Treat measurement as a state-changing operation, not merely a display command.
  10. Document software conventions, gate order, qubit mapping, and hardware assumptions.

Chapter Summary

Quantum gates are unitary transformations that preserve the norm of a quantum state. The Pauli X, Y, and Z gates perform bit and phase transformations; H creates and removes equal superpositions; S and T provide fixed phase shifts; and rotation gates implement parameterized changes around Bloch-sphere axes. Multi-qubit operations include CNOT, controlled-Z, general controlled-U, and SWAP. Tensor products describe operations on several qubits, while circuit order determines matrix order. Relative phase becomes observable through interference, and controlled gates can create entanglement. Circuit simplification uses inverse operations, self-inverse identities, and justified commutation. Real devices add noise, limited connectivity, calibration challenges, and readout errors, making efficient circuit design essential.

Key Terms

Qubit: A quantum two-level system represented by a normalized state vector.

Computational basis: The basis consisting of |0⟩ and |1⟩, or their multi-qubit extensions.

Amplitude: A complex coefficient whose squared magnitude gives measurement probability.

Normalization: The condition that all outcome probabilities sum to one.

Unitary operator: A matrix U satisfying U†U = I.

Quantum gate: A reversible unitary transformation applied to one or more qubits.

Pauli-X gate: A gate that exchanges |0⟩ and |1⟩.

Pauli-Y gate: A bit-and-phase transformation involving imaginary amplitudes.

Pauli-Z gate: A phase-flip gate that changes the sign of |1⟩.

Hadamard gate: A gate that creates equal superpositions from computational-basis states.

Phase gate: A gate that changes the phase of one basis component.

Rotation gate: A parameterized gate representing rotation around a Bloch-sphere axis.

Tensor product: Mathematical operation used to combine quantum systems.

Controlled gate: An operation applied to a target conditional on a control qubit.

CNOT: A controlled-X gate that flips the target when the control is 1.

SWAP gate: A gate that exchanges the states of two qubits.

Relative phase: A phase difference between components of a superposition.

Entanglement: A non-separable relationship between quantum systems.

Circuit depth: The number of sequential time layers in a circuit.

Decoherence: Loss of quantum information through environmental interaction.

Review Questions

Short Answer Questions

  1. What condition must a matrix satisfy to represent an ideal quantum gate?
  2. What is the difference between a bit flip and a phase flip?
  3. What state results from applying H to |0⟩?
  4. What does a CNOT gate do when its control qubit is 0?
  5. Why are relative phases important in quantum circuits?

Long Answer Questions

  1. Explain the action and significance of the Pauli X, Y, and Z gates, including their matrix representations.
  2. Describe how tensor products are used to represent operations on two qubits.
  3. Explain the construction of a Bell state using H and CNOT, showing each state transformation.
  4. Discuss the principal differences between ideal circuit execution and execution on noisy hardware.
  5. Explain how gate identities and commutation can be used to simplify a circuit, including examples of cases where gates cannot be reordered.

Analytical / Application Questions

  1. Starting from |00⟩, analyze the circuit H on the first qubit followed by CNOT with the first qubit as control. Determine all measurement probabilities and explain the correlations.
  2. Design a circuit that maps |0⟩ to a state with measurement probabilities cos²(θ/2) for 0 and sin²(θ/2) for 1. Identify the gate and parameter required.
  3. A hardware platform has no native SWAP gate but supports CNOT. Construct an equivalent three-gate circuit and explain how qubit connectivity affects its practical cost.

Multiple Choice Questions with Answers

Question 1

Which condition characterizes an ideal quantum gate matrix U?

A. U + U† = I

B. U†U = I

C. U² = 0

D. det(U) = 0

Correct Answer: B. U†U = I

Question 2

What is the result of applying the X gate to |0⟩?

A. |0⟩

B. −|0⟩

C. |1⟩

D. i|1⟩

Correct Answer: C. |1⟩

Question 3

What state results from applying H to |0⟩?

A. (|0⟩ + |1⟩)/√2

B. (|0⟩ − |1⟩)/√2

C. |1⟩

D. (|0⟩ + i|1⟩)/√2

Correct Answer: A. (|0⟩ + |1⟩)/√2

Question 4

Which gate changes the sign of the |1⟩ component while leaving |0⟩ unchanged?

A. X

B. Y

C. Z

D. H

Correct Answer: C. Z

Question 5

In a CNOT gate, what happens when the control qubit is 0?

A. The target is always measured as 0

B. The target is flipped

C. The target is unchanged

D. Both qubits are swapped

Correct Answer: C. The target is unchanged

Question 6

Starting with |00⟩, H on the first qubit followed by CNOT produces which state?

A. (|00⟩ + |01⟩)/√2

B. (|00⟩ + |11⟩)/√2

C. (|01⟩ + |10⟩)/√2

D. |11⟩

Correct Answer: B. (|00⟩ + |11⟩)/√2

Question 7

Which expression gives the probability of measuring basis state |x⟩ with amplitude αₓ?

A. αₓ

B. Re(αₓ)

C. |αₓ|²

D. 1 − |αₓ|²

Correct Answer: C. |αₓ|²

Question 8

Which identity is correct for the Hadamard gate?

A. H² = X

B. H² = Z

C. H² = I

D. H² = Y

Correct Answer: C. H² = I

Question 9

How many CNOT gates are required in the standard decomposition of a SWAP gate?

A. One

B. Two

C. Three

D. Four

Correct Answer: C. Three

Question 10

For the state Ry(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩, what is the probability of measuring 1?

A. sin(θ)

B. sin²(θ/2)

C. cos²(θ/2)

D. θ/2

Correct Answer: B. sin²(θ/2)

Introduction to Quantum Computing
Chapter 5 of 14