1. States¶
graphiq.state.QuantumState ¶
The QuantumState class is the unified API for accessing state representation backends. It contains one state representation.
Source code in graphiq/state.py
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 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 | |
rep_data property writable ¶
Representation data
Returns:
| Type | Description |
|---|---|
DensityMatrix | Stabilizer | Graph | representation data |
rep_type property writable ¶
Representation type
Returns:
| Type | Description |
|---|---|
str | representation type |
__init__(data, rep_type=None, mixed=False) ¶
Creates the QuantumState class with one initial representation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | list OR numpy.ndarray OR Graph OR nx.Graph | CliffordTableau | valid data input for "rep_type". Density matrices representations support np.ndarray or int inputs Stabilizer representations take int or StabilizerTableau Graph representations take networkx.Graph | required |
rep_type | str | selected representation to initialize; if not specified, the default choice is the density matrix if the number of qubits is less than the threshold value or stabilizer otherwise. | None |
mixed | boolean | boolean flag to initialize as a mixed state or not (mainly used for Stabilizer rep_type) | False |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/state.py
convert_representation(new_rep_type) ¶
Convert to a representation specified by new_rep_type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_rep_type | str | new representation type | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/state.py
copy() ¶
Make a copy of this QuantumState object
Returns:
| Type | Description |
|---|---|
QuantumState | a copy of the current QuantumState object |
partial_trace(keep, dims) ¶
Calculates the partial trace on all state representations which are currently defined
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep | list OR numpy.ndarray | An array of indices of the spaces to keep. For instance, if the space is \(A \times B \times C \times D\), and we want to trace out B and D, keep = [0,2] | required |
dims | list OR numpy.ndarray | An array of the dimensions of each space. For instance, if the space is \(A \times B \times C \times D\), dims = [\(dim_A\), \(dim_B\), \(dim_C\), \(dim_D\)] | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/state.py
show(show=True, ax=None) ¶
Plots the state representation using matplotlib formatting
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show | bool | if True, the state representation is plotted. Otherwise, it is drawn but not plotted | True |
ax | matplotlib.Axis | axis/axes on which to plot the state representation | None |
Returns:
| Type | Description |
|---|---|
matplotlib.Figure, matplotlib.Axis | fig, ax (the figure and axes on which data was plotted) |
Source code in graphiq/state.py
validate_data(data) classmethod ¶
Validate data type for input data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | int | np.ndarray | CliffordTableau | nx.Graph | input data | required |
Returns:
| Type | Description |
|---|---|
bool, int | True and the number of qubits if the data type is valid |
Source code in graphiq/state.py
graphiq.backends.density_matrix.state.DensityMatrix ¶
Bases: StateRepresentationBase
Density matrix of a state
Source code in graphiq/backends/density_matrix/state.py
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 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 | |
normalized property ¶
Return whether the state is normalized, that is, trace is 1
Returns:
| Type | Description |
|---|---|
bool | whether the state is normalized |
trace property ¶
Return the trace of the state
Returns:
| Type | Description |
|---|---|
float | the trace of the state |
__eq__(other) ¶
Compare two DensityMatrix objects and return True if the underlying density matrices are equal (up to precision)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other | DensityMatrix | another DensityMatrix object | required |
Returns:
| Type | Description |
|---|---|
bool | True if they are equal; False otherwise |
Source code in graphiq/backends/density_matrix/state.py
__init__(data, normalized=True, *args, **kwargs) ¶
Construct a DensityMatrix object from a numpy.ndarray or from the number of qubits. If an integer is specified, then the state is initialized as a product state of :math:|0\rangle with the given number of qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | numpy.ndarray | int | density matrix or the number of qubits | required |
normalized | bool | whether the state is normalized | True |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/density_matrix/state.py
apply_channel(kraus_ops) ¶
Apply a quantum channel on the state where the quantum channel is described by Kraus representation. Assumes the dimensions match; Otherwise, raise ValueError
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kraus_ops | list[numpy.ndarray] | a list of Kraus operators of the channel | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if Kraus operators have wrong dimensions. |
Source code in graphiq/backends/density_matrix/state.py
apply_measurement(projectors, measurement_determinism='probabilistic') ¶
Apply a measurement, either deterministically (with a certain outcome) or probabilistically
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectors | list[numpy.ndarray] | a list of projective measurements in the computational basis | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
int | the measurement outcome |
Source code in graphiq/backends/density_matrix/state.py
apply_measurement_controlled_gate(projectors, target_gate, measurement_determinism=1) ¶
Apply a measurement, either deterministically (with a certain outcome) or probabilistically and conditioned on the measurement outcome, apply the target_gate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectors | list[numpy.ndarray] | a list of projective measurements in the computational basis | required |
target_gate | numpy.ndarray | the gate to be applied if the measurement outcome is 1 | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 1 |
Returns:
| Type | Description |
|---|---|
int | the measurement outcome |
Raises:
| Type | Description |
|---|---|
AssertionError | if target_gate has different dimensions from the density matrix of the state |
Source code in graphiq/backends/density_matrix/state.py
apply_unitary(unitary) ¶
Apply a unitary to the state. Assumes the dimensions match; Otherwise, raise ValueError
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unitary | numpy.ndarray | unitary matrix to apply | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if the density matrix of the state has a different size from the unitary gate to be applied |
Source code in graphiq/backends/density_matrix/state.py
draw(style='bar', show=True) ¶
Draw a bar graph or heatmap of the DensityMatrix representation data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style | str | 'bar' for bar plot, 'heat' for heatmap | 'bar' |
show | bool | if True, show the density matrix plot. Otherwise, draw the density matrix plot but do not show | True |
Returns:
| Type | Description |
|---|---|
matplotlib.Figure, matplotlib.Axes | fig, axes on which the state is drawn |
Source code in graphiq/backends/density_matrix/state.py
from_graph(graph) classmethod ¶
Builds a density matrix representation from a graph (either nx.Graph or a Graph representation)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph | networkx.Graph OR Graph | the graph from which we will build a density matrix | required |
Returns:
| Type | Description |
|---|---|
DensityMatrix | a DensityMatrix representation with the data contained by graph |
Raises:
| Type | Description |
|---|---|
TypeError | if the input graph is neither nx.Graph or Graph |
Source code in graphiq/backends/density_matrix/state.py
partial_trace(keep, dims) ¶
Take the partial trace of the state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep | list OR numpy.ndarray | An array of indices of the spaces to keep. For instance, if the space is :math: | required |
dims | list OR numpy.ndarray | An array of the dimensions of each space. For instance, if the space is :math: | required |
Returns:
| Type | Description |
|---|---|
| |
Source code in graphiq/backends/density_matrix/state.py
graphiq.backends.stabilizer.state.Stabilizer ¶
Bases: StateRepresentationBase
Source code in graphiq/backends/stabilizer/state.py
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 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 | |
data property writable ¶
The data that represents the state given by this Stabilizer representation
Returns:
| Type | Description |
|---|---|
CliffordTableau | the tableau that represents this state |
n_qubits property ¶
Returns the number of qubits in the stabilizer state
Returns:
| Type | Description |
|---|---|
int | the number of qubits in the state |
tableau property writable ¶
The data that represents the state given by this Stabilizer representation
Returns:
| Type | Description |
|---|---|
CliffordTableau | the underlying representation |
__eq__(other) ¶
Compare two Stabilizer objects
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other | Stabilizer | the other Stabilizer to be compared | required |
Returns:
| Type | Description |
|---|---|
bool | True if the stabilizer tableaux of two Stabilizer objects are the same |
Source code in graphiq/backends/stabilizer/state.py
__str__() ¶
Return a string representation of this state representation
Returns:
| Type | Description |
|---|---|
str | a string representation of this state representation |
apply_circuit(gate_list_str, reverse=False) ¶
Apply a quantum circuit to the tableau
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_list_str | list[tuple] | a list of gates in the circuit | required |
reverse | bool | a parameter to indicate whether running the inverse circuit | False |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_cnot(control, target) ¶
Apply CNOT gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int | the control qubit position where the gate is applied | required |
target | int | the target qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_cz(control, target) ¶
Apply CZ gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int | the control qubit position where the gate is applied | required |
target | int | the target qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_hadamard(qubit_position) ¶
Apply the Hadamard gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_measurement(qubit_position, measurement_determinism='probabilistic') ¶
Apply the measurement in the computational basis to a given qubit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the measurement is applied | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
int | the measurement outcome |
Source code in graphiq/backends/stabilizer/state.py
apply_phase(qubit_position) ¶
Apply the phase gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_phase_dagger(qubit_position) ¶
Apply the phase dagger gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmax(qubit_position) ¶
Apply the X gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmay(qubit_position) ¶
Apply the Y gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmaz(qubit_position) ¶
Apply the Z gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_x_measurement(qubit_position, measurement_determinism='probabilistic') ¶
Apply the measurement in the computational basis to a given qubit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the measurement is applied | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
int | the measurement outcome |
Source code in graphiq/backends/stabilizer/state.py
partial_trace(keep, dims) ¶
Trace out qubits after disentangling them from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep | list[int] | numpy.ndarray | | required |
dims | | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
remove_qubit(qubit_position, measurement_determinism='probabilistic') ¶
Trace out one qubit after disentangling it from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position to be traced out | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
reset_qubit(qubit_position, measurement_determinism='probabilistic') ¶
Reset a given qubit to :math:|0\rangle state after disentangling it from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position to be reset | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
trace_out_qubits(qubit_positions, measurement_determinism='probabilistic') ¶
Trace out qubits after disentangling them from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_positions | list[int] | the qubit positions to be traced out | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
graphiq.backends.stabilizer.state.MixedStabilizer ¶
Bases: StateRepresentationBase
A mixed state representation using the stabilizer formalism, where the mixture is represented as a list of pure states (tableaus) and an associated mixture probability.
Source code in graphiq/backends/stabilizer/state.py
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 | |
data property writable ¶
The data that represents the state given by the MixedStabilizer representation
Returns:
| Type | Description |
|---|---|
list | the mixture that represents this state |
mixture property writable ¶
The mixture of pure states, represented as a list of tableaus and associated probabilities.
Returns:
| Type | Description |
|---|---|
list | the mixture as a list of (probability_i, tableau_i) |
n_qubits property ¶
Returns the number of qubits in the stabilizer state
Returns:
| Type | Description |
|---|---|
int | the number of qubits in the state |
probability property ¶
Computes the total probability as the summed probability of all pure states in the mixture \(\sum_i p_i \\ \forall (p_i, \mathcal{T}_i)\).
Returns:
| Type | Description |
|---|---|
float | sum of probabilities |
__eq__(other) ¶
Compare two MixedStabilizer objects
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other | MixedStabilizer | the other MixedStabilizer to be compared | required |
Returns:
| Type | Description |
|---|---|
bool | True if the stabilizer tableaux of two MixedStabilizer objects are the same |
Source code in graphiq/backends/stabilizer/state.py
__str__() ¶
Return a string representation of this state representation
Returns:
| Type | Description |
|---|---|
str | a string representation of this state representation |
Source code in graphiq/backends/stabilizer/state.py
apply_cnot(control, target) ¶
Apply CNOT gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int | the control qubit position where the gate is applied | required |
target | int | the target qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_conditioned_gate(qubit_position, outcomes, gate=None) ¶
Apply a single-qubit gate, conditioned on a classical measurement outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | required | |
outcomes | list of measurement outcomes for each tableau in the mixture | required | |
gate | str, one of 'x', 'y', 'z', or 'h' | None |
Returns:
| Type | Description |
|---|---|
| |
Source code in graphiq/backends/stabilizer/state.py
apply_cz(control, target) ¶
Apply CZ gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | int | the control qubit position where the gate is applied | required |
target | int | the target qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_hadamard(qubit_position) ¶
Apply the Hadamard gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_measurement(qubit_position, measurement_determinism='probabilistic') ¶
Apply the measurement in the computational basis to a given qubit. For the MixedStabilizer state, we measure the outcome for each tableau in the mixture, returning a list of outcomes.
todo think of classical probabilities being stored on the c-registers?¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the measurement is applied | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
list | the measurement outcome |
Source code in graphiq/backends/stabilizer/state.py
apply_phase(qubit_position) ¶
Apply the phase gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_phase_dagger(qubit_position) ¶
Apply the phase dagger gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmax(qubit_position) ¶
Apply the X gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmay(qubit_position) ¶
Apply the Y gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
apply_sigmaz(qubit_position) ¶
Apply the Z gate to the Stabilizer
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position where the gate is applied | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
partial_trace(keep, dims) ¶
Trace out qubits after disentangling them from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep | list[int] | numpy.ndarray | the qubit positions to be kept | required |
dims | list[int] | numpy.ndarray | dimension of each subsystem | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
reduce() ¶
Reduce the number of tableaux store in the mixture by comparing the Hamming distance between them. Probabilities are summed and one tableau removed if they are the same.
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
remove_qubit(qubit_position, measurement_determinism='probabilistic') ¶
Trace out one qubit after disentangling it from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position to be traced out | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
reset_qubit(qubit_position, measurement_determinism='probabilistic') ¶
Reset a given qubit to \(|0\rangle\) state after disentangling it from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_position | int | the qubit position to be reset | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
sort() ¶
Sort the mixture according to descending order of probabilities
Returns:
| Type | Description |
|---|---|
None | nothing |
trace_out_qubits(qubit_positions, measurement_determinism='probabilistic') ¶
Trace out qubits after disentangling them from the rest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubit_positions | list[int] | the qubit positions to be traced out | required |
measurement_determinism | str/int | if "probabilistic", measurement results are probabilistically selected if 1, measurement results default to 1 unless the probability of measuring p(1) = 0 if 0, measurement results default to 0 unless the probability of measuring p(0) = 0 | 'probabilistic' |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/stabilizer/state.py
graphiq.backends.graph.state.Graph ¶
Bases: StateRepresentationBase
Graph representation of a graph state. As the intermediate states of the process may not be graph states (but assuming still stabilizer states), we may need to keep track of local Clifford gates that convert the state to the graph state represented by the graph.
Source code in graphiq/backends/graph/state.py
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 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 | |
n_nodes property ¶
Returns the number of nodes in the Graph
Returns:
| Type | Description |
|---|---|
int | the number of nodes in the Graph |
__init__(data, clifford_dict=None, *args, **kwargs) ¶
Create a Graph representation object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | networkX.Graph | data used to construct the representation | required |
clifford_dict | dict | a dictionary that stores local Clifford for each node | None |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/graph/state.py
add_edge(first_node, second_node) ¶
Add an edge between two nodes. If any of these two nodes does not exist, no edge is added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first_node | int | the first node on which to add an edge | required |
second_node | int | the second node on which to add an edge | required |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/graph/state.py
add_node(node_to_add, lc_gate=None) ¶
Add a node to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_to_add | int | node id to add to the Graph representation | required |
lc_gate | list(str) | a list of local Clifford gates | None |
Returns:
| Type | Description |
|---|---|
None | nothing |
Raises:
| Type | Description |
|---|---|
ValueError | if node_to_add is of an invalid datatype |
Source code in graphiq/backends/graph/state.py
copy() ¶
draw(show=True, ax=None, with_labels=True) ¶
Draw the underlying networkX graph
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show | bool | if True, the Graph is shown. If False, the Graph is drawn but not displayed | True |
ax | matplotlib.Axis | axis on which to draw the plot (optional) | None |
with_labels | | True |
Returns:
| Type | Description |
|---|---|
None | nothing |
Source code in graphiq/backends/graph/state.py
find_lc(node_id) ¶
Find the local Clifford gates corresponding to a node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | int | the node index | required |
Returns:
| Type | Description |
|---|---|
ops.OneQubitOperationBase | local Clifford gates |
Source code in graphiq/backends/graph/state.py
get_edges() ¶
Get all graph edges (entangled pairs) in the Graph representation
Returns:
| Type | Description |
|---|---|
list | graph edges |
get_neighbors(node_id) ¶
Return the list of all neighbors (i.e. nodes connected by an edge) of the node with node_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | int | the ID of the node which we want to find the neighbours of | required |
Returns:
| Type | Description |
|---|---|
list | a list of neighbours for the node with node_id |
Source code in graphiq/backends/graph/state.py
get_nodes() ¶
Get all graph nodes (qubits) in the Graph representation
Returns:
| Type | Description |
|---|---|
list | all nodes in the Graph |
is_graph_state(graph) classmethod ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph | Graph | an instance of Graph | required |
Returns:
| Type | Description |
|---|---|
bool | True if graph is a graph state; False if graph is a non-graph stabilizer state |
Source code in graphiq/backends/graph/state.py
lc_equivalent(other_graph, mode='deterministic') ¶
Determines whether two graph states are local-Clifford equivalent or not, given the adjacency matrices of the two. It takes two adjacency matrices as input and returns a numpy.ndarray containing \(n (2 \times 2 array)s\) = clifford operations on each qubit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_graph | Graph | the other graph against which to check LC equivalence | required |
mode | str | the chosen mode for finding solutions. It can be either 'deterministic' (default) or 'random'. | 'deterministic' |
Returns:
| Type | Description |
|---|---|
bool, numpy.ndarray | None | If a solution is found, returns True and an array of single-qubit Clifford \(2 \times 2\) matrices in the symplectic formalism. If not, graphs are not LC equivalent and returns False, None. |
Raises:
| Type | Description |
|---|---|
AssertionError | if the number of rows in the row reduced matrix is less than the rank of coefficient matrix or if the number of linearly dependent columns is not equal to \(4n - rank\) (for \(n\) being the number of nodes in the graph) |
Source code in graphiq/backends/graph/state.py
local_complementation(node_id, copy=False) ¶
Takes the local complementation of the graph on the node indexed by node_id.
Local complementation: let n(node) be the set of neighbours of node. If a, b in n(node) and (a, b) is in the set of edges E of graph, then remove (a, b) from E. If a, b in n(node) and (a, b) is NOT in E, then add (a, b) into E.
The current implementation does not consider local Clifford gates. It assumes graph states. TODO: deal with general stabilizer states
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | int | the ID of the node around which local complementation should take place | required |
Returns:
| Type | Description |
|---|---|
Graph | the graph after the local complementation |
Source code in graphiq/backends/graph/state.py
update_lc(node_id, lc_gate) ¶
Find the local Clifford gates corresponding to a node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | int | the node index | required |
lc_gate | list(str) | a list of local Clifford gates | required |
Returns:
| Type | Description |
|---|---|
ops.OneQubitOperationBase | local Clifford gates |
Source code in graphiq/backends/graph/state.py
valid_datatype(data) classmethod ¶
Validate the data type of the input data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | any | input data | required |
Returns:
| Type | Description |
|---|---|
bool | whether the data type is allowed for this class |