Skip to content

Lesson 36: The Quantum Software Landscape

36.1 Learning Outcomes

By the end of this hour a student will be able to:

  1. Describe the layers of the quantum software stack and what each is responsible for.
  2. Compare simulator types (statevector, density matrix, stabiliser, tensor network, MPS) and their scaling.
  3. Explain transpilation and why it is unavoidable.
  4. Read and write basic OpenQASM.
  5. Choose an appropriate framework for a given task.

36.2 The Quantum Software Stack

  +--------------------------------------------------------+
  |  APPLICATION      chemistry, finance, ML, optimisation  |
  +--------------------------------------------------------+
  |  ALGORITHM        VQE, QAOA, Shor, Grover, QPE          |
  +--------------------------------------------------------+
  |  CIRCUIT / SDK    Qiskit, Cirq, PennyLane, Q#           |
  +--------------------------------------------------------+
  |  INTERMEDIATE     OpenQASM 3, QIR, Quil                 |
  +--------------------------------------------------------+
  |  COMPILER         transpiler: routing, mapping, opt.    |
  +--------------------------------------------------------+
  |  CONTROL          pulse-level: Qiskit Pulse, OpenPulse  |
  +--------------------------------------------------------+
  |  HARDWARE / SIM   QPU, statevector, tensor network      |
  +--------------------------------------------------------+

The analogy with classical computing: the SDK is the high-level language, OpenQASM is the assembly language, the transpiler is the compiler back end, and the pulse layer is the microcode.

36.3 Simulator Types

The most consequential practical choice a student makes.

Simulator Memory Time Max qubits Handles noise?
Statevector \(O(2^{n})\) \(O(2^{n})\) per gate ~30–40 no (pure states only)
Density matrix \(O(4^{n})\) \(O(4^{n})\) ~15–20 yes
Stabiliser (CHP) \(O(n^{2})\) \(O(n^{2})\) thousands Clifford + Pauli noise only
Matrix product state (MPS) \(O(n\chi^{2})\) \(O(n\chi^{3})\) 100s (low entanglement) with care
Tensor network depends on contraction width varies 100s (shallow) limited
Extended stabiliser \(O(\chi\,\mathrm{poly}(n))\), \(\chi = 2^{O(t)}\) — 100s with few \(T\) gates limited

Statevector — the default

Stores all \(2^{n}\) complex amplitudes.

\(n\) Memory (complex128)
20 16 MB
30 16 GB
34 256 GB
40 17.6 TB

A laptop handles ~28 qubits; a workstation ~34; a supercomputer ~45–49. Every additional qubit doubles the requirement — the wall is hard and unavoidable.

Stabiliser — the surprising one

Gottesman–Knill theorem (L08). Circuits of Clifford gates (\(H\), \(S\), CNOT) with computational-basis measurement are simulable in \(O(n^2)\) classical time.

So a 10 000-qubit Clifford circuit simulates instantly, while a 40-qubit circuit with \(T\) gates does not. What makes simulation hard is not qubit count but non-Cliffordness. Stabiliser simulators are essential for quantum error correction research, where circuits are large but almost entirely Clifford.

MPS / tensor network — the entanglement-aware one

An MPS represents the state as a chain of tensors with bond dimension \(\chi\), which bounds the entanglement across any cut:

\[ S_{\max} = \log_2\chi \]

Low-entanglement states are cheap. A product state has \(\chi = 1\); a shallow 1-D circuit has small \(\chi\). Cost grows as \(O(n\chi^3)\), so an MPS simulator can handle hundreds of qubits if the circuit does not generate much entanglement — but blows up for deep, highly entangling circuits.

This is how "quantum supremacy" claims get contested. Google's 2019 Sycamore result was later partially reproduced classically with improved tensor-network contraction, and the argument continues.

36.4 Transpilation

Definition. Transpilation (or compilation) rewrites an abstract circuit into one executable on specific hardware.

The four tasks

