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

# program_text

> Conversion utilities between tsim shorthand and stim program text.

## `enriched_stim_error`

```python theme={null}
enriched_stim_error(exc: ValueError, converted_text: str) -> ValueError
```

Improve stim parse errors for tsim-specific gates.

When stim raises a 'Gate not found' error for a gate that should have been
converted by shorthand\_to\_stim, this searches the converted text for the
unconverted usage and returns a more helpful error message.

## `shorthand_to_stim`

```python theme={null}
shorthand_to_stim(text: str) -> str
```

Convert tsim shorthand syntax to valid stim instructions.

**Converts:**

T 0 1               → S\[T] 0 1
T\_DAG 0 1           → S\_DAG\[T] 0 1
TPP X0*Y1           → SPP\[T] X0*Y1
TPP\_DAG X0*Y1       → SPP\_DAG\[T] X0*Y1
R\_Z(0.3) 0          → I\[R\_Z(theta=0.3*pi)] 0
R\_X(0.25) 0         → I\[R\_X(theta=0.25*pi)] 0
R\_Y(-0.5) 0         → I\[R\_Y(theta=-0.5*pi)] 0
U3(0.3, 0.24, 0.49) 0 → I\[U3(theta=0.3*pi, phi=0.24*pi, lambda=0.49*pi)] 0

## `stim_to_shorthand`

```python theme={null}
stim_to_shorthand(text: str) -> str
```

Convert expanded stim annotations back to tsim shorthand.

Rewrites:

* I\[U3(theta=θ*pi, phi=φ*pi, lambda=λ\*pi)] → U3(θ, φ, λ)
* I\[R\_X(theta=α\*pi)] / I\[R\_Y(...)] / I\[R\_Z(...)] → R\_X(α) / R\_Y(α) / R\_Z(α)
* SPP\[T] → TPP
* SPP\_DAG\[T] → TPP\_DAG
* S\[T] → T
* S\_DAG\[T] → T\_DAG
