Quantum Circuit DSL Reference

The authoritative reference for the circuit text accepted by the AutomationGlance simulation API.

Documentation version: 2.0 · Compatible with: current AutomationGlance simulator · Last reviewed: 2026-10-05

Declaration and line structure

Declare qubits N with an integer N from 1 to 8 for execution. Use one statement per line. Blank lines and lines whose first non-whitespace character is # are ignored. Inline comments and semicolon-separated statements are not supported. Commands and gate names are case-insensitive. Leading/trailing whitespace and repeated spaces or tabs between tokens are accepted.

The declaration is required, but the parser does not require it to be first. Put it first to make bounds checks clear. Repeated declarations produce qubits_redeclared warnings; the last value sets execution width. Gates are checked against the declaration in effect on their line and again against the final width at execution. CR and LF are each split by the parser, so reported line numbers for CRLF input can differ from editor line numbers. Prefer LF.

Supported gates

Public DSL gate signatures (qubits before angles)
SyntaxMeaning
H i, X i, Y i, Z iHadamard and Pauli gates
S i, T iPhase gates diag(1,i) and diag(1,exp(iπ/4))
RX i angle, RY i angle, RZ i angleexp(−i angle P/2), for P = X, Y, Z
U3 i theta phi lambdaMatrix rows: [cos(θ/2), −exp(iλ)sin(θ/2)] and [exp(iφ)sin(θ/2), exp(i(φ+λ))cos(θ/2)]
CX c t or CNOT c tControlled X; control first, target second
CZ c tControlled Z

Gate indices are zero-based integers in [0,N−1]. Gate operands also accept a q prefix, such as H q0. Parenthesized, comma-separated gate calls such as RX(0,1.5707963267948966) and CNOT(q0,q1) are accepted. This is qubit-first DSL syntax, unlike OpenQASM. Empty comma entries are ignored by the backend parser; avoid them because the browser exporter rejects them. Control and target must be distinct; equal indices are rejected with gate_qubits_distinct.

Numbers and angles

Angles are radians, parsed with invariant decimal notation: integers, signed decimals, leading decimal points, and scientific notation (for example -1.25e-2). Use numeric values for π; expressions such as pi/2, fractions, degree suffixes and decimal commas are unsupported. Qubit counts and indices use signed 32-bit integer parsing; positive signs and leading zeros are accepted, but fractional and negative indices are invalid. Nonfinite values such as NaN, Infinity and overflowing exponents are rejected with gate_parameter_invalid.

Measurement is terminal sampling

MEASURE i takes one integer index; it does not accept q0 or parentheses. Measurements are collected in source order and performed after all unitary gates, even if written earlier. There is no mid-circuit collapse, classical control, reset or conditional feedback. Repeated measurement indices repeat the same sampled bit. With no MEASURE statements, the response has an empty counts object but still includes the full statevector and probabilities.

State labels use q0 at the left (the most significant statevector index bit). Counts contain only the measured bits in declaration order: preparing q0=1,q1=0 and measuring 1 then 0 returns 01; the full state is 10.

Working examples

Bell pair

qubits 2
H 0
CX 0 1
MEASURE 0
MEASURE 1

Full-state probabilities are ½ for 00 and 11. Sampled counts fluctuate with shots and seed.

Parameterized and alternate gate notation

# Angles are radians
qubits 2
ry(q0,1.5707963267948966)
RZ 0 -1.25e-2
U3 1 0.5 0 1e-1
CZ 0 1
MEASURE 1
MEASURE 0

Validation and unsupported syntax

Unknown gates, wrong arity, missing declarations and invalid indices yield parse errors and HTTP 422; errors include a code and, where available, a line. Width above 8 is rejected at execution with HTTP 422. See API request limits and error formats. The editor's local analysis is advisory; the API validates execution. No auto-expansion of undeclared registers occurs.

H 0
qubits 2
SWAP 0 1
qubits 2
MEASURE q0
qubits 2
RX 0 pi/2
qubits 2
H 2

The older qubit q0 declaration, named registers, SWAP, CY, CCX, custom gate definitions, OpenQASM source, loops and conditions are unsupported. SWAP can be decomposed into three CX operations on distinct qubits; it is not a public DSL instruction.

Reproducibility

The DSL has no shots or seed statements. Those are API fields. A supplied signed 32-bit seed controls sampling; otherwise the simulator API hashes the exact circuit text and shots. Whitespace changes can therefore change the default counts without changing probabilities. Reproducibility assumes the same backend/runtime version. See OpenQASM export limitations.