Quantum Software Stack
A quantum software stack connects a mathematical task to device operations and interprets the resulting measurements. Some work can happen before a run; some must finish while a quantum state remains coherent; statistical analysis usually combines many runs. Calibration and experimental results also change later compilation decisions, so the process has feedback rather than a single downward sequence.
This page follows those connections. It separates ideal program meaning, target-specific execution, and inference from finite data. The individual representations and compiler transformations are developed in the linked pages.
Required background. Circuit Model defines registers and quantum–classical operations; Universal Gate Sets explains synthesis; Hardware Overview introduces physical controls and device constraints.
Quantum programs and their execution
Section titled “Quantum programs and their execution”Consider estimating an observable after a parameterized state preparation. An algorithm chooses the preparation and measurement. A compiler chooses native gates, physical qubits, and operation order. A controller delivers timed signals and acquires detector data. An estimator turns the outcomes into a value with uncertainty. A fault-tolerant implementation inserts encoded operations, syndrome extraction, decoding, and possibly resource factories.
| Stage | Main object | Question to resolve |
|---|---|---|
| Task and algorithm | Input, observable, accuracy, success probability | Are state preparation and data access included? |
| Quantum–classical program | Gates, measurements, branches, outputs | What do the register labels and parameters mean? |
| Encoded implementation, if used | Code operations, syndrome cycles, decoder, factories | Which physical resources realize the logical computation? |
| Compiled circuit | Native gates, placement, routing, schedule | Are connectivity and simultaneous-operation constraints satisfied? |
| Control execution | Frames, waveforms, acquisitions, branch decisions | Do signals and feedback meet the required timing? |
| Data and inference | Outcomes, acceptance flags, estimator, uncertainty | Which experimental ensemble does the answer describe? |
Not every system exposes each intermediate form. A service may combine passes or hide pulse definitions. The distinction still helps locate a failure: correct source code does not prove that a physical waveform was delivered, and plausible final counts do not prove that the intended circuit ran. Chong, Franklin, and Martonosi review how hardware constraints affect these software choices.
Specify the task before optimizing it
Section titled “Specify the task before optimizing it”An application needs an input representation, output quantity, accuracy or decision criterion, and allowed failure probability. For phase estimation, phase-grid spacing alone does not specify confidence: the prepared state’s eigenstate weights and the measurement distribution also matter. The phase-estimation article develops those probabilities.
An oracle query, a prepared state, and a classical data table are different access assumptions. Compilation cannot make an omitted preparation cost disappear. Likewise, allowing postselection changes the task unless rejection and the probability of acceptance are included explicitly.
What compilation must preserve
Section titled “What compilation must preserve”A program can denote a unitary, a channel, an outcome-resolved instrument, or a distribution of reported answers. Compare the relevant object on the specified input class. Equal matrix dimensions or equal gate counts establish none of these equivalences.
For an isolated unitary, global phase does not affect its channel. For a coherently controlled subroutine, that phase becomes relative between control branches and must be retained or compensated. Measurements and reset require channel or instrument semantics, developed in Circuit Intermediate Representations.
An unknown quantum state cannot be copied to avoid recomputation. Discarding a subsystem means taking its partial trace; if it is entangled with live data, the remaining state can be mixed. Reusing that physical subsystem additionally requires its specified initialization or reset. These physical operations are different from merely deleting a name in source code.
A composable approximation bound
Section titled “A composable approximation bound”For compatible completely positive trace-preserving maps, define
This distance includes inputs entangled with an untouched reference. If stage approximates by within , then
Insert and subtract one stage at a time. The triangle inequality bounds the sum; composition with the surrounding channels cannot increase this norm. Both properties are needed, not merely the existence of some distance between two layer descriptions (Watrous, Chapter 3). Classical records can be retained as orthogonal output labels, so a complete adaptive program also fits this channel description.
When two representations live on different spaces, first specify their input and output encoding or interpretation maps. When physical errors depend on an unmodeled environment or history, separate context-independent stage channels may not exist. One must enlarge the model or bound the whole process. Average gate infidelities are not interchangeable with these worst-case bounds.
Postselection is another qualification. The map including success and failure flags is linear, but normalizing only a successful branch is generally nonlinear in the input. Conditioning on rare acceptance can magnify a small unconditional difference; an accepted-output bound needs acceptance control. The approximation sum is therefore not automatically an experimental error bar or a conditional-fidelity guarantee.
The target includes timing and calibration
Section titled “The target includes timing and calibration”A device name and qubit count do not determine an executable. Relevant target information includes active connectivity, native operations, durations, concurrency restrictions, measurement/reset capabilities, calibrated frames and waveforms, and controller memory and latency limits. Record the version and calibration time used for a run so that these choices can be interpreted.
Drift can make yesterday’s good placement unsuitable today. Conversely, recompiling for every noisy fluctuation in a scalar calibration estimate can make performance less reliable. Error-Aware Compilation treats the uncertainty in choosing placements and schedules; Murali and colleagues give a concrete noise-adaptive mapping study.
For several modules, the target also includes resource contention, link generation, and memory availability. Modular Architectures explains those physical limits, while Distributed Quantum Computing develops remote operations and program partitioning.
Pass order changes cost
Section titled “Pass order changes cost”A typical compilation sequence parses and checks the program, simplifies classical control, synthesizes gates, optimizes the circuit, places qubits, inserts movement, schedules operations, and lowers them to controller instructions. A later pass may expose new opportunities for an earlier one: routing can create adjacent inverse gates, and decomposition can expose cancellations. Exact transformations need not commute as representations.
A virtual Z rotation may update a tracked phase without emitting a pulse. Moving or deleting a subsequent operation without carrying that frame changes the physical rotation axis. Timing constraints can also make a formally valid gate identity invalid as a schedule rewrite. Häner and colleagues discuss compilation across abstraction levels; the pulse-control page develops frames and timing.
Cost depends on the intended use
Section titled “Cost depends on the intended use”Gate count, depth, scheduled duration, ancilla count, classical bandwidth, and physical error can compete. Fewer entangling gates may require noisier links or longer idle times. More resource factories may reduce runtime at the cost of qubits and control infrastructure. Compare a Pareto set or state the weights and units of a scalar objective.
An independent-fault model sometimes uses
This is not a generic circuit success probability: a fault can be corrected or irrelevant to the requested observable, and multiple faults can cancel. Coherent errors cannot generally be represented by independent fault events. Spectator effects, crosstalk, and common drift can invalidate even the assumed marginal probabilities. Noise in Quantum Information explains how a component characterization differs from a workload’s effective channel.
Classical work has different deadlines
Section titled “Classical work has different deadlines”| Regime | Example | Timing constraint |
|---|---|---|
| Before execution | Synthesis, placement, scheduling | Finish before the executable is needed and its target assumptions expire |
| Between executions | Variational update or next-experiment selection | Usually no live quantum state must survive the calculation |
| During execution | Classification, reset, feedforward, decoder decision | Finish before the dependent operation needs the result |
| After data acquisition | Estimation, uncertainty, diagnostic comparisons | Preserve the meaning and selection of the measured samples |
Cross and colleagues distinguish near-time and real-time classical work in OpenQASM 3. Córcoles and colleagues demonstrate how adaptive execution changes an algorithm’s implementation. A faster classical processor helps only if acquisition, transport, synchronization, and dispatch meet the same deadline.
For a serial feedback path, a simple model is
Streaming stages can overlap; then use the actual dependency path rather than adding overlapping durations. Distinguish first-result latency from sustained throughput. Meeting a deadline requires a bound or an accepted tail probability for jitter, not just a favorable mean. A host callback after a job finishes cannot implement a branch acting on quantum data already discarded.
Retain branch states as well as probabilities
Section titled “Retain branch states as well as probabilities”Let measurement outcome have completely positive, trace-nonincreasing map , with trace preserving. If the subsequent branch operation is trace preserving, then
The normalized branch state is for . Matching only the final unconditioned state can lose the association between the output and the recorded bit. If a branch operation is itself selective, retain its additional success/failure outcome; its accepted trace is not the original measurement probability. See Quantum Instruments and Mid-Circuit Measurement and Feedforward.
Fault-tolerant resources must arrive on time
Section titled “Fault-tolerant resources must arrive on time”Encoded execution adds repeated syndrome extraction, decoding, tracked frames, logical movement, and possibly state injection and distillation. A logical gate count alone omits factory placement, storage, routing, and classical processing. Resource Estimation connects these choices to physical qubits and time.
For a resource buffer, write the exact count balance as
It obeys . Potential production is not always admitted production: a full buffer can block a factory or discard outputs. Requested demand is not always consumption: an empty buffer causes a stall unless the schedule can do other work. In a deterministic fluid approximation away from these boundaries, is useful. Average supply greater than demand alone does not exclude shortfalls during bursts. Storage errors and expiry can require another loss term.
A union bound can allocate total failure probability across defined data, factory, routing, decoder, and input/output fault events. It does not require independence, but every failure must be included and each probability must refer to its actual context. Surface Code provides one concrete encoded implementation; it is not the only stack.
Estimating a two-qubit correlator
Section titled “Estimating a two-qubit correlator”Suppose the task asks for after preparing . The circuit measures both qubits in the computational basis. For shot ,
With counts summing to ,
The classical-bit schema matters when identifying which two bits these are. However, exchanging these two bits leaves parity unchanged. This particular observable cannot reveal their interchange; an asymmetric probe such as is needed. A successful parity check therefore does not validate the entire output mapping.
For independent, identically distributed observations and fixed , the sample variance is . The corresponding estimated standard error of the sample mean is
With even and odd outcomes, and the estimated standard error is about . A large-sample normal interval is roughly at 95% confidence. This approximation is unsuitable near all-even or all-odd counts: a zero empirical variance does not prove zero uncertainty. A binomial interval for , transformed by , handles that boundary. Adaptive stopping needs its own coverage analysis.
If these are accepted shots, the estimate concerns the accepted ensemble. Acceptance correlated with the outcome or input generally changes the target. Readout correction changes the estimator and its variance; pooling drifting batches need not satisfy the identical-distribution assumption.
Sampling error does not include every bias
Section titled “Sampling error does not include every bias”Let be the ideal quantity and the actual expectation under the stated sampling and selection model. Then
The first term has mean zero only if the estimator is unbiased for that model. The second describes implementation or modeling bias. More shots need not reduce either an estimator’s own bias or the difference between actual and ideal expectations. Calibration, detector errors, synthesis, and selection need separate analysis. Reading Quantum-Technology Claims develops these distinctions beyond this example.
Check software meaning and physical execution separately
Section titled “Check software meaning and physical execution separately”For small isolated unitary circuits, compare matrices up to global phase, with a specified norm. Retain the phase for coherent controlled use. For adaptive circuits compare outcome-resolved maps, including probabilities and conditional states for every allowed input, not just one test state. Structural checks also verify resource conflicts, data dependencies, frames, and timing.
Exact dense comparison grows exponentially. Formal proofs, specialized equivalence methods, and independently generated small examples complement each other. Hietala and colleagues’ VOQC proves transformations against its mathematical circuit semantics; that proof does not certify an unmodeled controller, waveform, or device. Physical checks must additionally test measurement labels, branch execution, timing, and calibration validity.
Portability and reproduction
Section titled “Portability and reproduction”Parsing the same source does not guarantee support for its operations or timing. A backend’s supported language profile and target capabilities matter. Two implementations can preserve ideal behavior while having very different gate counts, latency, and physical error. Splitting an adaptive program into separate jobs is equivalent only if its quantum state and dependencies survive the split; syntax acceptance does not establish this.
For a published run retain source and parameters, compiler versions/options, randomized-routing seeds, target/calibration information, physical and output mappings, executable identity, timestamps, outcomes with acceptance flags, and analysis code. Preserve batch boundaries when conditions change. The reproducible-notebook guide develops a runnable workflow rather than another list of software layers.
Retries need explicit handling: a lost reply does not tell the client whether the device ran. Stable request identifiers and recorded execution status help avoid silently duplicating samples. Missing or outcome-dependent rejected records can bias an estimate even if the completed circuits are correct. Reproducibility means reconstructing the procedure and expected variation, not forcing a future noisy device to return the same bit string.
Exercises
Section titled “Exercises”1. Pass order and cost
Section titled “1. Pass order and cost”Two exact compiler passes satisfy and . Must they produce the same cost when applied in opposite orders?
Solution
No. Semantic preservation does not imply that the transformations commute or have identical cost effects:
as representations, even though both can denote the same computation. Decomposition can expose cancellations; routing can create new adjacent gates; and scheduling can constrain later rewrites. Pass order is therefore part of the optimization configuration and provenance.
2. A composed approximation bound
Section titled “2. A composed approximation bound”Four compatible channel stages have certified half-diamond distances , , , and . Give a conservative composed bound and state one reason it may not be a complete experimental error estimate.
Solution
A telescoping expansion and contractivity under the surrounding channels give
This is conservative and valid only for compatible channel domains and the stated metric. Unmodeled drift, leakage, correlated faults, detector bias, or a mismatch between the certified model and the physical device can add error not present in the four terms.
3. A serial feedback deadline
Section titled “3. A serial feedback deadline”A serial feedback path with nonoverlapping stages uses ns acquisition, ns digitization, ns classification, ns decision logic, ns dispatch, and ns propagation. The deadline is ns and the required engineering margin is of the deadline. Is the path admissible?
Solution
The nominal path is
The margin is , so the admissible latency is ns. Since ns is below ns, the nominal design meets the requirement with ns remaining. Jitter and worst-case rather than mean latencies must still be checked.
4. When a fault-product proxy fails
Section titled “4. When a fault-product proxy fails”A compiler estimates a candidate’s no-fault proxy as a product of independent gate no-fault probabilities. Give two physical effects that can make the ranking unreliable even when every marginal gate error estimate is accurate.
Solution
Coherent overrotations can add constructively or cancel depending on sequence and phase, so a product of marginal probabilities misses circuit structure. Simultaneous-operation crosstalk can make a gate’s error depend on the schedule and spectator states. Leakage persistence, common-mode drift, and correlated radiation events are other valid examples.
5. Measurement and conditional reset
Section titled “5. Measurement and conditional reset”A dynamic program measures a qubit and applies when the result is one. Why is unitary matrix comparison insufficient for validating a compiler pass that rewrites this fragment?
Solution
Measurement is not a unitary operation on the program’s visible state. It produces an outcome distribution, updates the conditional quantum state, and creates a classical record used by the branch. Validation must compare the outcome-resolved instrument or every branch probability and conditional state for every allowed input. A unitary matrix has no place to encode those semantics.
6. Factory supply and burst demand
Section titled “6. Factory supply and burst demand”A magic-state factory produces one state every code cycles. The scheduled computation consumes bursts of five states every cycles. Does the average supply exceed average demand, and is that alone sufficient to avoid stalls?
Solution
The supply rate is states per cycle. The average demand is states per cycle, so supply is already insufficient on average and the buffer will eventually empty.
Even if average supply exceeded demand, it would not alone prevent stalls. Burst timing and buffer capacity matter. The inventory must contain five usable states at each burst, including losses, verification failures, and routing latency.
7. Splitting an adaptive program
Section titled “7. Splitting an adaptive program”One backend accepts an OpenQASM program but lowers unsupported dynamic branches by splitting it into host-controlled jobs. Another executes the branches in its controller. Which portability claims hold?
Solution
Both may provide source or syntax portability. Semantic portability holds only if splitting preserves quantum-state continuity, branch behavior, and all required timing. Fresh jobs that reinitialize live data generally fail this test. Real-time target portability does not hold: the host-controlled backend cannot implement a coherence-bound branch merely by accepting the source. Performance portability also need not hold because queue and network latency can dominate the split execution.
8. Correlator uncertainty
Section titled “8. Correlator uncertainty”In the correlator example, accepted trials give and . Compute and its estimated standard error under the independent, identically distributed fixed-size sampling model.
Solution
The estimator is
Therefore
This quantifies sampling fluctuation under the stated model, not readout, compilation, or drift bias.
9. A symmetric observable hides a swapped mapping
Section titled “9. A symmetric observable hides a swapped mapping”The intended two-qubit output is , but the reported labels are interchanged. Compare the original and reported and . Which detects the error?
Solution
Both and have parity , so the correlator is unchanged. The first-qubit expectation changes from to . A parity-only check cannot detect this permutation; the asymmetric observable can.
10. Conditioning amplifies an unconditional difference
Section titled “10. Conditioning amplifies an unconditional difference”Two classical output distributions over are and for . Compute their total-variation distance before and after acceptance.
Solution
Before selection, half the sum of absolute differences is . After selection the output is certainly 0 in the first case and certainly 1 in the second, so the distance is 1. Arbitrarily small unconditional error can coexist with completely different rare accepted outputs. Retaining the acceptance flag avoids confusing these two questions.
References
Section titled “References”- F. T. Chong, D. Franklin, and M. Martonosi, “Programming languages and compiler design for realistic quantum hardware,” Nature 549, 180–187 (2017), doi:10.1038/nature23459.
- A. D. Córcoles et al., “Exploiting dynamic quantum circuits in a quantum algorithm with superconducting qubits,” Physical Review Letters 127, 100501 (2021), doi:10.1103/PhysRevLett.127.100501; arXiv:2102.01682.
- A. W. Cross et al., “OpenQASM 3: A broader and deeper quantum assembly language,” ACM Transactions on Quantum Computing 3, Article 12 (2022), doi:10.1145/3505636; arXiv:2104.14722.
- T. Häner, D. S. Steiger, K. Svore, and M. Troyer, “A software methodology for compiling quantum programs,” Quantum Science and Technology 3, 020501 (2018), doi:10.1088/2058-9565/aaa5cc.
- K. Hietala, R. Rand, S.-H. Hung, X. Wu, and M. Hicks, “A verified optimizer for quantum circuits,” Proceedings of the ACM on Programming Languages 5, Article 37 (2021), doi:10.1145/3434318; arXiv:1912.02250.
- P. Murali, J. M. Baker, A. Javadi-Abhari, F. T. Chong, and M. Martonosi, “Noise-adaptive compiler mappings for noisy intermediate-scale quantum computers,” in Proceedings of ASPLOS 2019, 1015–1029 (2019), doi:10.1145/3297858.3304075.
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed. (Cambridge University Press, 2010), doi:10.1017/CBO9780511976667.
- J. Watrous, The Theory of Quantum Information (Cambridge University Press, 2018), Chapter 3, author’s manuscript.