OpenQASM 3 cheat sheet
The code panel accepts OpenQASM 3 (and OpenQASM 2). These are the statements the composer can also draw.
OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; // quantum register bit[3] c; // classical register h q[0]; // single-qubit gate rx(pi/2) q[1]; // gate with a parameter cx q[0], q[1]; // control, target ccx q[0], q[1], q[2]; barrier q; c[0] = measure q[0]; c = measure q; // measure every qubit
| Statement | Meaning |
|---|---|
| qubit[n] q; | Declare n qubits named q[0] … q[n−1] |
| bit[n] c; | Declare n classical bits |
| g q[i]; | Apply gate g to qubit i |
| g(θ) q[i]; | Parameterized gate |
| cx q[c], q[t]; | Controlled gate: control first, target last (also cy, cz, ch, cp, crx, cry, crz, cu, ccx, cswap) |
| U(θ, φ, λ) q[i]; | The built-in general single-qubit rotation |
| c[j] = measure q[i]; | Measure qubit i into bit j |
| barrier q; | Keep the transpiler from reordering across this point |
| reset q[i]; | Return qubit i to |0⟩ |
if/else, while, for, switch and break/continue are drawn as frames (see the Dynamic circuits chapter). Custom gate definitions are valid OpenQASM 3 and still run, but the composer shows them as code-only.
Editing in the composer
| Action | How |
|---|---|
| Select several gates | Shift/Ctrl+click · drag a box on empty wire · Ctrl+A |
| Move the selection | Drag any selected gate, or arrow keys ↑ ↓ ← → |
| Copy · cut · paste · duplicate | Ctrl+C · Ctrl+X · Ctrl+V · Ctrl+D (Cmd on Mac; pasted QASM lines from anywhere work too) |
| Group into an if block · ungroup | Ctrl+G · Ctrl+Shift+G (or Unwrap in the inspector) |
| Delete · undo · redo | Delete / Backspace · Ctrl+Z · Ctrl+Y or Ctrl+Shift+Z |
| Change a rotation angle smoothly | Select the gate and drag the angle slider; it snaps to fractions of pi |
| Jump to the code | Double-click a gate or a block tag |