QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
  1. Docs
  2. OpenQASM 3 cheat sheet
Learn
  • Quantum basics
  • OpenQASM 3 cheat sheet
  • All gates, with the math
  • Every gate, interactive
  • Entanglement: how CNOT connects qubits
Circuits
  • Dynamic circuits: if/else, loops and conditions
Lessons
  • Learning path: from one qubit to algorithms
  • Quantum machine learning by hand
Run
  • Compile (transpile): levels, basis gates, topology
  • Simulators, noise, T1/T2 and fake backends
  • Python in the Playground
  • GitHub and git in the Playground
  • Articles and sharing
Analyze
  • Metrics: comparing distributions
  • Q-sphere and Bloch spheres
Hardware
  • Real IBM Quantum hardware
  • Device topology and calibration heat maps
  • Benchmark circuits: MQT Bench and QASMBench
Advanced
  • Circuit cutting, in depth
Story
  • The story of quantum computing
  • The Hamiltonian: where gates come from
  • What to expect next
Documentation/Learn/OpenQASM 3 cheat sheet

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
Comments use //. Angles accept pi, fractions such as pi/4 and decimals.
StatementMeaning
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

ActionHow
Select several gatesShift/Ctrl+click · drag a box on empty wire · Ctrl+A
Move the selectionDrag any selected gate, or arrow keys ↑ ↓ ← →
Copy · cut · paste · duplicateCtrl+C · Ctrl+X · Ctrl+V · Ctrl+D (Cmd on Mac; pasted QASM lines from anywhere work too)
Group into an if block · ungroupCtrl+G · Ctrl+Shift+G (or Unwrap in the inspector)
Delete · undo · redoDelete / Backspace · Ctrl+Z · Ctrl+Y or Ctrl+Shift+Z
Change a rotation angle smoothlySelect the gate and drag the angle slider; it snaps to fractions of pi
Jump to the codeDouble-click a gate or a block tag
← Previous
Quantum basics
Next →
All gates, with the math
On this page
  • Editing in the composer
Try it in the IDE →
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in