The playground runs OpenQASM 3.0, the third major version of the Open Quantum Assembly Language. This page documents the syntax constructs you can use, with examples drawn from the built-in example programs.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/itsubaki/qasm-playground/llms.txt
Use this file to discover all available pages before exploring further.
Version declaration
Every program must begin with a version declaration on the first non-comment line.Qubit declarations
Declare a register of qubits with a size, or a single named qubit without brackets.const int as the register size:
Reset
reset initializes one or more qubits to the |0⟩ state. Always reset qubits before use.
Built-in gate: U
U(theta, phi, lambda) is the universal single-qubit gate. All other gates are defined in terms of it.
Gate definitions
Define reusable gates with thegate keyword. The body expresses the gate in terms of U or other already-defined gates.
Controlled gates
Usectrl @ to add a control qubit to any gate. Use ctrl(n) @ to add n control qubits.
ccx) and a 4-controlled X gate:
Gate applications
Apply a gate by naming it followed by its qubit arguments. Use bracket notation to address individual qubits in a register.Measurement
measure collapses qubits and records outcomes. Measured qubits remain in the circuit; subsequent gates still apply.
Subroutine definitions
Usedef to define reusable subroutines. Parameters are typed with qubit or qubit[n].
Constants
Declare compile-time integer or float constants withconst.
Variables and expressions
Declare runtime integer variables and use arithmetic expressions:For loops
Iterate over an integer range withfor int:
Comments
Single-line comments start with//. There are no block comments.