1. Circuits¶
graphiq.circuit.circuit_dag.CircuitDAG ¶
Bases: CircuitBase
Directed Acyclic Graph (DAG) based circuit implementation
Each node of the graph contains an Operation (it is an input, output, or general Operation). The Operations in the topological order of the DAG.
Each connecting edge of the graph corresponds to a qubit/qudit or classical bit of the circuit
Source code in graphiq/circuit/circuit_dag.py
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 81 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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 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 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 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 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 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 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 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 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 | |
depth property ¶
Returns the circuit depth (NOT including input and output nodes)
Returns:
| Type | Description |
|---|---|
int | circuit depth |
register_depth property ¶
Returns the copy of register depth for each register
Returns:
| Type | Description |
|---|---|
dict | register depth |
__init__(n_emitter=0, n_photon=0, n_classical=0, openqasm_imports=None, openqasm_defs=None) ¶
Construct a DAG circuit with n_emitter one-qubit emitter quantum registers, n_photon one-qubit photon quantum registers, and n_classical one-cbit classical registers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_emitter | int | the number of emitter qubits/qudits in the system | 0 |
n_photon | int | the number of photon qubits/qudits in the system | 0 |
n_classical | int | the number of classical bits in the system | 0 |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/circuit_dag.py
add(operation) ¶
Add an operation to the end of the circuit (i.e. to be applied after the pre-existing circuit operations)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation | OperationBase | Operation (gate and register) to add to the graph | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
UserWarning | if no openqasm definitions exists for operation |
Source code in graphiq/circuit/circuit_dag.py
assign_noise(noise_model_map) ¶
Create a copy of the circuit where each gate is appended its noise model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
noise_model_map | | required |
Returns:
| Type | Description |
|---|---|
CircuitDAG | a new circuit |
Source code in graphiq/circuit/circuit_dag.py
calculate_all_reg_depth() ¶
Calculate all registers depth in the circuit Then return the register depth dict
Returns:
| Type | Description |
|---|---|
dict | register depth dict that has been calculated |
Source code in graphiq/circuit/circuit_dag.py
calculate_reg_depth(reg_type) ¶
Calculate the register depth of the register type Then return the register depth array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_type | str | str indicates register type. Can be "e", "p", or "c" | required |
Returns:
| Type | Description |
|---|---|
numpy.array | the array of register depth of all register in the register type |
Source code in graphiq/circuit/circuit_dag.py
compare(circuit, method='direct') ¶
Comparing two circuits by using GED or direct loop method
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
circuit | CircuitDAG | circuit that to be compared | required |
method | str | Determine which comparison function to use | 'direct' |
Returns:
| Type | Description |
|---|---|
bool | whether two circuits are the same |
Source code in graphiq/circuit/circuit_dag.py
draw_dag(show=True, fig=None, ax=None) ¶
Draw the circuit as a DAG
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show | bool | if True, the DAG is displayed (shown). If False, the DAG is drawn but not displayed | True |
fig | None | matplotlib.pyplot.figure | fig on which to draw the DAG (optional) | None |
ax | None | matplotlib.pyplot.axes | ax on which to draw the DAG (optional) | None |
Returns:
| Type | Description |
|---|---|
matplotlib.pyplot.figure, matplotlib.pyplot.axes | fig, ax on which the DAG was drawn |
Source code in graphiq/circuit/circuit_dag.py
edge_from_reg(t_edges, t_register) staticmethod ¶
Helper function to return correct edge from edges that map to the correct register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_edges | edge | input edge | required |
t_register | str | register | required |
Returns:
| Type | Description |
|---|---|
edge | correct edge |
Source code in graphiq/circuit/circuit_dag.py
find_incompatible_edges(first_edge) ¶
Find all incompatible edges of first_edge for which one cannot add any two-qubit operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first_edge | tuple | the edge under consideration | required |
Returns:
| Type | Description |
|---|---|
set(tuple) | a set of incompatible edges |
Source code in graphiq/circuit/circuit_dag.py
from_json(data_dict) classmethod ¶
Function to load from json object to circuit object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dict | dict | circuit json dict | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/circuit_dag.py
from_openqasm(qasm_script) classmethod ¶
Create a circuit based on an (assumed to be valid) openQASM script
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qasm_script | str | the openqasm script from which a circuit should be built | required |
Returns:
| Type | Description |
|---|---|
CircuitBase | a circuit object |
Source code in graphiq/circuit/circuit_dag.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 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 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 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 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
get_node_by_labels(labels) ¶
Get all nodes that satisfy all labels
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels | list[str] | descriptions of a set of nodes | required |
Returns:
| Type | Description |
|---|---|
list[int] | a list of node ids for nodes that satisfy all labels |
Source code in graphiq/circuit/circuit_dag.py
get_node_exclude_labels(labels) ¶
Get all nodes that do not satisfy any label in labels
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels | list[str] | descriptions of a set of nodes | required |
Returns:
| Type | Description |
|---|---|
list[int] | a list of node ids for nodes that do not satisfy any label in labels |
Source code in graphiq/circuit/circuit_dag.py
group_one_qubit_gates() ¶
Put consecutive one-qubit gates into a OneQubitGateWrapper
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/circuit_dag.py
insert_at(operation, edges) ¶
Insert an operation among specified edges
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation | OperationBase | Operation (gate and register) to add to the graph | required |
edges | list[tuple] | a list of edges relevant for this operation | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
UserWarning | if no openqasm definitions exists for operation |
AssertionError | if the number of edges disagrees with the number of q_registers |
Source code in graphiq/circuit/circuit_dag.py
min_reg_depth_index(reg_type) ¶
Calculate the register depth of the register type Then return the index of the register with minimum depth
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_type | str | str indicates register type. Can be "e", "p", or "c" | required |
Returns:
| Type | Description |
|---|---|
int | the index of register with min depth within register type |
Source code in graphiq/circuit/circuit_dag.py
reg_gate_history(reg, reg_type='e') ¶
Finds all the gates that the specified register goes through in the given circuit. A list of operations (gates) and a list of nodes in the chronological order is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg | int | the register | required |
reg_type | str | the type of the register | 'e' |
Returns:
| Type | Description |
|---|---|
tuple(list, list) | a tuple of lists, the first one is the list of operation and the second one is the list of nodes in the DAG |
Source code in graphiq/circuit/circuit_dag.py
remove_identity() ¶
Remove all identity gates
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/circuit_dag.py
remove_op(node) ¶
Remove an operation from the circuit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node | int | the node to be removed | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
replace_op(node, new_operation) ¶
Replaces an operation by a new one with the same set of registers it acts on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node | int | the node where the new operation is placed | required |
new_operation | OperationBase | the new operation | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
AssertionError | if new_operation acts on different registers from the operation in the node |
Source code in graphiq/circuit/circuit_dag.py
sequence(unwrapped=False) ¶
Return the sequence of operations composing this circuit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unwrapped | bool | If True, we "unwrap" the operation objects such that the returned sequence has only non-composed gates (i.e. wrapper gates which include multiple non-composed gates are broken down into their constituent parts). If False, operations are returned as defined in the circuit (i.e. wrapper gates are returned as wrappers) | False |
Returns:
| Type | Description |
|---|---|
list | iterator (of OperationBase subclass objects) | the operations which compose this circuit, in the order they should be applied |
Source code in graphiq/circuit/circuit_dag.py
sorted_reg_depth_index(reg_type) ¶
Return the array of register indexes with depth from smallest to largest Useful to find register index with nth smallest depth
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_type | str | str indicates register type. Can be "e", "p", or "c" | required |
Returns:
| Type | Description |
|---|---|
numpy.array | the array of register indexes with depth from smallest to largest |
Source code in graphiq/circuit/circuit_dag.py
to_json() ¶
Function to convert circuit object to json data format.
Returns:
| Type | Description |
|---|---|
dict | circuit json object |
Source code in graphiq/circuit/circuit_dag.py
unwrap_nodes() ¶
Unwrap the nodes with more than 1 ops in it
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/circuit_dag.py
validate() ¶
Assert that the circuit is valid (is a DAG, all nodes without input edges are input nodes, all nodes without output edges are output nodes)
Returns:
| Type | Description |
|---|---|
None | this function returns nothing |
Raises:
| Type | Description |
|---|---|
RuntimeError | if the circuit is not valid |
Source code in graphiq/circuit/circuit_dag.py
graphiq.circuit.ops ¶
The Operation objects are objects which tell the compiler what gate to apply on which registers / qubits
They serve two purposes: 1. They are used to build our circuit: circuit.add(OperationObj). The circuit constructs the DAG structure from the connectivity information in OperationObj 2. They are passed as an iterable to the compiler, such that the compiler can perform the correct series of information
REGISTERS VS QUDITS/CBITS: following qiskit/openQASM and other software, we allow a distinction between registers and qudits/qubits (where one register can contain a number of qubits / qudits).
IF an operation is given q_registers=(a, b), the circuit takes it to apply between registers a and b (that is, it applies between all qubits a[j], b[j] for 0 < j < n with a, b having length n)
If an operation is given q_registers=((a, b), (c, d)), the circuit takes it to apply between qubit b of register a, and qubit d of register c.
We can also use a mixture of registers and qubits: q_registers=(a, (b, c)) means that the operation will be applied between EACH QUBIT of register a, and qubit c of register b
CNOT ¶
CZ ¶
Bases: ControlledPairOperationBase
Controlled-Z gate Operation
Source code in graphiq/circuit/ops.py
ClassicalCNOT ¶
ClassicalCZ ¶
ClassicalControlledPairOperationBase ¶
Bases: OperationBase
This is used as a base class for our classical controlled gates (e.g. classical CNOT, classical CPHASE). Each ClassicalControlledPairOperationBase should have control and target registers/qubits specified, and a c_register target register/cbit specified.
Source code in graphiq/circuit/ops.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 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 580 581 | |
__init__(control, control_type, target, target_type, c_register=0, noise=nm.NoNoise()) ¶
Creates the classically controlled gate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int OR tuple (of ints, length 2) | the control register/qubit | required |
control_type | str | 'p' if photonic qubit, 'e' if emitter qubit | required |
target | int OR tuple (of ints, length 2) | target register/qubit for the Operation | required |
target_type | 'p' if photonic qubit, 'e' if emitter qubit | required | |
c_register | int OR tuple (of ints, length 2) | the classical register/cbit | 0 |
noise | graphiq.noise.noise_models.NoiseBase | Noise model | NoNoise() |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/ops.py
c_registers(c_reg) ¶
Handle to modify the register-cbit pair on which the operation acts. This also automatically updates the self.c_register field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c_reg | the new c_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new c_reg object does not have a length of 1 |
Source code in graphiq/circuit/ops.py
q_registers(q_reg) ¶
Handle to modify the register-qubit pairs on which the operation acts. This also automatically updates the self.control, self.target fields
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_reg | the new q_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new q_reg object does not have a length of 2 |
Source code in graphiq/circuit/ops.py
ControlledPairOperationBase ¶
Bases: OperationBase
This is used as a base class for our quantum controlled gates (e.g. CNOT, CPHASE). Each ControlledPairOperationBase should have control and target registers/qubits specified
Source code in graphiq/circuit/ops.py
__init__(control, control_type, target, target_type, noise=nm.NoNoise()) ¶
Creates a control gate object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int OR tuple (of ints, length 2) | control register/qubit for the Operation | required |
control_type | str | 'p' if photonic qubit, 'e' if emitter qubit | required |
target | int OR tuple (of ints, length 2) | target register/qubit for the Operation | required |
target_type | str | 'p' if photonic qubit, 'e' if emitter qubit | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Source code in graphiq/circuit/ops.py
q_registers(q_reg) ¶
Handle to modify the register-qubit pairs on which the operation acts. This also automatically updates the self.control, self.target fields
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_reg | the new q_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new q_reg object does not have a length of 2 |
Source code in graphiq/circuit/ops.py
Hadamard ¶
Identity ¶
Input ¶
Bases: InputOutputOperationBase
Input Operation. Serves as a placeholder in the circuit so that we know that this is where a given qubit/cbit is introduced (i.e. there are no prior operations on it)
Source code in graphiq/circuit/ops.py
InputOutputOperationBase ¶
Bases: OperationBase
This is used as a base class for our Input and Output Operations. These operations largely act as "dummy Operations" signalling the input / output of a state (useful for circuit DAG representation, for example)
Source code in graphiq/circuit/ops.py
__init__(register, reg_type, noise=nm.NoNoise()) ¶
Creates an IO base class Operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
register | int OR tuple (of ints, length 2) | the register/qubit which this I/O operation acts on | required |
reg_type | str | the input/output is for a quantum photonic register if 'p', for a quantum emitter register if 'e', and for a classical register if 'c' | required |
noise | graphiq.noise.noise_models.NoiseBase | Noise model | NoNoise() |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/ops.py
c_registers(c_reg) ¶
Handle to modify the register-cbit pairs on which the operation acts. This also automatically updates the self.register field, if the I/O is classical
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c_reg | the new c_register value to set (if any) | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new c_reg object does not match the length of self.c_registers (Operations should not have variable register numbers) |
Source code in graphiq/circuit/ops.py
q_registers(q_reg) ¶
Handle to modify the register-qubit pairs on which the operation acts. This also automatically updates the self.register field, if the I/O is quantum
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_reg | the new q_register value to set (if any) | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new q_reg object does not match the length of self.q_registers (Operations should not have variable register numbers) |
Source code in graphiq/circuit/ops.py
MeasurementCNOTandReset ¶
Bases: ClassicalControlledPairOperationBase
Measurement-controlled X gate Operation with resetting the control qubit after measurement
Source code in graphiq/circuit/ops.py
MeasurementZ ¶
Bases: OperationBase
Z Measurement Operation
Source code in graphiq/circuit/ops.py
__init__(register=0, reg_type='e', c_register=0, noise=nm.NoNoise()) ¶
Creates a Z measurement Operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
register | int OR tuple (of ints, length 2) | the quantum register on which the measurement is performed | 0 |
reg_type | str | 'p' if photonic qubit, 'e' if emitter qubit | 'e' |
c_register | int OR tuple (of ints, length 2) | the classical register to which the measurement result is saved | 0 |
noise | src.noise.noise_models.NoiseBase | Noise model | NoNoise() |
Returns:
| Type | Description |
|---|---|
None | this function returns nothing |
Source code in graphiq/circuit/ops.py
c_registers(c_reg) ¶
Handle to modify the register-cbit pair to which measurements are saved. This also automatically updates the self.c_register field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c_reg | the new c_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new c_reg object does not have a length of 1 |
Source code in graphiq/circuit/ops.py
q_registers(q_reg) ¶
Handle to modify the register-qubit pair which is measured. This also automatically updates the self.register field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_reg | the new q_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new q_reg object does not have a length of 1 |
Source code in graphiq/circuit/ops.py
OneQubitGateWrapper ¶
Bases: OneQubitOperationBase
This wrapper class allows us to compose a list of one-qubit operation and treat them as a single component within the circuit (this allows us, for example, to create every local Clifford gate with other gates, without having to separately implement every combination within the compiler)
Source code in graphiq/circuit/ops.py
unwrap() ¶
Unwraps the Operation into a list of sub-operations (this can be useful for any operations which are composed of multiple other operations) in the reverse order, which corresponds to the order of applying gates
Returns:
| Type | Description |
|---|---|
list | a sequence of base operations (i.e. operations which are not compositions of other operations) |
Source code in graphiq/circuit/ops.py
OneQubitOperationBase ¶
Bases: OperationBase
This is used as a base class for any one-qubit operation (one-qubit operations should all depend on a single parameter, "register"
Source code in graphiq/circuit/ops.py
__init__(register, reg_type, noise=nm.NoNoise()) ¶
Creates a one-qubit operation base class object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
register | int OR tuple (of ints, length 2) | the (quantum) register on which the single-qubit operation acts | required |
reg_type | str | 'e' if emitter qubit, 'p' if a photonic qubit | required |
noise | graphiq.noise.noise_models.NoiseBase | Noise model | NoNoise() |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/circuit/ops.py
q_registers(q_reg) ¶
Handle to modify the register-qubit pairs on which the operation acts. This also automatically updates the self.register field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_reg | the new q_register value to set | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the new q_reg object does not have a length of 1 |
Source code in graphiq/circuit/ops.py
OperationBase ¶
Bases: ABC
Base class from which operations will inherit
Source code in graphiq/circuit/ops.py
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 81 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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 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 | |
c_registers property writable ¶
Returns the c_registers tuple of the Operation class
Returns:
| Type | Description |
|---|---|
tuple | the c_registers_tuple |
labels property writable ¶
Returns the list of labels of this operation
Returns:
| Type | Description |
|---|---|
list[str] | list of labels |
q_registers property writable ¶
Returns the quantum registers tuple of the Operation class
Returns:
| Type | Description |
|---|---|
tuple | the registers tuple |
q_registers_type property writable ¶
Returns the quantum registers types ('e' for emitter, 'p' for photons) tuple of the Operation class
Returns:
| Type | Description |
|---|---|
tuple | the registers type |
__init__(q_registers=tuple(), q_registers_type=tuple(), c_registers=tuple(), noise=nm.NoNoise(), params=tuple(), param_info=dict()) ¶
Creates an Operation base object (which is largely responsible for holding the registers on which an operation act--this provides a consistent API for the circuit class to use when dealing with any arbitrary operation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q_registers | tuple (tuple of: integers OR tuples of length 2) | (a, ..., b) indices (indicating registers a, ..., b) OR ((a, b), ...) indicating photonic qubit b of register a OR any combination of (reg, bit) notation and reg notation These tuples can be of length 1 or empty as well, depending on the number of registers the gate requires | tuple() |
q_registers_type | tuple of strings, each is either 'p' (photonic qubit) or 'e' (emitter qubit) | tuple() | |
c_registers | tuple (tuple of: integers OR tuples of length 2) | same as photon/emitter_registers, but for the classical registers | tuple() |
noise | graphiq.noise.noise_models.NoiseBase | Noise model | NoNoise() |
params | tuple | an ordered list of parameter values for a parameterized gate | tuple() |
param_info | dict | a dictionary that specifies all the information regarding parameters | dict() |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
AssertionError | if photon_register, emitter_register, c_registers are not tuples, OR if the elements of the tuple do not correspond to the notation described above |
Source code in graphiq/circuit/ops.py
add_labels(new_labels) ¶
Adds new labels to existing labels
Returns:
| Type | Description |
|---|---|
None | nothing |
openqasm_info() classmethod ¶
Returns the information needed to generate an openQASM script using this operation (needed imports, how to define a gate, how to use a gate), packaged as a single object. This is used by the Circuit classes to generate openQASM scripts when needed
Returns:
| Type | Description |
|---|---|
| the operation class's openqasm information (possibly None) |
Source code in graphiq/circuit/ops.py
parse_q_reg_types() ¶
Find a proper string description of the register types relevant for this operation
Returns:
| Type | Description |
|---|---|
str | a string description |
Raises:
| Type | Description |
|---|---|
ValueError | if the quantum register type is not supported |
Source code in graphiq/circuit/ops.py
unwrap() ¶
Unwraps the Operation into a list of sub-operations (this can be useful for any operations which are composed of multiple other operations) in the reverse order, which corresponds to the order of applying operations.
Returns:
| Type | Description |
|---|---|
list | a sequence of base operations (i.e. operations which are not compositions of other operations) |
Source code in graphiq/circuit/ops.py
Output ¶
Bases: InputOutputOperationBase
Input Operation. Serves as a placeholder in the circuit so that we know that this is the final operation on a qubit/cbit (i.e. there are no subsequent operations on it)
Source code in graphiq/circuit/ops.py
ParameterizedControlledRotationQubit ¶
Bases: ControlledPairOperationBase
Parameterized two qubit controlled gate,
Source code in graphiq/circuit/ops.py
ParameterizedOneQubitRotation ¶
Bases: OneQubitOperationBase
Parameterized one qubit rotation.
Source code in graphiq/circuit/ops.py
Phase ¶
Bases: OneQubitOperationBase
Phase gate operation, P = diag(1, i)
Source code in graphiq/circuit/ops.py
PhaseDagger ¶
Bases: OneQubitOperationBase
Phase gate operation, P_dag = diag(1, -i)
Source code in graphiq/circuit/ops.py
RX ¶
Bases: ParameterizedOneQubitRotation
Rotation around the X axis
Source code in graphiq/circuit/ops.py
RY ¶
Bases: ParameterizedOneQubitRotation
Rotation around the Y axis
Source code in graphiq/circuit/ops.py
RZ ¶
Bases: ParameterizedOneQubitRotation
Rotation around the Z axis
Source code in graphiq/circuit/ops.py
SigmaX ¶
SigmaY ¶
SigmaZ ¶
class_to_name_mapping(class_op) ¶
Function to map operation class to string. It's used to convert circuit object to json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_op | operation | operation class | required |
Returns:
| Type | Description |
|---|---|
| |
Source code in graphiq/circuit/ops.py
find_local_clifford_by_matrix(matrix) ¶
Find local Clifford by its matrix representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix | numpy.ndarray | a matrix representation of one-qubit Clifford gate | required |
Returns:
| Type | Description |
|---|---|
list | the local Clifford gate specified by a list of basic gates it consists of or None if the input matrix is not a valid one-qubit Clifford gate |
Raises:
| Type | Description |
|---|---|
ValueError | if the matrix does not correspond to a valid one-qubit Clifford gate. |
Source code in graphiq/circuit/ops.py
local_clifford_to_matrix_map(gate) ¶
Find the 2 X 2 matrix corresponding to the local Clifford gate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate | list | a subclass of OperationBase | the local Clifford gate | required |
Returns:
| Type | Description |
|---|---|
numpy.ndarray | the 2 X 2 matrix corresponding to the local Clifford gate |
Source code in graphiq/circuit/ops.py
local_cliffords_name_to_matrix_map() ¶
Find all one-qubit local Clifford gates in the matrix representation
Returns:
| Type | Description |
|---|---|
map | all one-qubit local Clifford gates in the matrix representation |
Source code in graphiq/circuit/ops.py
name_to_class_map(name) ¶
Maps our openqasm naming scheme to operation classes. Does not handle multi-gate wrappers Does not handle multi-line openqasm components
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | gate name in openqasm | required |
Returns:
| Type | Description |
|---|---|
OperationBase class | the operation class corresponding to the openqasm name if the name is a valid name |
Source code in graphiq/circuit/ops.py
one_qubit_cliffords() ¶
Returns an iterator of single-qubit clifford gates
Returns:
| Type | Description |
|---|---|
map | iterator covering each single-qubit clifford gate |
Source code in graphiq/circuit/ops.py
simplify_local_clifford(gate_list) ¶
Simplify the list of basic gates that represents a local Clifford
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_list | list | original list of basic gates that represents a local Clifford | required |
Returns:
| Type | Description |
|---|---|
list | simplified list of basic gates that represents the same local Clifford |
Source code in graphiq/circuit/ops.py
graphiq.circuit.register ¶
Register ¶
Register class object, the class includes a dictionary which map the register type as the key and the register array as the value.
Source code in graphiq/circuit/register.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 81 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 | |
__init__(reg_dict, is_multi_qubit=False) ¶
Constructor for the register class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_dict | dict | register dictionary | required |
is_multi_qubit | bool | variable that indicate support for multi-qubit register | False |
Returns:
| Type | Description |
|---|---|
None | this function returns nothing |
Source code in graphiq/circuit/register.py
add_register(reg_type, size=1) ¶
Function that add a quantum/classical register to the register dict
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_type | str | 'p' for a photonic quantum register, 'e' for an emitter quantum register, 'c' for a classical register | required |
size | int | the new register size | 1 |
Returns:
| Type | Description |
|---|---|
int | the index number of the added register |
Raises:
| Type | Description |
|---|---|
ValueError | if new_size is not greater than the current register size |
Source code in graphiq/circuit/register.py
expand_register(reg_type, register, new_size=1) ¶
Function to expand quantum/classical registers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
register | int | the register index of the register to expand | required |
new_size | int | the new register size | 1 |
reg_type | str | 'p' for a photonic quantum register, 'e' for an emitter quantum register, 'c' for a classical register | required |
Returns:
| Type | Description |
|---|---|
None | this function returns nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if new_size is not greater than the current register size |
Source code in graphiq/circuit/register.py
next_register(reg_type, register) ¶
Provides the index of the next register in the provided register. This allows the user to query which register they should add next, should they decide to expand the register
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reg_type | str | indicate register type, can be "p", "e", or "c" | required |
register | int | the register index {0, ..., N - 1} for N emitter quantum registers | required |
Returns:
| Type | Description |
|---|---|
int (non-negative) | the index of the next register |