Declarations
Declaring is naming — it gives a label to a qubit, a classical bit, a list of qubits, or a gate pipeline so you can reference it later.
Comments
Lines starting with # are comments and are ignored by the compiler. Inline comments are supported too.
# This is a comment
q 0 -> H # inline comment
Qubit declaration
The standard way to declare a qubit uses the q keyword followed by an index:
alice : q 0
bob : q 1
This maps alice to qubit index 0 and bob to qubit index 1.
You can also give a qubit a custom register name for clarity:
alice : q ancilla 0
This maps to Qubit("ancilla", 0) in pytket instead of the default Qubit("q", 0).
The shorthand without q is also valid:
alice : 0
Classical bit declaration
Declare a classical bit (used to store measurement results) with the b keyword:
result : b 0
Custom register names are supported:
result : b outcomes 0
Classical bits are essential for conditional actions and classical bit operations.
Qubit reference without a name (q N)
You can refer to a qubit by its index directly in actions, lists, and gate arguments using the q prefix — no declaration needed:
q 0 -> H
q 0 -> CX(q 1)
This is identical to declaring alice : q 0 and then writing alice -> H or alice -> CX(bob).
Qubit list declaration
Group qubits together under one name:
pair : [alice, bob]
Mix named qubits with direct indices:
all3 : [alice, q 1, q 2]
Once declared, the list acts as a multi-qubit target in actions:
pair -> H # applies H to both alice and bob
Gate pipeline declaration
A pipeline is a named sequence of gates that can be applied to a qubit and also traversed in reverse:
bell_prep : H FCX(q 1)
Pipelines can reference named qubits as gate arguments:
alice : q 0
bob : q 1
entangle : H | FCX(bob)
Pipelines can also reference other pipelines by name:
diffuse_in : H | X
When used in an action, write diffuse_in <- to traverse it in reverse.
Using declared objects together
Named qubit in a gate argument
alice : q 0
bob : q 1
alice -> CX(bob)
Named qubit in an action
alice -> bell_prep
Named qubit added to a list
alice : q 0
group : [alice, q 1, q 2]
Named pipeline inside another pipeline
prep : H | S
expand : prep | X | prep <-