> ## Documentation Index
> Fetch the complete documentation index at: https://b01t.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Single-Qubit Gates Reference

> Complete reference for all single-qubit gates in b01t: Pauli gates, Clifford gates, T gate, and parametric rotations with their allowed contexts.

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

| Gate  | Operation                 | Exact context | Compute block | Phase block |
| ----- | ------------------------- | :-----------: | :-----------: | :---------: |
| `x`   | Pauli-X (bit flip)        |      Yes      |      Yes      |      No     |
| `h`   | Hadamard                  |      Yes      |       No      |      No     |
| `z`   | Pauli-Z (phase flip)      |      Yes      |       No      |     Yes     |
| `s`   | S gate (√Z)               |      Yes      |       No      |     Yes     |
| `sdg` | S-dagger (S†)             |      Yes      |       No      |     Yes     |
| `t`   | T gate (√S, π/8 rotation) |      Yes      |       No      |     Yes     |
| `tdg` | T-dagger (T†)             |      Yes      |       No      |     Yes     |
| `rx`  | X-rotation by angle θ     |       No      |       No      |      No     |
| `ry`  | Y-rotation by angle θ     |       No      |       No      |      No     |
| `rz`  | Z-rotation by angle θ     |       No      |       No      |    Yes\*    |

\* `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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
from b01t import coherent, QReg, x

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

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

***

## h

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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`.

<ParamField path="theta" type="float" required>
  Rotation angle in radians.
</ParamField>

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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.

<ParamField path="theta" type="float" required>
  Rotation angle in radians.
</ParamField>

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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

```python theme={null}
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`.

<ParamField path="theta" type="float" required>
  Rotation angle in radians.
</ParamField>

<ParamField path="q" type="Wire" required>
  The target qubit wire.
</ParamField>

```python theme={null}
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))
```