1. Gate translation (basis change). Hardware supports only a fixed basis gate set, e.g. IBM's \(\{\)ECR or CZ, \(R_z\), \(S_x\), \(X\}\). Every abstract gate must be decomposed into it.

\[ H \ \longrightarrow\ R_z(\pi)\,S_x\,R_z(\pi/2) \quad(\text{up to phase}) \]

2. Qubit mapping (layout). Assign logical qubits to physical qubits, preferring those with the best coherence and gate fidelity.

3. Routing (SWAP insertion). Real devices allow two-qubit gates only between connected qubits. A CNOT between distant qubits requires SWAPs to bring them together.

Suppose the device connectivity is a line:  q0 - q1 - q2 - q3
Requested: CNOT(q0, q3)

Compiled:  SWAP(q0,q1)  SWAP(q1,q2)  CNOT(q2,q3)  SWAP(q1,q2)  SWAP(q0,q1)

Each SWAP costs 3 CNOTs, so this one logical gate becomes \(4\times3 + 1 = 13\) CNOTs. Routing is often the dominant cost on real hardware, and finding the optimal routing is NP-hard.

4. Optimisation. Cancel adjacent inverse gates, merge consecutive rotations (\(R_z(a)R_z(b) = R_z(a+b)\)), commute gates past each other, resynthesise blocks.

Optimisation levels (Qiskit convention)

Level Behaviour Use
0 mapping only, no optimisation debugging
1 light — adjacent-gate cancellation quick runs
2 medium — commutation analysis default
3 heavy — resynthesis, noise-adaptive layout production

Level 3 typically reduces CNOT count by 30–60 % over level 0 — a decisive difference on NISQ hardware, where CNOT error (\(\sim10^{-2}\)) dominates.

Why transpilation is not optional

Requested Delivered on hardware
Any two-qubit pair only physically coupled pairs
Any gate only the basis set
Ideal gates gates with \(10^{-3}\)–\(10^{-2}\) error
Arbitrary depth depth limited by \(T_2/t_{\text{gate}}\)

36.5 OpenQASM

The assembly language of quantum computing, and the interchange format between frameworks.

A Bell state in OpenQASM 3

OPENQASM 3.0;
include "stdgates.inc";

qubit[2] q;
bit[2] c;

h q[0];
cx q[0], q[1];

c = measure q;

OpenQASM 2 versus 3

Feature QASM 2 QASM 3
Classical control flow none if, for, while
Real-time computation no yes
Timing / delay no yes
Typed classical variables no yes (int, float, bit)
Mid-circuit measurement + feed-forward limited full support

QASM 3's classical control matters because error correction and teleportation both require measuring, computing on the result, and applying a conditional gate — all within coherence time.

QASM 3 with feed-forward (teleportation correction)

OPENQASM 3.0;
include "stdgates.inc";

qubit[3] q;
bit m0;
bit m1;

// ... prepare and entangle ...

m0 = measure q[0];
m1 = measure q[1];

if (m1 == 1) { x q[2]; }
if (m0 == 1) { z q[2]; }

36.6 Framework Comparison

Framework Vendor Language Strength Best for
Qiskit IBM Python largest ecosystem, real hardware access general, teaching
Cirq Google Python explicit device/moment model hardware-aware research
PennyLane Xanadu Python autodiff, ML integration QML
Q# / QDK Microsoft Q# (own language) type safety, resource estimation algorithm verification
Braket SDK Amazon Python multi-vendor access comparing hardware
TensorFlow Quantum Google Python Keras integration hybrid quantum-classical ML
pytket Quantinuum Python best-in-class compiler circuit optimisation
ProjectQ ETH Zürich Python clean compiler design education
XACC ORNL C++/Python HPC integration supercomputing

Decision guide.

Goal Choose
Learning quantum computing Qiskit — most documentation and tutorials
Quantum machine learning PennyLane — automatic differentiation
Squeezing out the last CNOT pytket — best optimisation passes
Estimating fault-tolerant resources Q# / Azure Quantum Resource Estimator
Benchmarking across vendors Braket

