First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 6.3

Quantum Gates: Unitary Operators & Linear Algebra

Understand the mathematical engine of quantum circuits: Unitary 2x2 and 4x4 complex matrices that rotate quantum states.

Learning Objectives

  • βœ“Define quantum gates as Unitary square matrices: U * U_dagger = I
  • βœ“Understand geometric rotations on the Bloch Sphere: R_x(theta), R_y(theta), R_z(theta)
  • βœ“Analyze why quantum logic must be strictly reversible

πŸ“–Let's Begin with a Story

In classical computing, the universal building block is the NAND gate. If you plug in two 1s, it outputs 0. If you plug in 0 and 1, it outputs 1. Notice something crucial: two bits enter, but only one bit exits! The other bit was destroyed and vanished as thermal heat. You cannot run a NAND gate backwards: if you see an output of 1, you have no way of knowing whether the input was (0,0), (0,1), or (1,0). Quantum gates are fundamentally different. By the laws of quantum mechanics, information can never be destroyed. Every quantum gate is a reversible geometric rotation in a multi-dimensional sphere. If you rotate an apple 90 degrees clockwise, you can always rotate it 90 degrees counter-clockwise to put it back exactly as it was. That is why all quantum gates are unitary matrices!

Why Should You Learn Quantum Gates: Unitary Operators & Linear Algebra?

🎯 Practical & Engineering Stakes

The core algebra of quantum computing

Every quantum program you will ever write is simply a sequence of unitary matrix multiplications. Mastering their matrix properties unlocks complete fluency in quantum programming.

What Is It?

Simple Explanation

Classical gates are one-way streets (information gets crushed). Quantum gates are two-way roundabouts: - Every gate is a smooth, elegant rotation of the qubit's arrow on the Bloch sphere. - Because it’s a rotation, you can always run it in reverse to undo it. - A single-qubit gate is a 2x2 matrix of numbers. - A two-qubit gate is a 4x4 matrix of numbers.

Technical Explanation

A quantum gate acting on nn qubits is represented by a unitary matrix U∈U(2n)U \in U(2^n) satisfying U†U=UU†=I2nU^\dagger U = U U^\dagger = I_{2^n}, where U†=(Uβˆ—)TU^\dagger = (U^*)^T is the conjugate transpose. Unitary matrices preserve inner products ⟨UΟ•βˆ£Uψ⟩=βŸ¨Ο•βˆ£ΟˆβŸ©\langle U\phi | U\psi \rangle = \langle \phi | \psi \rangle, guarantee that probabilities sum to 1, and possess eigenvalues of unit modulus Ξ»=eiΞΈ\lambda = e^{i\theta}.

πŸ“š Key Terms

Unitary Matrix

Simple: A square grid of numbers whose reverse is its complex conjugate transpose (U * U_dagger = I).
Technical: A bounded linear operator on complex Hilbert space whose adjoint equals its inverse: U†=Uβˆ’1U^\dagger = U^{-1}.

Conjugate Transpose (U†U^\dagger)

Simple: Flipping rows and columns and changing the sign of all imaginary numbers (i becomes -i).
Technical: The Hermitian adjoint operator (U†)ij=Ujiβ€Ύ(U^\dagger)_{ij} = \overline{U_{ji}}.

TraceTrace

Simple: The sum of numbers along the main diagonal of a square matrix.
Technical: The invariant sum of diagonal elements Tr(A)=βˆ‘Aii\text{Tr}(A) = \sum A_{ii} equal to the sum of eigenvalues.

Q-Sphere Lab: Quantum Gates: Unitary Operators & Linear Algebra

IBM Q-Sphere Model

Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.3

Azimuth: 45Β°Elevation: 25Β°
+Z |0⟩-Z |1⟩+X |+⟩+Y |+i⟩01|ψ⟩
Q-Sphere Phase Color:
0 Ο€/2 Ο€ 3Ο€/2

Quantum Statevector

dim(H) = 2
|ψ⟩ = (1.000 + 0.000i)|0⟩
     + (0.000 + 0.000i)|1⟩
Polar Angle (ΞΈ):0.0Β° (0.000Ο€ rad)
Phase Angle (Ο•):0.0Β° (0.000Ο€ rad)

