Stim Utilities
dem_to_parity_check(dem)
Convert a detector error model (DEM) into a parity check matrix, observable matrix, and probability vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dem
|
DetectorErrorModel
|
The detector error model to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
H |
csc_matrix
|
A boolean matrix of shape (number of detectors, number of errors) where H[i, j] = True if detector i is involved in error j. |
obs_matrix |
csc_matrix
|
A boolean matrix of shape (number of observables, number of errors) where obs_matrix[i, j] = True if observable i is involved in error j. |
p |
ndarray
|
A 1D numpy array of probabilities corresponding to each error. |
Source code in src/color_code_stim/stim_utils.py
82 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 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 171 172 173 174 175 176 177 178 179 180 181 |
|
dem_to_str(dem)
Convert a detector error model to its string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dem
|
DetectorErrorModel
|
The detector error model to convert. |
required |
Returns:
Type | Description |
---|---|
str
|
String representation of the detector error model. |
Source code in src/color_code_stim/stim_utils.py
remove_obs_from_dem(dem)
Remove detectors acting as observables from a detector error model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dem
|
DetectorErrorModel
|
The detector error model to process. |
required |
Returns:
Type | Description |
---|---|
DetectorErrorModel
|
A new detector error model with all detectors acting as observables removed. |
Source code in src/color_code_stim/stim_utils.py
save_circuit_diagram(circuit, path, type='timeline-svg')
Save a textual diagram of circuit
to path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circuit
|
Circuit
|
Circuit whose diagram will be saved. |
required |
path
|
str
|
File path for the output diagram. |
required |
type
|
str
|
Format used by |
'timeline-svg'
|
Returns:
Type | Description |
---|---|
None
|
This function writes to disk and does not return a value. |
Source code in src/color_code_stim/stim_utils.py
separate_depolarizing_errors(circuit)
Separates depolarizing errors in a Stim circuit into X and Z error components using modified probability calculations.
DEPOLARIZE1(p) is replaced by X_ERROR(pxz) Z_ERROR(pxz). pxz = 2q1(1 - q1), where q1 = (1 - sqrt(1 - 4p/3))/2.
DEPOLARIZE2(p) on qubits A and B is replaced by a sequence of: X_ERROR(p_comp) on A Z_ERROR(p_comp) on A X_ERROR(p_comp) on B Z_ERROR(p_comp) on B CORRELATED_ERROR(p_comp) XAXB CORRELATED_ERROR(p_comp) ZAZB p_comp = 4q2(1 - q2)(1 - 2q2 + 2q22), where q2 = (1 - (1 - 16p/15)*(1/8))/2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circuit
|
Circuit
|
The input circuit containing depolarizing errors to be separated. |
required |
Returns:
Type | Description |
---|---|
Circuit
|
A new circuit with DEPOLARIZE1 and DEPOLARIZE2 instructions replaced by sequences of X and Z type errors according to the specified formulas. |
Raises:
Type | Description |
---|---|
ValueError
|
|
Source code in src/color_code_stim/stim_utils.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
str_to_dem(s)
Convert a string representation back to a detector error model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
String representation of a detector error model. |
required |
Returns:
Type | Description |
---|---|
DetectorErrorModel
|
The reconstructed detector error model. |