36.7 Solved Problems

Problem 1 — Choosing a simulator

Which simulator would you use, and why, for each task?

(a) Verify a 25-qubit Grover circuit. (b) Simulate a 500-qubit surface-code round. (c) Study depolarising noise on a 12-qubit VQE. (d) Simulate a 100-qubit shallow QAOA circuit.

Solution.

(a) Statevector. 25 qubits needs \(2^{25}\times16 = 537\) MB — fits in RAM. Grover contains multi-controlled gates (non-Clifford), so stabiliser simulation is unavailable. Statevector gives exact amplitudes, which is what verification requires.

(b) Stabiliser (CHP / Aaronson–Gottesman). Surface-code syndrome extraction is entirely Clifford (CNOTs, Hadamards, measurements). \(O(n^2)\) scaling makes 500 qubits trivial — statevector would need \(2^{500}\) amplitudes, more than there are atoms in the universe.

(c) Density matrix. Noise turns a pure state into a mixed one, which a statevector cannot represent. \(4^{12} = 1.7\times10^{7}\) entries × 16 bytes \(= 268\) MB — comfortable. (Alternative: statevector + Monte Carlo trajectory sampling, cheaper but needs many runs.)

(d) MPS or tensor network. \(2^{100}\) is impossible for statevector. A shallow QAOA circuit generates limited entanglement, so the bond dimension \(\chi\) stays modest and MPS cost \(O(n\chi^{3})\) is manageable. Caveat: if \(p\) is large, \(\chi\) grows exponentially and MPS fails too.

The general rule.

\[ \text{Clifford? } \to \text{stabiliser}; \quad \text{noisy \& small? } \to \text{density matrix}; \quad \text{low entanglement? } \to \text{MPS}; \quad \text{otherwise } \to \text{statevector, } n \le 30. \]

Problem 2 — Statevector memory and the wall

Compute memory for statevector simulation at \(n = 26, 30, 34, 38\) using complex128 (16 bytes). What is the largest \(n\) on (a) a 16 GB laptop, (b) a 1 TB server, (c) a 1 PB supercomputer?

Solution.

\[ M = 2^{n}\times16 \ \text{bytes} \]
\(n\) Amplitudes Memory
26 \(6.7\times10^{7}\) 1.07 GB
30 \(1.07\times10^{9}\) 17.2 GB
34 \(1.72\times10^{10}\) 275 GB
38 \(2.75\times10^{11}\) 4.4 TB

Maximum \(n\) per platform (allowing ~half the memory for the state, since gate application often needs a working copy):

(a) 16 GB laptop: \(2^{n}\times16 \le 8\times10^{9} \Rightarrow 2^{n}\le5\times10^{8} \Rightarrow n \le \mathbf{28}\).

(b) 1 TB server: \(2^{n}\le 3.1\times10^{10} \Rightarrow n\le\mathbf{34}\).

(c) 1 PB supercomputer: \(2^{n}\le3.1\times10^{13} \Rightarrow n\le\mathbf{44}\).

The brutal arithmetic. Going from a laptop to a petascale supercomputer — a \(10^{5}\)-fold memory increase — buys only 16 more qubits. Each qubit costs a factor of 2, so a factor of \(10^{5}\) is \(\log_2 10^{5} \approx 16.6\) qubits.

\[ \boxed{\ \text{This is precisely why quantum computers are interesting: } 50 \text{ qubits already exceeds all classical memory.}\ } \]

Problem 3 — Transpilation cost of routing

A circuit needs CNOT(\(q_0\), \(q_7\)) on a device with linear connectivity \(q_0 - q_1 - \cdots - q_7\). Count the physical CNOTs, and compute the circuit fidelity at CNOT error \(10^{-2}\).

Solution.

Distance. \(q_0\) to \(q_7\) is 7 hops apart, so 6 SWAPs are needed to bring them adjacent (moving \(q_0\) next to \(q_7\)).

Naive routing.

