program_text
Conversion utilities between tsim shorthand and stim program text.
enriched_stim_error
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.
Source code in src/tsim/utils/program_text.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
shorthand_to_stim
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 X0Y1 → SPP[T] X0Y1 TPP_DAG X0Y1 → SPP_DAG[T] X0Y1 R_Z(0.3) 0 → I[R_Z(theta=0.3pi)] 0 R_X(0.25) 0 → I[R_X(theta=0.25pi)] 0 R_Y(-0.5) 0 → I[R_Y(theta=-0.5pi)] 0 U3(0.3, 0.24, 0.49) 0 → I[U3(theta=0.3pi, phi=0.24pi, lambda=0.49pi)] 0
Source code in src/tsim/utils/program_text.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
stim_to_shorthand
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
Source code in src/tsim/utils/program_text.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |