diagram
SVG diagram rendering for quantum circuits.
Diagram
Diagram(svg: str)
Wrapper for SVG diagram with Jupyter notebook display support.
Source code in src/tsim/utils/diagram.py
16 17 18 | |
__str__
__str__() -> str
Return the raw SVG string.
Source code in src/tsim/utils/diagram.py
20 21 22 | |
GateLabel dataclass
GateLabel(label: str, annotation: str | None = None)
Label for a gate in the SVG diagram.
placeholders_to_t
placeholders_to_t(
svg_string: str,
placeholder_id_to_labels: dict[float, GateLabel],
) -> str
Replace I_ERROR placeholder gates in an SVG diagram with actual gate names.
Supported gates are T, T†, R_Z, R_X, R_Y, U_3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
svg_string | str | The SVG string from stim's diagram() method containing I_ERROR | required |
placeholder_id_to_labels | dict[float, GateLabel] | Mapping from identifier (float), i.e. the p values of | required |
Returns:
| Type | Description |
|---|---|
str | Modified SVG string with I_ERROR gates replaced by the actual gate names. |
Source code in src/tsim/utils/diagram.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
render_svg
render_svg(
c: Circuit,
type: str,
*,
tick: int | range | None = None,
filter_coords: Iterable[Iterable[float] | DemTarget] = (
(),
),
rows: int | None = None,
width: float | None = None,
height: float | None = None
) -> Diagram
Render a stim circuit timeline/timeslice diagram with custom labels.
Source code in src/tsim/utils/diagram.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
tagged_gates_to_placeholder
tagged_gates_to_placeholder(
circuit: Circuit,
) -> tuple[stim.Circuit, dict[float, GateLabel]]
Replace tagged gates with I_ERROR placeholder gates for rendering.
Converts S[T], S_DAG[T], I[R_X(...)], I[R_Y(...)], I[R_Z(...)], I[U3(...)] to I_ERROR placeholder gates whose p-values are used as identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit | Circuit | The stim circuit to replace tagged gates with I_ERROR placeholder gates. | required |
Returns:
| Type | Description |
|---|---|
Circuit | A tuple containing the modified circuit and a dictionary mapping the p-values |
dict[float, GateLabel] | of the I_ERROR placeholder gates to the actual gate names. |
Source code in src/tsim/utils/diagram.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
wrap_svg
wrap_svg(
svg: str,
*,
width: float | None = None,
height: float | None = None
) -> str
Optionally wrap an SVG string in a scrolling container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
svg | str | Raw SVG markup. | required |
width | float | None | Explicit width for the container. | None |
height | float | None | Desired height; used to infer width from viewBox if width is not given. | None |
Source code in src/tsim/utils/diagram.py
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 | |