packages feed

symplectic-chp-0.1.0.0: data/stim-circuits/unsupported-rx.derive.md

# Unsupported RX Gate: Error Handling Test

## Circuit Specification

```
RX 0
M 0
```

## Objective

Verify that the CHP simulator correctly rejects non-Clifford gates with a clear error message.

---

## The RX Gate

### Definition

The RX gate is a rotation around the X-axis by angle $\theta$:

$$R_X(\theta) = e^{-i\theta X/2} = \cos\frac{\theta}{2} I - i\sin\frac{\theta}{2} X$$

### Matrix Form

$$R_X(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}$$

---

## Clifford vs. Non-Clifford

### Clifford Group Definition

The Clifford group $\mathcal{C}_n$ consists of unitaries that:
1. Map Pauli group to itself under conjugation: $U P U^\dagger \in \mathcal{P}_n$ for all $P \in \mathcal{P}_n$
2. Can be generated by $\{H, S, \text{CNOT}\}$

### Testing if RX is Clifford

For RX to be Clifford, it must map Pauli operators to Pauli operators.

**Test on Z:**
$$R_X(\theta) Z R_X(-\theta) = \begin{pmatrix} \cos\theta & -i\sin\theta \\ i\sin\theta & -\cos\theta \end{pmatrix}$$

For this to be a Pauli matrix ($\pm X, \pm Y, \pm Z$), we need:
- $\sin\theta = 0$ AND $\cos\theta = \pm 1$ → $\theta \in \{0, \pi, 2\pi, ...\}$
- OR $\cos\theta = 0$ AND $\sin\theta = \pm 1$ → $\theta \in \{\pi/2, 3\pi/2, ...\}$

### Clifford Cases

| $\theta$ | $R_X(\theta)$ | Clifford? |
|-----------|---------------|-----------|
| 0 | $I$ | Yes |
| $\pi/2$ | $\sqrt{X}$ | Yes (if global phase ignored) |
| $\pi$ | $X$ | Yes |
| $3\pi/2$ | $\sqrt{X}^\dagger$ | Yes |
| Generic $\theta$ | — | **No** |

**Conclusion:** Generic $R_X(\theta)$ is **not** a Clifford gate.

---

## Why Non-Clifford Gates Break CHP

### CHP Algorithm Requirements

The CHP simulator uses the **stabilizer formalism**:
- States represented by stabilizer generators
- Evolution via conjugation: $g \rightarrow U g U^\dagger$
- Measurements via symplectic inner product

### The Problem with RX

For non-Clifford $U$:
$$U X U^\dagger \notin \{\pm X, \pm Y, \pm Z\}$$

The result is a **superposition of Pauli operators**:
$$R_X(\theta) Y R_X(-\theta) = \cos\theta \, Y + \sin\theta \, Z$$

This cannot be represented efficiently in the stabilizer formalism.

### Gottesman-Knill Theorem

The theorem states that circuits consisting of:
- Clifford gates (H, S, CNOT)
- Computational basis measurements
- Classical control

Can be simulated efficiently classically.

**Corollary:** Adding non-Clifford gates (like T or RX) enables universal quantum computation, which cannot be efficiently simulated (assuming standard complexity conjectures).

---

## Expected Behavior

### Translation Phase

The STIM-to-CHP translator should:
1. Parse the RX gate from STIM syntax
2. Check against supported gate list
3. Detect unsupported Clifford gate
4. Generate clear error message

### Expected Error Message

```
Translation error: Unsupported gate: RX
This gate is not a Clifford gate or is not yet implemented.
```

### Simulator Response

| Phase | Expected Behavior |
|-------|-------------------|
| Parse | Successfully parse STIM syntax |
| Translate | Detect unsupported gate, return error |
| Simulation | **Not executed** |
| Exit Code | Non-zero (failure) |

---

## Expected Outcome

| Property | Expected Value |
|----------|---------------|
| **Parse Status** | Success |
| **Translation Status** | Failure (expected) |
| **Error Type** | `UnsupportedGate RX` |
| **Simulation** | Not performed |
| **Test Result** | PASS (error caught as expected) |

**Key Insight:** This test verifies the simulator's error handling capability rather than its simulation capability.

**Safety:** Correct rejection of unsupported gates prevents silent production of incorrect results.