๐Ÿงฑ Introduction to the Quantum Software Stack

What Happens Between an Algorithm and a Pulse, Built From Scratch

๐Ÿ“– Reading Time: 20-25 minutes ๐Ÿ“Š Difficulty: Beginner ๐Ÿ’ป Code Examples: 0 ๐Ÿ“ Exercises: 0

๐ŸŒ EN | ๐Ÿ‡ฏ๐Ÿ‡ต JP | Last sync: 2026-08-13

AI Terakoya Topโ€บFundamental Mathematics Dojoโ€บIntroduction to the Quantum Software Stack

โ† Back to Fundamental Mathematics Dojo

๐ŸŽฏ Series Overview

This is not an SDK tutorial. It is a course on what SDKs do.

That distinction is the reason the series exists, so it is worth being precise about it. Between a quantum algorithm written as mathematics and a machine that accepts shaped microwave or laser pulses there are six layers of software: a circuit representation, an optimizer, a placement and routing stage, a gate-synthesis stage, a pulse compiler with its calibration loops, and a measurement post-processor. Chapter 1 tabulates seven, because its table counts the algorithm itself as layer 1. Every quantum framework in existence implements those layers. None of them explains them, because documentation exists to tell you which function to call, not what the function had to solve.

So this course builds a miniature version of the whole stack, in NumPy, from nothing. A circuit intermediate representation in Chapter 1, with a unitary-equivalence checker that guards every rewrite that follows. A peephole optimizer and single- and two-qubit gate synthesis in Chapter 2. Connectivity graphs, layout and a SWAP router in Chapter 3. A three-level pulse simulator with Rabi, Ramsey and DRAG calibration in Chapter 4. Readout-error correction, zero-noise extrapolation, probabilistic error cancellation and a resource estimator in Chapter 5. Nothing is called; everything is written, run, and measured.

The payoff is not that you should use the code here instead of a framework โ€” you should not, and the closing section of Chapter 1 says so plainly. The payoff is that a framework's API changes every year and its layers do not. When you can read a transpiled circuit and say this grew because of routing, not synthesis, or look at a basis gate set and know which synthesis problem the compiler had to solve, or estimate what an algorithm will cost before writing a line of it, then the documentation of any framework becomes a reference rather than a mystery. That is the state this course is designed to leave you in.

The second commitment is the verification discipline, which is the technical spine of the series. A compiler pass is correct when it preserves the meaning of the circuit, and for quantum circuits "same meaning" has an exact and checkable definition: the same unitary, up to a global phase. Every pass in these five chapters ships with that check, run exhaustively where the register is small and on random states where it is not. Chapter 1 builds the checker; Chapter 2 uses it on six hundred randomly generated rewrites โ€” two hundred circuits through each of three optimizing pipelines โ€” alongside two hundred runs of a no-op control pipeline; Chapter 5 uses it on the mitigation circuits. It is also how this course can be honest without hardware access: the claims are either checked numerically or presented as parametric estimates, never quoted.

Learning Path

