Skip to main content
Single-qubit gates act on one Wire at a time. Every gate function in this reference is imported directly from b01t and can be called inside any decorated program body. Which gates are available depends on context: exact programs (@coherent, @primitive) reject parametric rotations, while broad programs (@parametric, @adaptive) accept all gates listed here. Calling a gate outside a decorated build context raises DSLValidationError.

Gate overview

GateOperationExact contextCompute blockPhase block
xPauli-X (bit flip)YesYesNo
hHadamardYesNoNo
zPauli-Z (phase flip)YesNoYes
sS gate (√Z)YesNoYes
sdgS-dagger (S†)YesNoYes
tT gate (√S, π/8 rotation)YesNoYes
tdgT-dagger (T†)YesNoYes
rxX-rotation by angle θNoNoNo
ryY-rotation by angle θNoNoNo
rzZ-rotation by angle θNoNoYes*
* rz is allowed in broad-path phase blocks (@parametric) but is not in the exact gate set and cannot be used in @coherent or @primitive programs.

x

from b01t import x
x(q: Wire) -> None
Pauli-X gate. Flips |0⟩ to |1⟩ and |1⟩ to |0⟩. This is the quantum analogue of a classical NOT gate. x is self-inverse: x(x(q)) = I. Allowed in: exact programs, compute blocks, phase blocks (no), top-level broad programs.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, x

@coherent
def flip(sys: QReg) -> None:
    x(sys[0])

prog = flip.build_exact(("sys", 1))

h

from b01t import h
h(q: Wire) -> None
Hadamard gate. Maps |0⟩ to (|0⟩ + |1⟩)/√2 and |1⟩ to (|0⟩ − |1⟩)/√2, creating an equal superposition. h is self-inverse. Allowed in: exact programs (top-level), top-level broad programs. Not allowed in compute or phase blocks — it is neither a permutation gate nor a diagonal gate.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, h, cx

@coherent
def bell_pair(a: QReg, b: QReg) -> None:
    h(a[0])
    cx(a[0], b[0])

prog = bell_pair.build_exact(("a", 1), ("b", 1))

z

from b01t import z
z(q: Wire) -> None
Pauli-Z gate. Leaves |0⟩ unchanged and maps |1⟩ to −|1⟩. z is self-inverse and is a diagonal gate. Allowed in: exact programs, phase blocks.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, h, z, cx
from b01t import ancilla, compute, phase, uncompute

@coherent
def phase_flip(sys: QReg) -> None:
    with ancilla(1) as anc:
        compute(lambda: cx(sys[0], anc[0]))
        phase(lambda: z(anc[0]))
        uncompute()

prog = phase_flip.build_exact(("sys", 1))

s

from b01t import s
s(q: Wire) -> None
S gate (phase gate). Applies a π/2 phase to |1⟩, equivalent to √Z. s and sdg are inverses of each other. Allowed in: exact programs, phase blocks.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, h, s

@coherent
def hs(q: QReg) -> None:
    h(q[0])
    s(q[0])

prog = hs.build_exact(("q", 1))

sdg

from b01t import sdg
sdg(q: Wire) -> None
S-dagger gate (S†). The inverse of s. Applies a −π/2 phase to |1⟩. Allowed in: exact programs, phase blocks.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, s, sdg

@coherent
def cancel(q: QReg) -> None:
    s(q[0])
    sdg(q[0])  # s followed by sdg = identity

prog = cancel.build_exact(("q", 1))

t

from b01t import t
t(q: Wire) -> None
T gate (π/8 gate). Applies a π/4 phase to |1⟩, equivalent to √S. Together with h and cx, the T gate generates a universal gate set. t and tdg are inverses. Allowed in: exact programs, phase blocks.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, h, t, cx

@coherent
def t_layer(q: QReg) -> None:
    h(q[0])
    t(q[0])
    h(q[0])

prog = t_layer.build_exact(("q", 1))

tdg

from b01t import tdg
tdg(q: Wire) -> None
T-dagger gate (T†). The inverse of t. Applies a −π/4 phase to |1⟩. Allowed in: exact programs, phase blocks.
q
Wire
required
The target qubit wire.
from b01t import coherent, QReg, t, tdg

@coherent
def cancel_t(q: QReg) -> None:
    t(q[0])
    tdg(q[0])  # identity

prog = cancel_t.build_exact(("q", 1))

rx

from b01t import rx
rx(theta: float, q: Wire) -> None
Rotation about the X axis by angle theta (in radians). Parametric — not in the exact gate set. Allowed in: @parametric and @adaptive programs only. Raises DSLValidationError inside @coherent or @primitive.
theta
float
required
Rotation angle in radians.
q
Wire
required
The target qubit wire.
from b01t import parametric, QReg, rx
import math

@parametric
def x_rot(q: QReg) -> None:
    rx(math.pi / 3, q[0])

prog = x_rot.build(("q", 1))

ry

from b01t import ry
ry(theta: float, q: Wire) -> None
Rotation about the Y axis by angle theta (in radians). Parametric — not in the exact gate set. Allowed in: @parametric and @adaptive programs only.
theta
float
required
Rotation angle in radians.
q
Wire
required
The target qubit wire.
from b01t import parametric, QReg, ry
import math

@parametric
def grover_diffuser(q: QReg) -> None:
    ry(math.pi / 4, q[0])

prog = grover_diffuser.build(("q", 1))

rz

from b01t import rz
rz(theta: float, q: Wire) -> None
Rotation about the Z axis by angle theta (in radians). Parametric — not in the exact gate set. rz is a diagonal gate and is allowed in broad-path phase blocks inside @parametric programs. Allowed in: @parametric and @adaptive programs; allowed in broad-path phase blocks. Raises DSLValidationError inside @coherent or @primitive.
theta
float
required
Rotation angle in radians.
q
Wire
required
The target qubit wire.
from b01t import parametric, QReg, rz
import math

@parametric
def phase_rot(q: QReg) -> None:
    rz(math.pi / 8, q[0])

prog = phase_rot.build(("q", 1))