instructions
ZX graph representations of quantum gates and instructions.
GraphRepresentation dataclass
GraphRepresentation(
graph: GraphS = GraphS(),
rec: list[int] = list(),
silent_rec: list[int] = list(),
detectors: list[int] = list(),
observables_dict: dict[int, int] = dict(),
first_vertex: dict[int, int] = dict(),
last_vertex: dict[int, int] = dict(),
channel_probs: list[ndarray] = list(),
correlated_error_probs: list[float] = list(),
num_error_bits: int = 0,
num_correlated_error_bits: int = 0,
track_classical_wires: bool = False,
)
ZX graph built from a stim circuit.
Contains the graph and all auxiliary data needed for sampling.
edge_type property
edge_type
Edge type enum.
observables property
observables: list[int]
Get list of observable vertices sorted by index.
vertex_type property
vertex_type
Vertex type enum.
add_dummy
add_dummy(
b: GraphRepresentation,
qubit: int,
row: float | int | None = None,
) -> int
Add a dummy boundary vertex for a qubit.
Source code in src/tsim/core/instructions.py
80 81 82 83 84 85 86 87 88 | |
add_lane
add_lane(b: GraphRepresentation, qubit: int) -> int
Initialize a qubit lane if it doesn't exist.
Source code in src/tsim/core/instructions.py
91 92 93 94 95 96 97 98 | |
c_xyz
c_xyz(b: GraphRepresentation, qubit: int) -> None
Right handed period 3 axis cycling gate, sending X -> Y -> Z -> X.
Source code in src/tsim/core/instructions.py
209 210 211 212 213 | |
c_zyx
c_zyx(b: GraphRepresentation, qubit: int) -> None
Left handed period 3 axis cycling gate, sending Z -> Y -> X -> Z.
Source code in src/tsim/core/instructions.py
216 217 218 219 220 | |
cnot
cnot(
b: GraphRepresentation,
control: int,
target: int,
classically_controlled: list[bool] | None = None,
) -> None
Apply CNOT (controlled-X) gate.
Source code in src/tsim/core/instructions.py
351 352 353 354 355 356 357 358 | |
correlated_error
correlated_error(
b: GraphRepresentation,
qubits: list[int],
types: list[Literal["X", "Y", "Z"]],
p: float,
) -> None
Add a correlated error term affecting multiple qubits with given Pauli types.
Source code in src/tsim/core/instructions.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
cy
cy(
b: GraphRepresentation,
control: int,
target: int,
classically_controlled: list[bool] | None = None,
) -> None
Apply controlled-Y gate.
Source code in src/tsim/core/instructions.py
361 362 363 364 365 366 367 368 369 370 | |
cz
cz(
b: GraphRepresentation,
control: int,
target: int,
classically_controlled: list[bool] | None = None,
) -> None
Apply controlled-Z gate.
Source code in src/tsim/core/instructions.py
373 374 375 376 377 378 379 380 | |
depolarize1
depolarize1(
b: GraphRepresentation, qubit: int, p: float
) -> None
Apply single-qubit depolarizing channel with total error probability p.
Source code in src/tsim/core/instructions.py
582 583 584 | |
depolarize2
depolarize2(
b: GraphRepresentation,
qubit_i: int,
qubit_j: int,
p: float,
) -> None
Apply two-qubit depolarizing channel with total error probability p.
Source code in src/tsim/core/instructions.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
detector
detector(
b: GraphRepresentation, rec: list[int], *args
) -> None
Add detector annotation that XORs the given measurement record bits.
Source code in src/tsim/core/instructions.py
864 865 866 867 868 869 870 871 872 873 874 875 | |
ensure_lane
ensure_lane(b: GraphRepresentation, qubit: int) -> None
Ensure qubit lane exists.
Source code in src/tsim/core/instructions.py
101 102 103 104 | |
finalize_correlated_error
finalize_correlated_error(b: GraphRepresentation) -> None
Finalize the current correlated error channel.
- Rename all "c{i}" phases to "e{num_error_bits + i}" in the graph
- Compute and append the 2^k probability array to channel_probs
- Increment num_error_bits by k
- Reset num_correlated_error_bits to 0 and correlated_error_probs to []
Source code in src/tsim/core/instructions.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
h
h(b: GraphRepresentation, qubit: int) -> None
Apply Hadamard gate.
Source code in src/tsim/core/instructions.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
h_xy
h_xy(b: GraphRepresentation, qubit: int) -> None
Apply variant of Hadamard gate that swaps the X and Y axes (instead of X and Z).
Source code in src/tsim/core/instructions.py
237 238 239 240 241 | |
h_yz
h_yz(b: GraphRepresentation, qubit: int) -> None
Apply variant of Hadamard gate that swaps the Y and Z axes (instead of X and Z).
Source code in src/tsim/core/instructions.py
244 245 246 247 248 | |
i
i(b: GraphRepresentation, qubit: int) -> None
Apply identity (advances the row).
Source code in src/tsim/core/instructions.py
180 181 182 183 184 | |
iswap
iswap(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Swap two qubits and phase the -1 eigenspace of the ZZ observable by i.
Source code in src/tsim/core/instructions.py
397 398 399 400 401 402 | |
iswap_dag
iswap_dag(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Swap two qubits and phase the -1 eigenspace of the ZZ observable by -i.
Source code in src/tsim/core/instructions.py
405 406 407 408 409 410 | |
last_edge
last_edge(b: GraphRepresentation, qubit: int)
Get the last edge for a qubit.
Source code in src/tsim/core/instructions.py
73 74 75 76 77 | |
last_row
last_row(b: GraphRepresentation, qubit: int) -> float
Get the row of the last vertex for a qubit.
Source code in src/tsim/core/instructions.py
68 69 70 | |
m
m(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
Measure qubit in Z basis with optional bit-flip error probability p.
Source code in src/tsim/core/instructions.py
732 733 734 735 736 737 738 | |
mpp
mpp(
b: GraphRepresentation,
paulis: list[tuple[Literal["X", "Y", "Z"], int]],
invert: bool = False,
) -> None
Measure a single Pauli product.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b | GraphRepresentation | The graph representation to modify. | required |
paulis | list[tuple[Literal['X', 'Y', 'Z'], int]] | List of (pauli_type, qubit) pairs defining the Pauli product. | required |
invert | bool | Whether to invert the measurement result. | False |
Source code in src/tsim/core/instructions.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
mr
mr(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
Z-basis demolition measurement (optionally noisy).
Projects each target qubit into |0> or |1>, reports its value (false=|0>, true=|1>), then resets to |0>.
Source code in src/tsim/core/instructions.py
772 773 774 775 776 777 778 779 780 781 | |
mrx
mrx(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
X-basis demolition measurement (optionally noisy).
Projects each target qubit into |+> or |->, reports its value (false=|+>, true=|->), then resets to |+>.
Source code in src/tsim/core/instructions.py
784 785 786 787 788 789 790 791 792 793 794 795 | |
mry
mry(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
Y-basis demolition measurement (optionally noisy).
Projects each target qubit into |i> or |-i>, reports its value (false=|i>, true=|-i>), then resets to |i>.
Source code in src/tsim/core/instructions.py
798 799 800 801 802 803 804 805 806 807 808 809 | |
mx
mx(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
Measure qubit in X basis.
Source code in src/tsim/core/instructions.py
812 813 814 815 816 | |
my
my(
b: GraphRepresentation,
qubit: int,
p: float = 0,
invert: bool = False,
) -> None
Measure qubit in Y basis.
Source code in src/tsim/core/instructions.py
819 820 821 822 823 | |
observable_include
observable_include(
b: GraphRepresentation, rec: list[int], idx: int
) -> None
Add observable annotation that XORs the given measurement record bits.
Source code in src/tsim/core/instructions.py
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | |
pauli_channel_1
pauli_channel_1(
b: GraphRepresentation,
qubit: int,
px: float,
py: float,
pz: float,
) -> None
Apply single-qubit Pauli channel with given X, Y, Z error probabilities.
Source code in src/tsim/core/instructions.py
539 540 541 542 543 544 545 546 | |
pauli_channel_2
pauli_channel_2(
b: GraphRepresentation,
qubit_i: int,
qubit_j: int,
pix: float = 0,
piy: float = 0,
piz: float = 0,
pxi: float = 0,
pxx: float = 0,
pxy: float = 0,
pxz: float = 0,
pyi: float = 0,
pyx: float = 0,
pyy: float = 0,
pyz: float = 0,
pzi: float = 0,
pzx: float = 0,
pzy: float = 0,
pzz: float = 0,
) -> None
Apply two-qubit Pauli channel with given error probabilities for all 15 Pauli pairs.
Source code in src/tsim/core/instructions.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
r
r(b: GraphRepresentation, qubit: int) -> None
Z-basis reset.
Forces each target qubit into the |0> state by silently measuring it in the Z basis and applying an X gate if it ended up in the |1> state.
Source code in src/tsim/core/instructions.py
826 827 828 829 830 831 832 | |
r_x
r_x(
b: GraphRepresentation, qubit: int, phase: Fraction
) -> None
Apply R_X rotation gate with given phase (in units of π).
Source code in src/tsim/core/instructions.py
148 149 150 151 | |
r_y
r_y(
b: GraphRepresentation, qubit: int, phase: Fraction
) -> None
Apply R_Y rotation gate with given phase (in units of π).
Source code in src/tsim/core/instructions.py
154 155 156 157 158 | |
r_z
r_z(
b: GraphRepresentation, qubit: int, phase: Fraction
) -> None
Apply R_Z rotation gate with given phase (in units of π).
Source code in src/tsim/core/instructions.py
142 143 144 145 | |
rx
rx(b: GraphRepresentation, qubit: int) -> None
X-basis reset.
Forces each target qubit into the |+> state by silently measuring it in the X basis and applying a Z gate if it ended up in the |-> state.
Source code in src/tsim/core/instructions.py
835 836 837 838 839 840 841 842 843 844 | |
ry
ry(b: GraphRepresentation, qubit: int) -> None
Y-basis reset.
Forces each target qubit into the |i> state by silently measuring it in the Y basis and applying an X gate if it ended up in the |-i> state.
Source code in src/tsim/core/instructions.py
847 848 849 850 851 852 853 854 855 856 | |
s
s(b: GraphRepresentation, qubit: int) -> None
Apply S gate (π/2 Z rotation).
Source code in src/tsim/core/instructions.py
251 252 253 | |
s_dag
s_dag(b: GraphRepresentation, qubit: int) -> None
Apply S† gate (-π/2 Z rotation).
Source code in src/tsim/core/instructions.py
290 291 292 | |
sqrt_x
sqrt_x(b: GraphRepresentation, qubit: int) -> None
Apply √X gate (π/2 X rotation).
Source code in src/tsim/core/instructions.py
256 257 258 | |
sqrt_x_dag
sqrt_x_dag(b: GraphRepresentation, qubit: int) -> None
Apply √X† gate (-π/2 X rotation).
Source code in src/tsim/core/instructions.py
261 262 263 | |
sqrt_xx
sqrt_xx(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the XX observable by i.
Source code in src/tsim/core/instructions.py
413 414 415 416 417 | |
sqrt_xx_dag
sqrt_xx_dag(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the XX observable by -i.
Source code in src/tsim/core/instructions.py
420 421 422 423 424 | |
sqrt_y
sqrt_y(b: GraphRepresentation, qubit: int) -> None
Apply √Y gate (π/2 Y rotation).
Source code in src/tsim/core/instructions.py
266 267 268 269 270 | |
sqrt_y_dag
sqrt_y_dag(b: GraphRepresentation, qubit: int) -> None
Apply √Y† gate (-π/2 Y rotation).
Source code in src/tsim/core/instructions.py
273 274 275 276 277 | |
sqrt_yy
sqrt_yy(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the YY observable by i.
Source code in src/tsim/core/instructions.py
427 428 429 430 431 432 433 434 435 | |
sqrt_yy_dag
sqrt_yy_dag(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the YY observable by -i.
Source code in src/tsim/core/instructions.py
438 439 440 441 442 443 444 445 446 | |
sqrt_z
sqrt_z(b: GraphRepresentation, qubit: int) -> None
Apply √Z gate (alias for S gate).
Source code in src/tsim/core/instructions.py
280 281 282 | |
sqrt_z_dag
sqrt_z_dag(b: GraphRepresentation, qubit: int) -> None
Apply √Z† gate (alias for S† gate).
Source code in src/tsim/core/instructions.py
285 286 287 | |
sqrt_zz
sqrt_zz(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the ZZ observable by i.
Source code in src/tsim/core/instructions.py
449 450 451 452 453 | |
sqrt_zz_dag
sqrt_zz_dag(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Phases the -1 eigenspace of the ZZ observable by -i.
Source code in src/tsim/core/instructions.py
456 457 458 459 460 461 462 | |
swap
swap(
b: GraphRepresentation, qubit1: int, qubit2: int
) -> None
Apply SWAP gate.
Source code in src/tsim/core/instructions.py
383 384 385 386 387 388 389 390 391 392 393 394 | |
t
t(b: GraphRepresentation, qubit: int) -> None
Apply T gate (π/4 Z rotation).
Source code in src/tsim/core/instructions.py
132 133 134 | |
t_dag
t_dag(b: GraphRepresentation, qubit: int) -> None
Apply T† gate (-π/4 Z rotation).
Source code in src/tsim/core/instructions.py
137 138 139 | |
tick
tick(b: GraphRepresentation) -> None
Add a tick to the circuit (align all qubits to same row).
Source code in src/tsim/core/instructions.py
895 896 897 898 899 900 901 | |
u3
u3(
b: GraphRepresentation,
qubit: int,
theta: Fraction,
phi: Fraction,
lambda_: Fraction,
) -> None
Apply U3 gate: U3(θ,φ,λ) = R_Z(φ)·R_Y(θ)·R_Z(λ).
Source code in src/tsim/core/instructions.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
x
x(b: GraphRepresentation, qubit: int) -> None
Apply Pauli X gate.
Source code in src/tsim/core/instructions.py
187 188 189 | |
x_error
x_error(
b: GraphRepresentation, qubit: int, p: float
) -> None
Apply X error with probability p.
Source code in src/tsim/core/instructions.py
610 611 612 613 614 | |
x_phase
x_phase(
b: GraphRepresentation, qubit: int, phase: Fraction
) -> None
Apply X-axis rotation to qubit. This is equivalent to r_x up to a phase.
Source code in src/tsim/core/instructions.py
112 113 114 115 116 117 118 119 | |
xcx
xcx(
b: GraphRepresentation, control: int, target: int
) -> None
X-controlled X gate. Applies X to target if control is in |-> state.
Source code in src/tsim/core/instructions.py
465 466 467 468 469 | |
xcy
xcy(
b: GraphRepresentation, control: int, target: int
) -> None
X-controlled Y gate. Applies Y to target if control is in |-> state.
Source code in src/tsim/core/instructions.py
472 473 474 475 476 | |
xcz
xcz(
b: GraphRepresentation,
control: int,
target: int,
classically_controlled: list[bool] | None = None,
) -> None
X-controlled Z gate. Applies Z to target if control is in |-> state.
Source code in src/tsim/core/instructions.py
479 480 481 482 483 484 485 486 487 488 489 490 491 | |
y
y(b: GraphRepresentation, qubit: int) -> None
Apply Pauli Y gate.
Source code in src/tsim/core/instructions.py
192 193 194 195 196 | |
y_error
y_error(
b: GraphRepresentation, qubit: int, p: float
) -> None
Apply Y error with probability p.
Source code in src/tsim/core/instructions.py
617 618 619 620 621 622 623 | |
ycx
ycx(
b: GraphRepresentation, control: int, target: int
) -> None
Y-controlled X gate. Applies X to target if control is in |-i> state.
Source code in src/tsim/core/instructions.py
494 495 496 497 498 | |
ycy
ycy(
b: GraphRepresentation, control: int, target: int
) -> None
Y-controlled Y gate. Applies Y to target if control is in |-i> state.
Source code in src/tsim/core/instructions.py
501 502 503 504 505 | |
ycz
ycz(
b: GraphRepresentation,
control: int,
target: int,
classically_controlled: list[bool] | None = None,
) -> None
Y-controlled Z gate. Applies Z to target if control is in |-i> state.
Source code in src/tsim/core/instructions.py
508 509 510 511 512 513 514 515 516 517 518 519 520 | |
z
z(b: GraphRepresentation, qubit: int) -> None
Apply Pauli Z gate.
Source code in src/tsim/core/instructions.py
199 200 201 | |
z_error
z_error(
b: GraphRepresentation, qubit: int, p: float
) -> None
Apply Z error with probability p.
Source code in src/tsim/core/instructions.py
626 627 628 629 630 | |
z_phase
z_phase(
b: GraphRepresentation, qubit: int, phase: Fraction
) -> None
Apply Z-axis phase rotation to qubit. This is equivalent to r_z up to a phase.
Source code in src/tsim/core/instructions.py
122 123 124 125 126 127 128 129 | |