Born Rule Probabilities: P(x) = |⟨x|ψ⟩|²Σ P = 1.00

P(|0⟩) = |α|²100.0%
P(|1⟩) = |β|²0.0%
Quantum Measurement

Apply Single-Qubit Unitary Gates

Presets:
Continuous Polar Angle θ (0° = |0⟩, 180° = |1⟩):0.0°
Continuous Phase Angle Ο• (0Β° to 360Β°):0.0Β°
Recent Operations Log:
#1Initial state: |0⟩

πŸ“ Mathematical Foundation

LaTeX KaTeX
U=(u00u01u10u11),U†=(u00βˆ—u10βˆ—u01βˆ—u11βˆ—),UU†=U†U=(1001)=IU = \begin{pmatrix} u_{00} & u_{01} \\ u_{10} & u_{11} \end{pmatrix}, \quad U^\dagger = \begin{pmatrix} u_{00}^* & u_{10}^* \\ u_{01}^* & u_{11}^* \end{pmatrix}, \quad U U^\dagger = U^\dagger U = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I

What does it mean?

Unitary Condition for Quantum Gates: Unlike classical gates that destroy information (like AND or OR), all quantum gates are reversible unitary transformations. Multiplying gate U by its conjugate transpose U† yields the Identity matrix I, preserving state vector length and total probability with zero information loss.

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
UUUnitary quantum gate matrixA 2Γ—22 \times 2 complex matrix that rotates the quantum state vector
U†U^\daggerHermitian adjoint (dagger)Transpose rows and columns, then take complex conjugate (i β†’ -i)
UU†=IU U^\dagger = IUnitarity conditionGuarantee that the operation is 100% reversible with zero information loss
I=[[1,0],[0,1]]I = [[1, 0], [0, 1]]Identity matrixThe do-nothing base matrix that leaves state vectors unchanged

πŸ“Š Numerical Example

Testing the unitarity of the Phase Gate S = [[1, 0], [0, i]]:

Step 1: Write S matrix: S = [[1, 0], [0, i]] Step 2: Compute S† (transpose and conjugate i β†’ -i): S† = [[1, 0], [0, -i]] Step 3: Multiply S Γ— S†: S Γ— S† = [[1Γ—1 + 0Γ—0, 1Γ—0 + 0Γ—(-i)], [0Γ—1 + iΓ—0, 0Γ—0 + iΓ—(-i)]] = [[1, 0], [0, -i^2]] Recall i^2 = -1, so -i^2 = -(-1) = 1: = [[1, 0], [0, 1]] = I βœ“

Result: The S gate satisfies S S† = I, confirming it is a mathematically valid reversible quantum gate.

βš™οΈ How Does It Work?

1

Matrix-Vector Product

Apply gate U to input state vector |psi>: |psi'> = U * |psi>.

2

Norm Preservation

Verify that length of output vector remains strictly equal to 1.0.

3

Inversion

To undo the gate, apply U_dagger: U_dagger * |psi'> = |psi>.

🌍 Where Is It Used?

Quantum Circuit Compilation (Qiskit Transpiler)

Problem: Physical quantum computers only support 2 or 3 native microwave pulses.

Solution: The transpiler decomposes arbitrary high-level unitary matrices into equivalent products of physical hardware basis gates.

🎯 Try It Yourself

Why MUST all quantum gates be represented by Unitary matrices?

Interactive activity component

🐍 Python Hands-On: Exploring Single-Qubit Unitary Matrices in Qiskit

Construct single-qubit quantum gates (X, Y, Z, H, S, T) in Qiskit and compute their exact 2x2 complex unitary matrices.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install qiskit numpy
Packages:
qiskitnumpy

2Import Libraries

Import Statementspython
1from qiskit import QuantumCircuit
2from qiskit.quantum_info import Operator
3import numpy as np

from qiskit import QuantumCircuit β†’ Circuit module

from qiskit.quantum_info import Operator β†’ Operator matrix extractor

import numpy as np β†’ NumPy for formatting

3Demonstration Code & Logic