SWAP(0,1) SWAP(1,2) SWAP(2,3) SWAP(3,4) SWAP(4,5) SWAP(5,6)   -- 6 SWAPs in
CNOT(6,7)                                                      -- 1 CNOT
SWAP(5,6) SWAP(4,5) SWAP(3,4) SWAP(2,3) SWAP(1,2) SWAP(0,1)   -- 6 SWAPs out
\[ \text{CNOTs} = 12\ \text{SWAPs}\times3 + 1 = \mathbf{37} \]

Optimised (no swap-back). If subsequent gates can use the permuted layout, the return SWAPs are unnecessary and a final classical relabelling of the measurement bits suffices:

\[ 6\times3 + 1 = \mathbf{19}\ \text{CNOTs} \]

Fidelity.

\[ F_{\text{naive}} = (1 - 10^{-2})^{37} = 0.99^{37} = \mathbf{0.689} \]
\[ F_{\text{opt}} = 0.99^{19} = \mathbf{0.826} \]

One logical CNOT costs 17–31 % of the circuit's fidelity.

Design implications.

  1. Design circuits for the hardware topology. Nearest-neighbour circuits transpile for free.
  2. Use optimization_level=3, which uses SABRE routing and avoids unnecessary swap-backs.
  3. Prefer devices with better connectivity. Trapped-ion machines have all-to-all coupling and need zero SWAPs — often outperforming faster superconducting devices on connectivity-heavy circuits despite slower gates.

Problem 4 — Writing and reading OpenQASM

Write OpenQASM 3 for a 3-qubit GHZ state with measurement. Then hand-simulate this QASM and state the output distribution:

qubit[2] q;
bit[2] c;
h q[0];
h q[1];
cz q[0], q[1];
h q[1];
c = measure q;

Solution.

Part 1 — GHZ.

OPENQASM 3.0;
include "stdgates.inc";

qubit[3] q;
bit[3] c;

h q[0];
cx q[0], q[1];
cx q[0], q[2];

c = measure q;

Expected output: 000 and 111, each with probability \(\frac12\).

Part 2 — hand-simulate the given circuit.

Recall from L08 that \(\mathrm{CNOT}_{0\to1} = (I\otimes H)\,CZ\,(I\otimes H)\). The circuit is \(H_0, H_1, CZ, H_1\), which is

\[ (I\otimes H)\,CZ\,(H\otimes H) = (I\otimes H)\,CZ\,(I\otimes H)\,(H\otimes I) = \mathrm{CNOT}_{0\to1}\,(H\otimes I) \]

So the circuit is exactly \(H\) on \(q_0\) then CNOT — the Bell-state circuit.

\[ |00\rangle \ \longrightarrow\ \frac{1}{\sqrt2}\big(|00\rangle + |11\rangle\big) \]

Output distribution: 00 and 11 with probability 0.5 each; 01 and 10 never occur.

Verification by direct computation:

\[ |00\rangle \xrightarrow{H\otimes H} \tfrac12\big(|00\rangle+|01\rangle+|10\rangle+|11\rangle\big) \]
\[ \xrightarrow{CZ} \tfrac12\big(|00\rangle+|01\rangle+|10\rangle-|11\rangle\big) \]
\[ \xrightarrow{I\otimes H} \tfrac{1}{2\sqrt2}\Big[(|00\rangle+|01\rangle) + (|00\rangle-|01\rangle) + (|10\rangle+|11\rangle) - (|10\rangle - |11\rangle)\Big] \]
\[ = \tfrac{1}{2\sqrt2}\big[2|00\rangle + 2|11\rangle\big] = \tfrac{1}{\sqrt2}\big(|00\rangle+|11\rangle\big) \ \checkmark \]

Problem 5 — Framework selection for a research project

Recommend a framework for each project, with reasoning.

(a) Train a 6-qubit VQC with PyTorch integration. (b) Estimate the physical qubits needed to factor RSA-2048. (c) Minimise the CNOT count of a 20-qubit chemistry circuit. (d) Compare the same circuit on superconducting, trapped-ion and neutral-atom hardware. (e) Simulate 200 qubits of a surface code.

