gate { } Blocks

Declare custom gates, sequences, or controlled unitaries. Blocks are preprocessed before the circuit is built.

Minimal matrix gate

gate MY_H {
  name: My Hadamard
  label: MH
  matrix: [1/sqrt(2) 1/sqrt(2); 1/sqrt(2) -1/sqrt(2)]
  color: purple
  qubits: 1
}

MY_H 0

Parametric header

gate U(theta, phi, lambda) {
  matrix: [cos(theta/2) -e**(1i*lambda)*sin(theta/2); e**(1i*phi)*sin(theta/2) e**(1i*(phi+lambda))*cos(theta/2)]
  qubits: 1
}

Sequence gate with wire placeholders

gate SWAPSEQ [a,b] {
  sequence: CX [a,b], CX [b,a], CX [a,b]
  encapsulate: true
  targets: 2
}

Controlled gate via targetmatrix

gate CX {
  targetmatrix: [0 1; 1 0]
  controls: 1..max
  targets: 1
}

Properties

PropertyDescription
matrix:Square unitary [row; row; …], up to 16×16. Cells use complex expressions: i, pi, e**(i*pi/4), sin/cos/tan, sqrt, **, {0} param refs. Rows separated by semicolons, entries by spaces.
targetmatrix:Controlled sub-unitary applied when all controls are |1⟩. Pair with controls: and targets:.
u:OpenQASM-style θ, φ, λ angles for a 2×2 U gate. Must agree with matrix: if both are set.
sequence:Comma-separated Qubi lines executed as the gate body, e.g. CX [a,b], CX [b,a], CX [a,b]. Use wire placeholders from the gate header.
controls:How many control wires: 1, 1..max, 1.2.7, or an expression list.
targets:How many target wires (same notation as controls:).
qubits:Total wire count when not using separate controls/targets.
label: / sidelabel:Tile text (max 4 chars). $swap, $GATE pull built-in symbols.
desc: / examples:Tooltip text and sample invocations for the gate info panel.
color: / font: / size:Palette and tile styling (color names or hex).
category: / subcategory:Palette grouping (Single, Multi, etc.).
encapsulate:true (default) - one tile on the diagram; false - expand sequence inline.
name:Human-readable gate name in the palette.
Unitary check: Matrices are verified at preprocess time. Non-unitary or non-power-of-two dimensions are rejected with a line number.