Python Execution Codepython
1gate_names = ['X (NOT)', 'Y', 'Z (Phase)', 'H (Hadamard)', 'S (pi/2)', 'T (pi/4)']
2print('=== Fundamental Single-Qubit Gate Matrices in Qiskit ===\n')
3for name in gate_names:
4 qc = QuantumCircuit(1)
5 if 'X' in name: qc.x(0)
6 elif 'Y' in name: qc.y(0)
7 elif 'Z' in name: qc.z(0)
8 elif 'H' in name: qc.h(0)
9 elif 'S' in name: qc.s(0)
10 elif 'T' in name: qc.t(0)
11 matrix = Operator(qc).data
12 print(f'{name} Unitary Matrix:')
13 print(np.round(matrix, 3))
14 print()
Step-by-Step Code Breakdown:

gate_names = ['X (NOT)', 'Y', 'Z (Phase)', 'H (Hadamard)', 'S (pi/2)', 'T (pi/4)']

List of gates

print('=== Fundamental Single-Qubit Gate Matrices in Qiskit ===\n')

Header

for name in gate_names:

Loop gates

qc = QuantumCircuit(1)

Create 1-qubit circuit

if 'X' in name: qc.x(0)

Apply X

elif 'Y' in name: qc.y(0)

Apply Y

elif 'Z' in name: qc.z(0)

Apply Z

elif 'H' in name: qc.h(0)

Apply H

elif 'S' in name: qc.s(0)

Apply S

elif 'T' in name: qc.t(0)

Apply T

matrix = Operator(qc).data

Extract matrix

print(f'{name} Unitary Matrix:')

Print name

print(np.round(matrix, 3))

Print rounded matrix

print()

Spacing

πŸ“‹ Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Exploring Single-Qubit Unitary Matrices in Qiskit
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install qiskit numpy
8
9# Step 2: Import libraries
10from qiskit import QuantumCircuit
11from qiskit.quantum_info import Operator
12import numpy as np
13
14# Step 3: Run Demonstration
15gate_names = ['X (NOT)', 'Y', 'Z (Phase)', 'H (Hadamard)', 'S (pi/2)', 'T (pi/4)']
16print('=== Fundamental Single-Qubit Gate Matrices in Qiskit ===\n')
17for name in gate_names:
18 qc = QuantumCircuit(1)
19 if 'X' in name: qc.x(0)
20 elif 'Y' in name: qc.y(0)
21 elif 'Z' in name: qc.z(0)
22 elif 'H' in name: qc.h(0)
23 elif 'S' in name: qc.s(0)
24 elif 'T' in name: qc.t(0)
25 matrix = Operator(qc).data
26 print(f'{name} Unitary Matrix:')
27 print(np.round(matrix, 3))
28 print()
⚑ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

πŸ”„ Algorithmic Execution Flow

1
Instantiate Circuits

Create circuits applying individual single-qubit gates.

β†’
2
Extract Unitaries

Use Qiskit Operator to compute the exact 2x2 complex matrix representation.

β†’
3
Inspect Transformations

Display matrices demonstrating rotational actions on the Bloch sphere.

πŸ“₯ Input / Initial State
Single-qubit circuits with X, Y, Z, H, S, and T gates.
πŸ“€ Expected Output
2x2 unitary matrices for each gate:
X: [[0, 1], [1, 0]]
Z: [[1, 0], [0, -1]]
H: [[0.707, 0.707], [0.707, -0.707]]
S: [[1, 0], [0, 1j]]
πŸ’‘ What Does This Demonstration Show?

Every single-qubit gate corresponds to a 2x2 complex unitary matrix that preserves vector norms, rotating the state vector across the continuous Bloch sphere.

Course Learning Resource β€’ Slide DeckLesson 810 Slides

Lesson 8: Two Qubits and Entanglement

Hadamard, CNOT, Bell-state intuition, and correlated quantum circuits.

Author: Dr. Syed Muzamil Bashaβ€’ FDP Approved Curriculum
Open in New Tab

πŸ“ Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: What is the matrix dimension of a quantum gate that acts on 2 qubits simultaneously (e.g. CNOT)?

Question 2: Why must all quantum gates be represented as unitary matrices?

Question 3: What is a universal gate set in quantum computing?

Question 4: What is the dimension of a single-qubit gate matrix?

Question 5: What property distinguishes quantum gates from classical logic gates?