Solution.

(a) PennyLane. It is the only framework with first-class automatic differentiation that interoperates natively with PyTorch, TensorFlow and JAX. A QNode is a differentiable PyTorch module, so quantum layers drop straight into an existing classical network, and gradients flow through by parameter-shift automatically. (TensorFlow Quantum is the Keras-only alternative.)

(b) Q# / Azure Quantum Resource Estimator. Microsoft's tool is purpose-built for this: it takes a Q# program, applies a chosen QEC scheme (surface code, Hastings–Haah), a physical error rate and a gate-time model, and outputs physical qubit counts and runtime. No other framework does fault-tolerant resource estimation as a first-class feature.

(c) pytket (Quantinuum). Independent benchmarks consistently show TKET producing 10–30 % fewer two-qubit gates than other transpilers, thanks to its Clifford-resynthesis and phase-polynomial passes. It also accepts circuits from Qiskit and Cirq, so you can write in Qiskit and compile with pytket.

(d) Amazon Braket. It provides a single SDK and a single billing account across IonQ (trapped ion), Rigetti and IQM (superconducting), and QuEra (neutral atom). Writing the comparison in any vendor SDK would mean maintaining three separate code paths and three accounts.

(e) Stim (Craig Gidney's stabiliser simulator), accessible from Python. Surface-code circuits are Clifford, and Stim simulates millions of Clifford gates per second — orders of magnitude faster than Qiskit's or Cirq's stabiliser back ends. It is the standard tool in the QEC community, paired with PyMatching for decoding.

The meta-lesson. There is no single best framework. Frameworks are interoperable via OpenQASM 3, so the professional workflow is to use each where it is strongest: prototype in Qiskit, differentiate in PennyLane, compile with pytket, estimate resources in Q#, and benchmark on Braket.

36.8 Practice Problems

  1. Memory for a 22-qubit statevector at complex64 (8 bytes)? [Ans: 33.6 MB]
  2. Why can a 1000-qubit Clifford circuit be simulated but not a 50-qubit universal one?
  3. How many CNOTs to route CNOT(\(q_0,q_4\)) on a line, with swap-back? [Ans: \(8\times3+1 = 25\)]
  4. Write OpenQASM 3 for the Deutsch algorithm with \(f(x)=x\).
  5. What bond dimension does a 2-qubit maximally entangled state need? [Ans: \(\chi = 2\)]
  6. Which framework for benchmarking three vendors' hardware, and why?
  7. Compare optimisation levels 0 and 3 in terms of CNOT count and fidelity.

36.9 Summary

  • The stack runs application → algorithm → SDK → intermediate representation (OpenQASM/QIR) → transpiler → pulse → hardware.
  • Simulator choice is the key practical decision: statevector (\(O(2^n)\), ≤30–40 qubits), density matrix (\(O(4^n)\), noisy, ≤20), stabiliser (\(O(n^2)\), thousands of qubits but Clifford only), MPS/tensor network (hundreds of qubits at low entanglement).
  • What makes simulation hard is non-Cliffordness and entanglement, not qubit count.
  • Transpilation performs gate translation, layout, routing (SWAP insertion — often the dominant cost) and optimisation. Level 3 typically saves 30–60 % of CNOTs.
  • OpenQASM 3 is the interchange standard and adds classical control flow, enabling mid-circuit measurement with feed-forward.
  • Framework choice follows the task: Qiskit (general/teaching), PennyLane (QML/autodiff), pytket (compilation), Q# (resource estimation), Braket (multi-vendor), Stim (QEC).

Next lesson: L37 — IBM Qiskit I: circuits, simulation and primitives.

Practise now: unit4-platforms-lab.html → Circuit Builder: build a circuit visually and see the equivalent Qiskit, Cirq, PennyLane, Q# and OpenQASM 3 code emitted side by side.