Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Quantum intermediate representation

A versioned intermediate program representation connecting quantum-language front ends with target-specific compilation.

Also called QIR

Edition released Coverage: Overview · Technical
On this page

Definition, purpose and input assumptions

QIR describes quantum programs within an LLVM-based intermediate representation. It helps separate source-language syntax from target-specific execution details. This entry explains quantum software concepts; it does not prescribe infrastructure for the Learn website. A shared representation does not guarantee that every target supports every program feature.

Mathematical mechanism

The representation can include quantum instruction calls, classical control and runtime interfaces. Profiles identify supported subsets. A front end may express a measurement-conditioned operation in the intermediate program, while a backend must determine whether the target can implement the required feed-forward and timing.

A QIR version and an LLVM version are separate compatibility facts. Any executable example must pin both applicable tooling and the supported profile rather than treating a mutable specification as a tested runtime.

Fully solved reference example

Consider the abstract program: prepare |+>, measure Z to obtain bit m, and apply X to a fresh zero qubit if m=1. Its ideal output record and target state are(0,|0>) or(1,|1>), each with probability 1/2. A representation that retains the conditional branch can express this behavior.

If a backend drops the branch and always leaves the target zero, the final joint distribution changes: record 1,target 1 disappears. Matching the marginal record distribution alone would fail to detect the semantic error. This complete example specifies what an intermediate representation and backend must preserve.

Limitations and classical comparison

Compilation interoperability is conditional on profiles, instruction semantics and target capabilities. It is not evidence that a provider implements every runtime function or gate natively. A format-valid program can still be unsupported or physically expensive.

Scientific relationships

QIR is used in quantum circuit compilation and connects languages such as Q# to target-specific tools. It differs from a scientific algorithm and from a guarantee of cross-provider hardware support.

A branch-sensitive intermediate-program example

Consider a program that initializes q and t to zero, applies RY(pi/3) to q, measures q into m, then applies RY(pi/3) to t when m is zero or RY(2pi/3) when m is one. It finally measures t into n and returns the ordered pair (m,n). This describes the source-level semantics that an intermediate representation and its lowering must preserve; it is not an LLVM or QIR syntax fragment claiming a particular toolchain version.

The first outcome has probabilities P(m = 0) = 3/4 and P(m = 1) = 1/4. Conditional on m = 0, the target has P(n = 1) = 1/4; conditional on m = 1, that probability is 3/4. The complete joint distribution in order 00,01,10,11 is therefore (9/16, 3/16, 1/16, 3/16). Its marginals are P(m = 1) = 1/4 and P(n = 1) = 3/8, and the covariance of the two zero-one outcomes is 3/32.

Preserving only either marginal would be insufficient. A lowering could return the correct frequencies for m and n while destroying their correlation. The output tuple's order and the measurement-record identities are consequently part of the semantic contract, alongside gate angles and qubit allocation. The exact joint probabilities provide a small complete reference for checking a branch-preserving compilation.

A valid transformation and an invalid averaging shortcut

Because both target operations rotate about Y, the program can first apply RY(pi/3) to t on every path, then apply an additional RY(pi/3) only when m is one. This moves a common operation outside the branch while preserving the conditional target state. The transformation relies on the specific rotation algebra and the fact that no target measurement or conflicting operation intervenes.

Replacing both branches by one rotation at the probability-weighted mean angle, 5pi/12, is not equivalent. The original target ensemble has Bloch vector (sqrt(3)/2, 0, 1/4) and purity 29/32. A single ideal rotation of a zero qubit produces a pure state with purity one. Its one probability may happen to be numerically close to the mixture's value, but the state and joint record correlations differ. Classical averaging of program parameters is not a general semantics-preserving transformation for quantum mixtures.

Classical values and quantum references have different effects

An intermediate program may represent a branch condition as an immutable classical value and merge selected classical results at a join. A quantum handle, however, refers to a subsystem whose state changes under quantum instruction calls. Copying the handle's machine-level representation does not clone the subsystem. Analyses that reorder, remove, or combine calls must respect aliasing and quantum side effects rather than treating them as pure numerical functions returning independent values.

For example, two adjacent X operations on the same qubit cancel ideally, but that rewrite requires knowing they address the same logical subsystem and that no intervening operation changes the context. Conversely, two identical-looking operations on different handles cannot be merged merely because their instruction names and parameters match. Measurements introduce classical records and state updates, so eliminating a call may remove information later used in control flow even if a final marginal appears unchanged.

Profiles and version compatibility

The official QIR specification describes an LLVM-based interface between language-specific compilation and target-specific lowering. Profiles restrict the functionality a target is expected to support. A program using mid-circuit measurement and outcome-dependent gates requires the relevant adaptive behavior; a format capable of expressing it does not make every backend able to execute it. Instruction availability, runtime interfaces, and target capabilities must be checked together.

The live specification accessed on 2026-12-03 distinguishes QIR versions and LLVM compatibility, including the move to opaque pointers in QIR 2.0. This entry does not claim an executed QIR/LLVM pair or pin a mutable repository commit. The worked calculation is deliberately semantic, so its mathematical validity does not depend on importing an untested instruction signature. An executable artifact would additionally need a concrete specification revision, LLVM contract, profile, and backend implementation; none is inferred from the conceptual example.

Costs retained through lowering

An intermediate representation can expose control flow and operations needed for resource analysis, but target lowering determines how abstract operations become native gates, measurements, resets, and delays. A conditional rotation may require classical feed-forward latency. Logical qubit count differs from a physical allocation after ancilla insertion or error correction. These costs should remain traceable to program operations rather than being erased by a claim of language interoperability.

For the two-qubit reference, classical density matrices and the four-entry probability table are complete alternatives for verifying ideal behavior. They do not test a backend's timing or instruction support. The distinction allows a reader to assess the scientific semantics separately from the implementation compatibility of any later code artifact.

Sources

  • QIR Alliance · Documentation · github.com
    Verification scope

    Recorded source check ·

    Official specification content retrieved, including compilation model, profiles and QIR/LLVM version distinctions.

    The control-flow example explains language-independent semantics. Its scope excludes compiler, profile, parser and backend execution.