OpenQASM (Open Quantum Assembly Language, often shortened to QASM) is an open, human-readable language for describing quantum circuits: it declares qubits and classical bits, applies gates, performs measurements and, in its third version, mixes in real-time classical control and timing. In quantum software it plays the role of a common interchange format between SDKs, compilers, simulators and cloud services, so a circuit built in one tool can be executed or optimized in another.
The language sits at a deliberately low level of abstraction. It is not meant to express algorithms elegantly, as a high-level quantum programming language would, but to state precisely which operations run on which qubits in which order. That precision is why it has become the de facto text representation for circuits across much of the quantum computing ecosystem.
How an OpenQASM program describes a circuit
An OpenQASM program is a sequence of statements that a parser turns into a circuit or a richer intermediate representation. A typical program starts with a version header such as OPENQASM 3.0;, includes a standard gate library, declares registers, applies gates and ends with measurements that write results into classical bits.
The language defines only a tiny set of built-in primitives. In version 2.0 these are the general single-qubit rotation U(theta, phi, lambda) and the controlled-NOT CX; every other gate, from Hadamard to Toffoli, is defined in terms of these primitives in an include file. Version 3.0 keeps U and adds a global phase primitive, while the familiar gates live in stdgates.inc. This design makes the semantics of every gate unambiguous, because each one reduces to a known matrix.
The core building blocks are summarized below, with the syntax that differs between the two major versions.
| Element | OpenQASM 2.0 form | OpenQASM 3.0 form | Purpose |
|---|---|---|---|
| Qubit declaration | qreg q[2]; | qubit[2] q; | Allocates quantum registers |
| Classical bits | creg c[2]; | bit[2] c; | Stores measurement outcomes |
| Gate library | include "qelib1.inc"; | include "stdgates.inc"; | Imports standard gate definitions |
| Gate application | h q[0]; cx q[0],q[1]; | h q[0]; cx q[0], q[1]; | Applies operations to qubits |
| Measurement | measure q -> c; | c = measure q; | Collapses qubits into bits |
| Custom gate | gate name a,b { ... } | gate name a, b { ... } | Defines reusable unitary blocks |
Statements such as barrier and reset complete the picture. A barrier prevents compilers from moving operations across a boundary, and reset returns a qubit to the zero state, which matters for mid-circuit qubit reuse.
What changed from OpenQASM 2.0 to OpenQASM 3.0
OpenQASM 2.0, released in 2017 alongside early public cloud access to superconducting processors, describes static circuits: a fixed list of gates followed by measurements, with only a primitive conditional that compares a whole classical register to an integer. OpenQASM 3.0, specified from 2021 under an open technical steering committee, turned the format into a real-time quantum-classical language.
The new version reflects what modern hardware can do between gates: measure a qubit, compute on the result in the control electronics and branch within the qubit coherence time. The main additions are listed here.
| Capability | What it adds | Typical use |
|---|---|---|
| Classical types | int, uint, float, bool, angle, complex | Arithmetic on measurement results |
| Control flow | if, else, for, while loops | Adaptive and repeat-until-success circuits |
| Subroutines and extern | Classical functions callable at run time | Decoding and feedback logic |
| Timing | delay, duration and stretch types | Dynamical decoupling, precise scheduling |
| Gate modifiers | ctrl, negctrl, inv and pow | Building controlled or inverse gates |
| Calibrations | defcal blocks with OpenPulse grammar | Pulse-level control of gates |
OpenQASM 3.0 is largely backward compatible: most 2.0 programs parse with minor edits, such as replacing the old include file. However, many backends support only a subset of 3.0 features, so a syntactically valid program can still be rejected by a particular device.
OpenQASM among other circuit representations
OpenQASM is one of several intermediate formats in quantum software, and each serves a different layer of the stack. Its closest neighbors are Quil, used historically by Rigetti, and QIR, an LLVM-based representation promoted for compiled hybrid programs. High-level languages such as Q# and Python SDKs such as Qiskit or Cirq sit above these formats and often emit OpenQASM as output.
| Representation | Abstraction level | Main strength | Main limitation |
|---|---|---|---|
| OpenQASM 3.0 | Assembly with control flow | Broad tool and cloud support | Uneven feature support by backend |
| Quil | Assembly with shared memory model | Explicit classical memory semantics | Smaller ecosystem |
| QIR | LLVM intermediate representation | Integration with classical compilers | Hard for humans to read |
| Python SDK objects | In-memory circuit data structures | Rich programming environment | Tied to one framework |
The practical consequence is that OpenQASM serves best as a portable, inspectable text layer. It is easy to read in code review, store in version control and send through a cloud API, while QIR targets deeper compiler integration.
Using OpenQASM in practice
Most developers rarely write long OpenQASM programs by hand. Instead, they export and import circuits through SDK functions, for example the dedicated qasm2 and qasm3 modules in Qiskit, OpenQASM import in Cirq or conversion utilities for TKET. Cloud services such as Amazon Braket accept OpenQASM 3.0 as a submission format, which makes the language a contract between client code and hardware providers.
The right workflow depends on the goal, as the following decision table shows.
| Situation | Recommended approach | Reason |
|---|---|---|
| Moving circuits between SDKs | Export and import OpenQASM 2.0 or 3.0 | Neutral format both tools understand |
| Archiving benchmark circuits | Store OpenQASM text files | Readable, diffable, tool independent |
| Mid-circuit feedback experiments | Write or generate OpenQASM 3.0 | Native if and while semantics |
| Pulse calibration research | Use defcal with OpenPulse | Ties gates to physical waveforms |
| Algorithm prototyping | Use a high-level SDK instead | Assembly detail slows iteration |
When generating code programmatically, it pays to pin the language version and validate output with a reference parser before submission. Doing so catches unsupported constructs early rather than at the queue of a remote device.
Limitations and common mistakes
OpenQASM specifies what a program means, but not what every machine can execute. A logical circuit still has to pass through transpilation and qubit routing to match the native gate set and connectivity of a device, and that step can change gate counts substantially. Frequent pitfalls include the following.
- Mixing version syntax, such as using
qregdeclarations together with 3.0 measurement assignment, which strict parsers reject. - Assuming identical gate definitions across include files; the global phase of some gates differs between libraries, which matters inside controlled operations.
- Relying on unsupported features, for example while loops or extern calls, on backends that execute only static circuits.
- Confusing qubit indices after transpilation, because physical qubits in compiled output rarely match the virtual order of the source.
- Treating OpenQASM as an optimizer; the language records operations faithfully and performs no simplification by itself.
Despite these limits, the open specification and wide interoperability keep OpenQASM central to quantum software, especially as dynamic circuits become standard on current hardware.
In everyday language
OpenQASM is like sheet music for a quantum computer. A composer can write a melody in many different apps, but sheet music lets any trained musician play it. In the same way, people build quantum programs in many different tools, and OpenQASM writes the result down in a shared, readable form.
Each line says something simple: prepare these qubits, apply this operation, measure that one. The newer version also allows decisions along the way, such as doing one thing if a measurement shows zero and another if it shows one. The key point is that OpenQASM does not make programs smarter; it makes them portable and precise.
Seen in the real world
A university research group studies error mitigation on a 12-qubit benchmark circuit. The team designs the circuit in one Python SDK, but wants to compare results from a superconducting processor and a trapped-ion system offered through two different cloud services. Rewriting the circuit for each provider would introduce errors and waste time.
Instead, the researchers export the circuit as OpenQASM 3.0, store the file in their repository and submit it to both services, each of which compiles it to its own native gates. When a later experiment needs a mid-circuit measurement followed by a conditional correction, they add an if statement to the same file. The outcome is a single reviewable source of truth for every run, which makes the published comparison reproducible by other groups.