flowchart LR P1["Required
Quantum computing
introduction"] P2["Recommended
Quantum hardware
introduction"] A["Chapter 1
The stack, the IR,
and equivalence"] B["Chapter 2
Optimization and
gate synthesis"] C["Chapter 3
Transpilation and
connectivity"] D["Chapter 4
Pulses and
calibration"] E["Chapter 5
Mitigation and
resource estimation"] P1 --> A P2 --> A A --> B B --> C A --> D B -.-> E C -.-> E D --> E style P1 fill:#e2e8f0,stroke:#94a3b8,stroke-width:1px,color:#334155 style P2 fill:#e2e8f0,stroke:#94a3b8,stroke-width:1px,color:#334155 style A fill:#667eea,stroke:#764ba2,stroke-width:2px,color:#fff style B fill:#7b2cbf,stroke:#764ba2,stroke-width:2px,color:#fff style C fill:#7b2cbf,stroke:#764ba2,stroke-width:2px,color:#fff style D fill:#7b2cbf,stroke:#764ba2,stroke-width:2px,color:#fff style E fill:#9d4edd,stroke:#764ba2,stroke-width:2px,color:#fff

Chapter 1 is not optional: it fixes the circuit representation, the qubit convention and the equivalence checker that the other four chapters use without restating. From there the series splits. Chapters 2 and 3 are the compiler path and are best read in order, since routing consumes the output of synthesis. Chapter 4 depends only on Chapter 1 and can be read directly after it by anyone whose interest is control rather than compilation. Chapter 5 reads best after all of them, but the dependence is conceptual rather than a flow of data: it prices what the other layers cannot fix, and it assumes you can already read a gate count as Chapter 2 does, a routing overhead as Chapter 3 does, and a physical error rate as Chapter 4 measures one. Its resource estimator is self-contained โ€” the inputs are a Hamiltonian 1-norm, a target precision, a walk cost, a physical error rate and a logical qubit count, and nothing is imported from the earlier chapters' code. The dashed edges above mark that kind of dependency.

๐Ÿ“‹ Learning Objectives

On finishing this series you will be able to:

๐Ÿ“– Prerequisites

Required. Introduction to Quantum Computing, or equivalent fluency with state vectors and unitary gates, the big-endian qubit convention, the ninety-nine-line state-vector simulator of that course's Chapter 2, and its treatment of noise channels and error correction in Chapter 5. Every chapter here re-lists the simulator functions it needs, but none of them re-derives the physics.

Required. Linear algebra: unitary and Hermitian matrices, tensor products, eigendecomposition, and matrix norms. Chapter 2's synthesis arguments and Chapter 4's three-level dynamics both need eigenvalues rather than only matrix multiplication.

Required. Python 3.8 or later with NumPy, SciPy and Matplotlib. There is no quantum SDK and no hardware backend anywhere in this series โ€” that is the point of it.

Recommended. Introduction to Quantum Hardware. Chapter 3 explains connectivity graphs as consequences of the platform physics โ€” all-to-all for trapped ions, sparse for superconducting circuits โ€” and Chapter 4 revisits the resonant-drive physics of that course's Chapter 2 in the language of control. Both chapters are readable without it, and considerably more interesting with it.

Useful but not required. Intermediate Quantum Algorithms, for the circuits this stack is asked to compile, and for the resource-estimation conventions Chapter 5 stays consistent with.


๐Ÿ“š Chapters

Chapter 1: The Stack from Algorithms to Pulses

Why there are layers at all, and where the boundaries belong: the criterion turns out to be how perishable each pass's input is, which sorts the seven layers into exactly the order they are conventionally drawn in. The circuit intermediate representation of the course is then fixed โ€” gate tuples, big-endian wires, run_circuit, circuit_depth, gate_counts โ€” with an argument that the choice of gate set, and nothing about data structures, is what makes a layer boundary. Compilation is defined as meaning-preserving rewriting, with the three correctness relations in use (exact up to a global phase, exact up to a qubit permutation, approximate within $\varepsilon$) and the unitary-equivalence checker that tests the first of them. Closes with a map of what commercial frameworks call these layers, in terms general enough to survive their next several releases, and with a four-stage compiler pipeline whose stubs the remaining chapters replace.

Key topics : the seven layers ยท perishability as the layering criterion ยท circuit IR as data ยท gate sets as layer boundaries ยท depth and its unit-time assumption ยท the three correctness relations ยท global-phase removal by Hilbert-Schmidt overlap ยท why a global phase is not global inside a controlled block ยท state versus unitary equivalence ยท the SDK layer correspondence

๐Ÿ’ป 7 Code Examples โฑ๏ธ 45-50 minutes ๐Ÿ“Š Intermediate

Read Chapter 1 โ†’

Chapter 2: Circuit Optimization and Gate Synthesis

The rewriting rules that a peephole optimizer is made of: fusion of adjacent gates, cancellation of inverses, and the commutation rules that decide when two gates may be exchanged. Single-qubit synthesis by Euler decomposition, which turns any $U(2)$ into three rotations, implemented and verified against the Chapter 1 checker. Two-qubit synthesis: the KAK decomposition as a concept, explicit two- and three-CNOT constructions, and the lower bound on the CNOT count that says when you have finished. Then Clifford$+T$ and the reason the $T$ gate is expensive, which is a statement about error correction rather than about hardware, and which sets up the resource arithmetic of Chapter 5. Closes with measurements: a peephole optimizer run over random circuits with the depth and gate-count reduction recorded, and every rewrite verified for unitary equivalence.

Key topics : gate fusion and cancellation ยท commutation rules ยท circuit identities ยท Euler and ZYZ decomposition ยท KAK decomposition ยท two-CNOT and three-CNOT constructions ยท CNOT lower bounds ยท Clifford$+T$ ยท $T$ count ยท exhaustive equivalence verification of an optimizer

๐Ÿ’ป 7 Code Examples โฑ๏ธ 45-50 minutes ๐Ÿ“Š Advanced

Read Chapter 2 โ†’

Chapter 3: Transpilation โ€” Mapping to Connectivity

Connectivity graphs as consequences of physics: all-to-all where a shared bosonic mode couples every qubit, a two-dimensional lattice or a heavy-hex graph where the coupling is capacitive and the frequencies must not collide. The placement problem โ€” choosing which physical qubit each program qubit starts on โ€” with an honest account of why it is NP-hard and why heuristics are nonetheless sufficient. Routing by SWAP insertion, and the principle behind the forward-and-backward heuristics that modern routers use. Then the cost measurement: SWAP overhead as a function of connectivity and circuit structure, with the reasoning behind synthetic benchmarks and without any vendor numbers. Closes with an implementation: a graph representation, a nearest-neighbour router, GHZ and QFT circuits routed onto three geometries with their SWAP counts compared, and post-routing equivalence verified including the qubit permutation.

Key topics : coupling graphs ยท all-to-all, lattice and heavy-hex ยท initial layout selection ยท NP-hardness and why heuristics suffice ยท SWAP insertion ยท lookahead routing heuristics ยท SWAP overhead versus connectivity ยท equivalence up to a permutation

๐Ÿ’ป 7 Code Examples โฑ๏ธ 45-50 minutes ๐Ÿ“Š Advanced

Read Chapter 3 โ†’

Chapter 4: Pulses and Calibration

What is underneath a gate: a rotation is a resonant drive, and the physics of Chapter 2 of the hardware course reappears here as a control problem. Pulse shaping from the square pulse to the Gaussian to DRAG, motivated by the thing that makes shaping necessary โ€” leakage out of the computational subspace of a weakly anharmonic system. The calibration loop as the distinctive feature of this layer: Rabi amplitude calibration, frequency calibration by Ramsey interferometry, and DRAG coefficient calibration, which together are software conducting an experiment on its own machine. Randomized benchmarking and the reason it can separate gate fidelity from state-preparation and measurement error. Closes with a three-level pulse simulator: leakage measured under a square pulse and suppressed by DRAG, calibration loops that recover parameters deliberately mis-set beforehand, and a simulated randomized-benchmarking run whose extracted gate error matches the value that was configured.

Key topics : resonant drive and the rotating frame ยท leakage and anharmonicity ยท Gaussian and DRAG pulse shaping ยท Rabi amplitude calibration ยท Ramsey frequency calibration ยท DRAG coefficient calibration ยท randomized benchmarking ยท separating SPAM from gate error

๐Ÿ’ป 9 Code Examples โฑ๏ธ 50-55 minutes ๐Ÿ“Š Advanced

Read Chapter 4 โ†’

Chapter 5: Error Mitigation as Software, and Resource Estimation

Mitigation treated as what it actually is โ€” a software layer that post-processes measurement results. Readout-error correction from the confusion matrix, by inversion and by constrained least squares, with the reason the second is preferred. Zero-noise extrapolation implemented by gate folding, with the variance cost measured rather than asserted. Probabilistic error cancellation and its quasi-probability construction, with the exponential sampling cost shown numerically, because an honest account of a method includes the point at which it stops working. Then the boundary of the whole approach: mitigation costs grow exponentially and correction costs grow polynomially, which is where software ingenuity ends and error correction begins. A resource-estimation pipeline follows, implemented as functions from an algorithm's $T$ count through code distance and physical qubit count to a runtime. Closes with a map of the six-course quantum family and how its chapters cross-reference.

Key topics : confusion matrix and readout correction ยท constrained least squares ยท zero-noise extrapolation by gate folding ยท variance cost of mitigation ยท quasi-probability and PEC ยท exponential sampling cost ยท mitigation versus correction ยท $T$ count to code distance to physical qubits ยท runtime estimation ยท the series map

๐Ÿ’ป 8 Code Examples โฑ๏ธ 45-50 minutes ๐Ÿ“Š Advanced

Read Chapter 5 โ†’


๐Ÿ”ค Notation and Conventions

Two conventions are inherited from Introduction to Quantum Computing and never changed; the third is new here and is the technical contract of the series.

Symbol Meaning
$\lvert q_0 q_1 \cdots q_{n-1}\rangle$ big-endian: qubit 0 is leftmost and most significant. The opposite of the convention used by much of the SDK literature
$\hbar = 1$ reduced units wherever a Hamiltonian appears, which is Chapter 4
$C = [g_1, \ldots, g_L]$ a circuit is a list of gate tuples, applied left to right
$U(C)$ the $2^n \times 2^n$ matrix of a circuit, $U_{g_L}\cdots U_{g_1}$
$e^{i\varphi}$ the global phase, quotiented out by every equivalence check
$\mathrm{depth}(C)$ number of layers under greedy packing by qubit disjointness
$\varepsilon$ error of an approximate synthesis, in operator norm
$d$ code distance (Chapter 5); $\lVert \cdot \rVert$ is the operator norm elsewhere
$X, Y, Z, H, S, T$, CNOT gate symbols, identical to the introductory course

The circuit IR. Fixed in Chapter 1 and used unchanged by all five chapters:

Gate tuple Meaning
("h", q), ("x", q), ("z", q), ("s", q), ("t", q) fixed single-qubit gates
("rx", theta, q), ("ry", theta, q), ("rz", theta, q) rotations, angle in radians, $R_a(\theta) = e^{-i\theta A/2}$
("cx", control, target), ("cz", q1, q2) two-qubit gates

Three functions come with it โ€” run_circuit(circ, n), circuit_depth(circ, n), gate_counts(circ) โ€” and each chapter re-lists the ones it uses, verbatim.

Parameters, not specifications. Gate durations, error rates and coherence times appear throughout as dimensionless parameters swept over decades. They are there to expose scaling and constant factors, and they are not device specifications, measurements, or predictions about any machine.


๐Ÿ” What This Series Is and Is Not

It is not an SDK tutorial. No framework is installed, imported, or version-pinned anywhere in these five chapters. Section 1.4 maps the layers onto the components every framework has, using generic names, and that is the closest the series comes to API documentation โ€” deliberately, because an API changes and a layer does not.

It is a bridge to an SDK, not a replacement for one. A production framework gives you hardware access, passes developed against real devices, and a maintained machine description for every backend. None of that is replaceable. What it does not give you is knowledge of what the passes did, and that is the half this course supplies.

It is not a hardware course. The physics of qubits, coherence and gate mechanisms belongs to Introduction to Quantum Hardware. Chapter 4 uses exactly as much of it as a control problem requires: a three-level system, a drive, and a leakage channel.

It is not an algorithms course. The circuits compiled here are small and generic. For the algorithms that produce interesting circuits, read Intermediate Quantum Algorithms.

It is not promotional about mitigation. Chapter 5 implements zero-noise extrapolation and probabilistic error cancellation and then measures what they cost. Where the cost is exponential, that is stated with the number attached, and the chapter says plainly where software ingenuity ends.

Everything runs, and everything is checked. Every code example was executed to produce the output shown. Every rewriting pass is accompanied by a unitary-equivalence check, and where the register is too large for an exhaustive check, the fallback and its limitations are stated rather than skipped.

๐Ÿ“š Recommended Learning Paths

Pattern 1: Complete path (6-7 days)

Pattern 2: The compiler path (2-3 days)

Pattern 3: The control path (1-2 days)

Pattern 4: The sceptic's path (half a day)

๐ŸŽฏ Overall Learning Outcomes

Knowledge Level

Practical Skills

Application Ability

๐Ÿ› ๏ธ Technologies and Tools Used

Main Libraries

Development Environment

๐Ÿš€ Next Steps

Deep Dive Learning

Related Series

Practical Projects

โš ๏ธ Disclaimer