Q-Bridge

OpenQASM 2 vs OpenQASM 3: The Differences You Hit First

The practical differences between OpenQASM 2 and OpenQASM 3: register declarations, measurement syntax, includes, classical control and timing. Side-by-side examples, plus what Q-Bridge's circuit analyzer does and does not read.

Two versions of the same idea

OpenQASM is a plain-text language for writing quantum circuits. Version two, often written 2.0, is the one most older tutorials and exported circuits use. Version three, written 3.0, is a larger language that keeps the same core idea (declare qubits, apply gates, measure) and extends it with classical programming features. If you move circuits between tools you will meet both, so it helps to recognize them at a glance.

The same circuit in both

Here is a two-qubit circuit that prepares an entangled pair and measures it, first in version two:

```

OPENQASM 2.0;

include "qelib1.inc";

qreg q[2];

creg c[2];

h q[0];

cx q[0], q[1];

measure q[0] -> c[0];

measure q[1] -> c[1];

```

and in version three:

```

OPENQASM 3.0;

include "stdgates.inc";

qubit[2] q;

bit[2] c;

h q[0];

cx q[0], q[1];

c[0] = measure q[0];

c[1] = measure q[1];

```

The gates are identical. Everything that differs is bookkeeping around them.

The differences you hit first

  • Header. `OPENQASM 2.0;` becomes `OPENQASM 3.0;`.
  • Include file. Version two circuits usually include `qelib1.inc` for the standard gates. Version three uses `stdgates.inc`.
  • Quantum registers. `qreg q[2];` becomes `qubit[2] q;`. The size moves from the end of the name to the type.
  • Classical registers. `creg c[2];` becomes `bit[2] c;`.
  • Measurement. Version two writes an arrow, `measure q[0] -> c[0];`, where the result flows into the classical bit. Version three writes an assignment, `c[0] = measure q[0];`, because measurement is now an expression whose value you store.

For circuits that only use standard gates, those five changes are most of what a manual conversion involves.

Classical control

Version two does have a conditional, but it is narrow: a single gate can run only if a whole classical register equals a given integer. There are no loops, no branching blocks and no way to name a reusable routine beyond gate definitions.

Version three opens this up. It adds ordinary `if` and `else` blocks, `for` and `while` loops, subroutines, and classical types such as integers and floating-point numbers. That is what lets a circuit decide what to do next based on a mid-circuit measurement, which is the foundation of many error-correction and feedback protocols.

Timing and other additions

Beyond control flow, version three introduces constructs that have no counterpart in version two:

  • Timing. Delays and durations, so a circuit can say how long an idle period lasts.
  • Gate modifiers. Controlled and inverse forms of an existing gate, written as a prefix on the gate call.
  • Pulse-level hooks. A way to attach low-level pulse definitions to a gate for a particular device.

Treat this list as a map of where the language went, not a promise about any one tool. Support for these features is uneven across simulators, compilers and devices, and a circuit that uses them may only load in tools built for version three.

Which should you write?

If your circuit is a fixed sequence of standard gates and measurements, either version expresses it, and the choice mostly comes down to what your downstream tools accept. Use version two when you need to hand a circuit to older tooling. Use version three when you need mid-circuit decisions, loops or timing, or when the tools you work with have moved to it. If you maintain circuits in both, keep the standard-gate core identical and keep the version-specific parts to the header, registers and measurements, so conversion stays mechanical.

Reading both in Q-Bridge

Q-Bridge is a web dashboard for writing OpenQASM circuits, running them and keeping the resulting jobs. Its circuit analyzer reads the text of a circuit and reports gate count, depth, qubit count, a per-gate breakdown, two-qubit gate count, the number of measurements and which qubit pairs interact.

For the topic of this page, the relevant detail is that the analyzer recognizes both register styles, `qreg` and `qubit[n]`, and both measurement syntaxes, the arrow form and the assignment form. You can paste either version of the example above and get the same reading.

Its limits matter as much as its coverage. The analyzer is a deterministic text parse that runs in your browser, not a compiler pass. Classical control is ignored, so a branch or loop does not change the counts it reports. A custom gate definition counts as one operation rather than being expanded. It does not estimate execution time. This page does not claim that Q-Bridge executes every version three feature; the analyzer is a reader of the syntax described here.

The analyzer sits inside the dashboard, which requires an account. To see what the numbers mean, read circuit depth and gate count. To run a circuit once you have read it, see running OpenQASM in the browser, and for what the counts mean afterwards, see what shots are. Plan limits are on the pricing page, and you can create an account on the Free plan.

A conversion checklist

When you move a standard-gate circuit from version two to version three, work through the same steps each time: change the header, switch the include file, rewrite each register declaration, rewrite each measurement, then run the result through a reader such as the analyzer and confirm the gate count and qubit count match the original. If the counts differ, a declaration or measurement was missed.

Create a Q-Bridge account, paste a circuit written in either version into the circuit analyzer, and compare its gate count, depth and two-qubit gate count.

Get started