References
Ansaetze#
Source code in qml_essentials/ansaetze.py
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 | |
Matchgate
#
Bases: DeclarativeCircuit
Matchgate LASA layer: RZ on every qubit + nearest-neighbour RXX.
Generators \(\{Z_k\} \cup \{X_k X_{k+1}\}\); the Lie closure is the matchgate algebra \(\mathfrak{so}(2n)\) with \(\dim = n(2n-1)\) (Kokcu et al., arXiv:2104.00728). RXX is applied on the even nearest-neighbour bonds and then the odd bonds of the open chain, so the layer width is \(n + (n-1)\). Gradients assume JAX autodiff.
Source code in qml_essentials/ansaetze.py
Permutation_Equivariant
#
Bases: DeclarativeCircuit
\(S_n\) permutation-equivariant layer (Schatzki et al., arXiv:2210.09974).
Shared-angle RX and RY on every qubit followed by a shared-angle RZZ on every qubit pair, realising \(\exp(-i \frac{a}{2} \sum_k X_k) \exp(-i \frac{b}{2} \sum_k Y_k) \exp(-i \frac{c}{2} \sum_{j<k} Z_j Z_k)\) for the rotation convention \(R_P(\theta) = \exp(-i \frac{\theta}{2} P)\). The three parameters are tied (shared across all gates), so the layer width is 3 independent of the qubit count.
Gradients assume JAX autodiff; a parameter-shift differentiator would need special handling for the shared parameters.
Source code in qml_essentials/ansaetze.py
XY_Brickwork
#
Bases: DeclarativeCircuit
Off-diagonal XY brickwork: nearest-neighbour RXX then RYY.
Generators \(\{X_k X_{k+1}, Y_k Y_{k+1}\}\); the Lie closure is the off-diagonal algebra \(\mathfrak{so}(n) \oplus \mathfrak{so}(n)\) with no single-qubit \(Z\), hence no deterministic \(\mathfrak{g}\)-purity floor. RXX on the even then odd bonds, followed by RYY on the even then odd bonds, so the layer width is \(2(n-1)\). Gradients assume JAX autodiff.
Source code in qml_essentials/ansaetze.py
Circuit#
Bases: ABC
Abstract base class for quantum circuit ansätze.
Source code in qml_essentials/ansaetze.py
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 154 155 156 157 158 | |
__call__(*args, **kwds)
#
__init__()
#
build(w, n_qubits, **kwargs)
abstractmethod
#
Build one layer of the quantum circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
ndarray
|
Parameter array for the current layer. |
required |
n_qubits
|
int
|
Number of qubits in the circuit. |
required |
**kwargs
|
Any
|
Additional keyword arguments passed from _build. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Circuit construction result. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in qml_essentials/ansaetze.py
get_control_angles(w, n_qubits)
#
Extract angles for controlled rotation gates from parameter array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
ndarray
|
Parameter array for one layer. |
required |
n_qubits
|
int
|
Number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ndarray]
|
Optional[np.ndarray]: Array of controlled gate parameters, or empty array if circuit contains no controlled gates. |
Source code in qml_essentials/ansaetze.py
get_control_indices(n_qubits)
abstractmethod
#
Get indices for controlled rotation gates in one layer.
Returns slice indices [start:stop:step] for extracting controlled gate parameters from a full parameter array for one layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
Optional[List[int]]
|
Optional[List[int]]: List of three integers [start, stop, step] for slicing, or None if the circuit contains no controlled rotation gates. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in qml_essentials/ansaetze.py
n_params_per_layer(n_qubits)
abstractmethod
#
Get the number of parameters per circuit layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Number of qubits in the circuit. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of parameters required per layer. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |
Source code in qml_essentials/ansaetze.py
n_pulse_params_per_layer(n_qubits)
#
Get the number of pulse parameters per circuit layer.
Subclasses that do not use pulse-level simulation do not need to override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Number of qubits in the circuit. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of pulse parameters required per layer. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If called but not overridden by subclass. |
Source code in qml_essentials/ansaetze.py
Declarative Circuit#
Bases: Circuit
A circuit defined entirely by a sequence of Block descriptors.
Subclasses only need to set the class attribute structure — a tuple of
All of n_params_per_layer, n_pulse_params_per_layer,
get_control_indices, and build are derived automatically.
Source code in qml_essentials/ansaetze.py
get_control_indices(n_qubits)
classmethod
#
Computes parameter indices for controlled rotation Gates. Scans the structure for Block with [start, stop, step] into the flat parameter vector, or None.
Source code in qml_essentials/ansaetze.py
Block#
Source code in qml_essentials/ansaetze.py
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 | |
__init__(gate, topology=None, shared=False, wires=None, **kwargs)
#
Initialize a Block object; the atoms of Ansatzes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate
|
str
|
Name of the Gate class to use. |
required |
topology
|
Any
|
Topology of the gate for entangling gates. Defaults to None. |
None
|
shared
|
bool
|
Tie all gates of the block to a single parameter (per-gate width), instead of one parameter per gate. Defaults to False. |
False
|
wires
|
Optional[List[int]]
|
Fixed wires for a non-entangling block. If None, the block spans all qubits. Defaults to None. |
None
|
kwargs
|
Any
|
Additional keyword arguments passed to the topology function. |
{}
|
Source code in qml_essentials/ansaetze.py
apply(n_qubits, w=None, w_idx=None, **kwargs)
#
Applies the block to the given circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Number of qubits, the block is applied to. |
required |
w
|
ndarray
|
Weights to use for rotational gates. Defaults to None. |
None
|
w_idx
|
int
|
Index of weights to use for rotational gates. Defaults to None. |
None
|
**kwargs
|
Any
|
Keyword arguments passed to the gate. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The new index of weights after applying the block. |
Source code in qml_essentials/ansaetze.py
Encoding#
Source code in qml_essentials/ansaetze.py
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 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 | |
is_golomb
property
#
Whether this encoding uses the Golomb (multi-qubit diagonal) strategy.
__init__(strategy, gates)
#
Initializes an Encoding object.
Implementations closely follow https://doi.org/10.22331/q-2023-12-20-1210
Parameters#
strategy : str The encoding strategy to use. Available options: ['hamming', 'binary', 'ternary'] gates : Union[str, Callable, List[Union[str, Callable]]] The gates to use for encoding. Can be a string, a callable or a list of strings or callables.
Returns#
None
Raises#
ValueError If the encoding strategy is not implemented. ValueError If there is an error parsing the Gates.
Source code in qml_essentials/ansaetze.py
binary(enc)
#
Binary encoding strategy.
Returns an encoding function that scales the input by a factor of 2^wires.
Binary encoding uses 2^(omegas + 1) - 1 frequencies for the encoding. See https://doi.org/10.22331/q-2023-12-20-1210 for more details.
Parameters#
enc : Callable The encoding function to be wrapped.
Returns#
Callable The wrapped encoding function.
Source code in qml_essentials/ansaetze.py
get_n_freqs(data_reupload)
#
Number of reachable frequencies (positive + negative + DC) for the
encoding strategy, given the (n_layers, n_qubits) data-reupload mask.
Source code in qml_essentials/ansaetze.py
get_spectrum(data_reupload)
#
Reachable Fourier frequency comb for the encoding strategy.
Computed exactly from the (n_layers, n_qubits) data-reupload mask as
the Minkowski sum of the per-gate generator frequencies:
- hamming: every encoding gate contributes +/-1, so the comb is
{-k, ..., k}withkthe total number of encoding gates. - binary / ternary: qubit
qis scaled bybase**q(base 2 / 3), applied once per active layer, so the comb is the Minkowski sum over qubits of{k * base**q : |k| <= count_q}withcount_qthe number of layers that re-upload on qubitq. - golomb: a single multi-qubit diagonal gate per active layer (see
Model._iec), each spanning[-max_mark, max_mark];kactive layers give{-k*max_mark, ..., k*max_mark}. The contiguous range is returned (not the sparse mark-difference set) because the FFT inCoefficients._fourier_transformsamples atmodel.degreeresolution and must cover the max frequency; residual sparse gaps carry ~0 coefficients.
See https://doi.org/10.22331/q-2023-12-20-1210 for more details.
Parameters#
data_reupload : np.ndarray
Boolean mask of shape (n_layers, n_qubits) (or (n_qubits,)
for a single layer) marking where the encoding re-uploads.
Returns#
np.ndarray The sorted reachable spectrum of the encoding strategy.
Source code in qml_essentials/ansaetze.py
get_weights(n_qubits)
#
Per-qubit weight vector w for the separable weighted encodings.
The encoding loads the scaled input phi_q = w_q * x on qubit q, so the
returned weights match the per-qubit scaling of the strategy callables
(see :meth:binary and :meth:ternary).
Parameters#
n_qubits : int The number of qubits carrying the encoding.
Returns#
np.ndarray
The weight vector of shape (n_qubits,).
Raises#
ValueError If the strategy is non-separable (golomb) and has no per-qubit weights.
Source code in qml_essentials/ansaetze.py
golomb(enc)
#
Golomb encoding strategy.
Returns a callable that applies a multi-qubit diagonal unitary
S(x) = exp(-i H x) where H = diag(golomb_marks) to all
qubits simultaneously. This produces the largest possible
|Ω| = d(d-1)+1 for any d-dimensional Hamiltonian, with
|R(k)| = 1 for all nonzero frequencies k.
Unlike the other strategies, Golomb encoding does not wrap a
per-qubit gate. Instead, the model's _iec method detects
is_golomb and applies a single GolombEncoding gate on
all qubits.
See Peters et al., arXiv:2209.05523, Sec. 3.1 and Appendix C.4.
Parameters#
enc : Callable or None Ignored (Golomb encoding uses its own multi-qubit gate).
Returns#
Callable
A callable with the same signature as per-qubit encoding
functions but that applies :func:GolombEncoding.
Source code in qml_essentials/ansaetze.py
hamming(enc)
#
Hamming encoding strategy.
Returns an encoding function that uses the Hamming encoding strategy which uses 2 * omegas + 1 frequencies for the encoding. See https://doi.org/10.22331/q-2023-12-20-1210 for more details.
Parameters#
enc : Callable The encoding function to be wrapped.
Returns#
Callable The wrapped encoding function.
Source code in qml_essentials/ansaetze.py
ternary(enc)
#
Ternary encoding strategy.
Returns an encoding function that scales the input by a factor of 3^wires.
Ternary encoding uses 3^omegas frequencies for the encoding. See https://doi.org/10.22331/q-2023-12-20-1210 for more details.
Parameters#
enc : Callable The encoding function to be wrapped.
Returns#
Callable The wrapped encoding function.
Source code in qml_essentials/ansaetze.py
Model#
A quantum circuit model.
Source code in qml_essentials/model.py
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 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 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 | |
all_qubit_measurement
property
#
Check if measurement is performed on all qubits.
batch_shape
property
#
Get the batch shape (B_I, B_P, B_R, B_E). If the model was not called before, it returns (1, 1, 1, 1).
Returns:
| Type | Description |
|---|---|
Tuple[int, ...]
|
Tuple[int, ...]: Tuple of (input_batch, param_batch, pulse_batch, enc_pulse_batch). Returns (1, 1, 1, 1) if model has not been called yet. |
data_reupload
property
writable
#
Get the data reupload mask.
degree
property
writable
#
Get the degree of the model.
eff_batch_shape
property
#
Get the effective batch shape after applying repeat_batch_axis mask.
Returns:
| Type | Description |
|---|---|
Tuple[int, ...]
|
Tuple[int, ...]: Effective batch dimensions, excluding zeros. |
enc_params
property
writable
#
Get the encoding parameters used for input transformation.
enc_pulse_params
property
writable
#
Get the encoding pulse parameters for all_pulse-mode execution.
execution_type
property
writable
#
Gets the execution type of the model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The execution type, one of 'density', 'expval', or 'probs'. |
frequencies
property
writable
#
Get the frequencies of the model.
has_dru
property
#
Check if the model has data reupload.
noise_params
property
writable
#
Gets the noise parameters of the model.
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Union[float, Dict[str, float]]]]
|
Optional[Dict[str, float]]: A dictionary of |
Optional[Dict[str, Union[float, Dict[str, float]]]]
|
noise parameters or None if not set. |
observables
property
writable
#
The custom :class:~jaqsi.operations.Operation observables,
or the list of measured wires when using the default PauliZ readout.
With a list of observables, __call__ and execution_type="expval"
returns one expectation value per observable instead of one PauliZ
per measured qubit.
output_qubit
property
writable
#
Deprecated alias for :attr:observables; returns the measured wires.
params
property
writable
#
Get the variational parameters of the model.
pulse_params
property
writable
#
Get the pulse parameters for pulse-mode gate execution.
shots
property
writable
#
Gets the number of shots to use for the quantum device.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Optional[int]: The number of shots. |
__call__(params=None, inputs=None, pulse_params=None, enc_params=None, data_reupload=None, noise_params=None, execution_type=None, force_mean=False, gate_mode=None, enc_pulse_params=None, random_key=None, keepdims=False)
#
Execute the quantum circuit (callable interface).
Provides a convenient callable interface for circuit execution, delegating to the _forward method.
This method writes the arguments it receives onto the model, so it
cannot be wrapped in an outer jax.jit or jax.vmap. Use
:meth:apply for that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[ndarray]
|
Variational parameters of shape (n_layers, n_params_per_layer) or (batch, n_layers, n_params_per_layer). If None, uses model's internal parameters. |
None
|
inputs
|
Optional[ndarray]
|
Input data of shape (batch_size, n_input_feat). If None, uses zero inputs. |
None
|
pulse_params
|
Optional[ndarray]
|
Pulse parameter scalers for the ansatz and state-preparation gates. Passing them runs those gates at pulse level. If None, they stay unitary. |
None
|
enc_params
|
Optional[ndarray]
|
Encoding parameters of shape (n_qubits, n_input_feat). If None, uses model's encoding parameters. |
None
|
noise_params
|
Optional[Dict[str, Union[float, Dict[str, float]]]]
|
Noise configuration. If None, uses previously set noise parameters. |
None
|
execution_type
|
Optional[str]
|
Measurement type: "expval", "density", "probs", or "state". If None, uses current execution_type setting. |
None
|
force_mean
|
bool
|
If True, averages results over measurement qubits. Defaults to False. |
False
|
gate_mode
|
Optional[str]
|
Deprecated. If None (default), the gate
execution backend is inferred from the provided pulse
parameters: |
None
|
enc_pulse_params
|
Optional[ndarray]
|
Pulse parameter scalers for the encoding gates. Passing them runs the encoding gates at pulse level. If None, they stay unitary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for stochastic
execution ( |
None
|
keepdims
|
bool
|
If True, the full (B_I, B_P, B_R, B_E, O) shape is returned. If False (default), all singleton axes are squeezed out. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Circuit output with shape depending on execution_type: - "expval": (n_measured_wiress,) or scalar - "density": (2^n_output, 2^n_output) - "probs": (2^n_output,) or (n_pairs, 2^pair_size) - "state": (2^n_qubits,) |
Note
An eager call stores params, pulse_params and enc_params
on the model, but a traced call (jit, grad, vmap) does
not: JAX tracers must not outlive their transform, so the model
state keeps its previous value. Two consequences:
- Anything reading model state after a traced call -
draw, :class:~qml_essentials.entanglement.Entanglement, :class:~qml_essentials.expressibility.Expressibility, or a later call that omitsparams- sees the old parameters. Assignmodel.params = paramsyourself if the state should follow a traced optimization step. - Omitting
paramsin a second call inside the same trace falls back to that stale state, so the result does not depend on the traced parameters (its gradient is zero). Passparamsexplicitly on every call inside a trace.
The skipped writes are reported at debug log level.
Source code in qml_essentials/model.py
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 | |
__init__(n_qubits, n_layers, circuit_type='No_Ansatz', data_reupload=True, state_preparation=None, encoding=Gates.RX, trainable_frequencies=False, initialization='random', initialization_domain=[0, 2 * jnp.pi], output_qubit=None, observables=None, shots=None, random_seed=1000, repeat_batch_axis=[True, True, True, True], pulse_shape='gaussian')
#
Initialize the quantum circuit model. Parameters will have the shape [impl_n_layers, parameters_per_layer] where impl_n_layers is the number of layers provided and added by one depending if data_reupload is True and parameters_per_layer is given by the chosen ansatz.
The model is initialized with the following parameters as defaults: - noise_params: None - execution_type: "expval" - shots: None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
The number of qubits in the circuit. |
required |
n_layers
|
int
|
The number of layers in the circuit. |
required |
circuit_type
|
(str, Circuit)
|
The type of quantum circuit to use. If None, defaults to "no_ansatz". |
'No_Ansatz'
|
encoding
|
Union[str, Callable, List[str], List[Callable]]
|
The unitary to use for encoding the input data. Can be a string (e.g. "RX") or a callable (e.g. gateset.RX). Defaults to gateset.RX. If input is multidimensional it is assumed to be a list of unitaries or a list of strings. |
RX
|
trainable_frequencies
|
bool
|
Sets trainable encoding parameters for trainable frequencies. Defaults to False. |
False
|
initialization
|
str
|
The strategy to initialize the parameters. Can be "random", "zeros", "zero-controlled", "pi", or "pi-controlled". Defaults to "random". |
'random'
|
output_qubit
|
(List[int], int)
|
Deprecated alias for
|
None
|
shots
|
Optional[int]
|
The number of shots to use for the quantum device. Defaults to None. |
None
|
random_seed
|
int
|
seed for the random number generator in initialization is "random" and for random noise parameters. Defaults to 1000. |
1000
|
repeat_batch_axis
|
List[bool]
|
Each boolean in the array determines over which axes to parallelise computation. The axes correspond to [inputs, params, pulse_params, enc_pulse_params]. Defaults to [True, True, True, True], meaning that batching is enabled over all axes. A 3-element list (legacy) is accepted and extended with a trailing True for the enc_pulse_params axis. |
[True, True, True, True]
|
pulse_shape
|
str
|
Pulse envelope shape for pulse-level
simulation. One of |
'gaussian'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in qml_essentials/model.py
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 | |
__repr__()
#
__str__()
#
apply(params=None, inputs=None, pulse_params=None, enc_params=None, noise_params=None, execution_type=None, force_mean=False, gate_mode=None, enc_pulse_params=None, key=None)
#
Execute the quantum circuit without modifying the model.
Functional counterpart of :meth:__call__. No model state is written,
so the call can be wrapped in an outer jax.jit, jax.vmap or a
whole jitted training step. The output always keeps the full
(B_I, B_P, B_R, B_E, O) shape, so its rank does not depend on the batch
sizes; call .squeeze() for the shape :meth:__call__ returns.
Arguments left as None fall back to the current model state, which an
outer jax.jit bakes in at trace time. Anything that varies between
calls, such as the parameters during training or the key for shots,
has to be passed explicitly.
Unlike :meth:__call__ this method takes no data_reupload
argument, as that reconfigures the circuit; set
:attr:data_reupload on the model beforehand instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[ndarray]
|
Variational parameters of shape (n_layers, n_params_per_layer) or (batch, n_layers, n_params_per_layer). If None, uses model's internal parameters. |
None
|
inputs
|
Optional[ndarray]
|
Input data of shape (batch_size, n_input_feat). If None, uses zero inputs. |
None
|
pulse_params
|
Optional[ndarray]
|
Pulse parameter scalers for the ansatz and state-preparation gates. Passing them runs those gates at pulse level. If None, they stay unitary. |
None
|
enc_params
|
Optional[ndarray]
|
Encoding parameters of shape (n_qubits, n_input_feat). If None, uses model's encoding parameters. |
None
|
noise_params
|
Optional[Dict[str, Union[float, Dict[str, float]]]]
|
Noise configuration. If None, uses the model's noise parameters. |
None
|
execution_type
|
Optional[str]
|
Measurement type: "expval", "density", "probs", or "state". If None, uses current execution_type setting. |
None
|
force_mean
|
bool
|
If True, averages results over measurement qubits. Defaults to False. |
False
|
gate_mode
|
Optional[str]
|
Deprecated. If None (default), the mode
is inferred from the provided pulse parameters. See
:meth: |
None
|
enc_pulse_params
|
Optional[ndarray]
|
Pulse parameter scalers for the encoding gates. Passing them runs the encoding gates at pulse level. If None, they stay unitary. |
None
|
key
|
Optional[PRNGKey]
|
JAX random key for shots and stochastic noise. If None, the model's random key is used without advancing it. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Circuit output of shape (B_I, B_P, B_R, B_E, O), where O is the per-sample output shape of the execution type and may span more than one axis (e.g. "density" and "probs"). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the encoding gates would run at pulse level but the encoding has no pulse parametrization, or if shots are set for a density measurement. |
Source code in qml_essentials/model.py
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 | |
draw(inputs=None, figure='text', **kwargs)
#
Visualize the quantum circuit.
Records the circuit tape (without noise) and renders the gate sequence using the requested backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Optional[ndarray]
|
Input data for the circuit.
If |
None
|
figure
|
str
|
Rendering backend. One of:
|
'text'
|
**kwargs
|
Any
|
Extra options forwarded to the drawing backend
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, Any]
|
Depends on figure: |
Union[str, Any]
|
|
Union[str, Any]
|
|
Union[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If figure is not one of the supported modes. |
Source code in qml_essentials/model.py
draw_pulse(inputs=None, **kwargs)
#
Visualize the pulse schedule for the circuit.
Records the circuit in pulse mode and collects PulseEvents automatically via the pulse-event tape, then renders them.
State preparation, ansatz and encoding gates are all rendered as pulses. Encodings without a pulse parametrization (golomb and custom callables) are omitted from the schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
Optional[ndarray]
|
Input data. If |
None
|
**kwargs
|
Any
|
Forwarded to
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
|
Source code in qml_essentials/model.py
exact_spectrum(method='tree')
#
Compute the exact per-feature Fourier spectrum via the FourierTree.
Unlike :attr:frequencies -- a naive per-feature estimate derived purely
from the encoding, which can overestimate the spectrum (some
coefficients are constrained to zero for all parameters) -- this builds
the analytical Fourier tree (Nemkov et al.) and returns, for each input
feature, the integer frequencies whose Fourier coefficient is not
identically zero. The result is always a subset of :attr:frequencies.
The support is derived purely symbolically (no parameter sampling): see
:meth:~qml_essentials.coefficients.FourierTree.get_exact_support.
With method="tree" (default), frequencies whose contributions cancel
identically across tree paths (e.g. two consecutive encodings combining
into a single rotation) are excluded exactly; this enumerates the
explicit tree, which can be infeasible for deep entangling circuits.
With method="dp", a merged-state dynamic program derives the support
without enumerating paths, which scales to deep circuits at the cost of
not detecting identical cross-path cancellations.
Requires a Clifford + Pauli-rotation ansatz (see
:class:~qml_essentials.pauli.PauliCircuit); other gate sets raise
NotImplementedError during tree construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
|
'tree'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple[np.ndarray, ...]: One sorted integer frequency array per input |
...
|
feature (same layout as :attr: |
Source code in qml_essentials/model.py
initialize_params(random_key=None, repeat=1, initialization=None, initialization_domain=None)
#
Initialize the variational parameters of the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_key
|
Optional[PRNGKey]
|
JAX random key for initialization. If None, uses the model's internal random key. |
None
|
repeat
|
int
|
Number of parameter sets to create (batch dimension). Defaults to 1. |
1
|
initialization
|
Optional[str]
|
Strategy for parameter initialization. Options: "random", "zeros", "pi", "zero-controlled", "pi-controlled". If None, uses the strategy specified in the constructor. |
None
|
initialization_domain
|
Optional[List[float]]
|
Domain [min, max] for random initialization. If None, uses the domain from constructor. |
None
|
Returns:
| Type | Description |
|---|---|
PRNGKey
|
random.PRNGKey: Updated random key after initialization. |
Raises:
| Type | Description |
|---|---|
Exception
|
If an invalid initialization method is specified. |
Source code in qml_essentials/model.py
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 | |
next_key()
#
Advance the internal random key and return a fresh sub key.
Intended for stochastic execution inside a JAX transform: a jitted
call is traced once and replays the key that was current at trace
time, so fresh randomness has to enter as an argument. Call this
outside the transform and pass the result as random_key. Since the
key is an argument rather than a constant, this does not trigger
recompilation.
Returns:
| Type | Description |
|---|---|
PRNGKey
|
random.PRNGKey: Fresh sub key, split off the internal key. |
Source code in qml_essentials/model.py
transform_input(inputs, enc_params)
#
Transform input data by scaling with encoding parameters.
Implements the input transformation as described in arXiv:2309.03279v2, where inputs are linearly scaled by encoding parameters before being used in the quantum circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
ndarray
|
Input data point of shape (n_input_feat,) or (batch_size, n_input_feat). |
required |
enc_params
|
ndarray
|
Encoding weight scalar or vector used to scale the input. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Transformed input, element-wise product of inputs and enc_params. |
Source code in qml_essentials/model.py
Entanglement#
Source code in qml_essentials/entanglement.py
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 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 | |
bell_measurements(model, n_samples, random_key=None, scale=False, **kwargs)
classmethod
#
Compute the Bell measurement for a given model.
Constructs a 2 * n_qubits circuit that prepares two copies of
the model state (on disjoint qubit registers), applies CNOTs and
Hadamards, and measures probabilities on the first register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
int
|
The number of samples to compute the measure for. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples according to the number of qubits. |
False
|
**kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The Bell measurement value. |
Source code in qml_essentials/entanglement.py
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 | |
concentratable_entanglement(model, n_samples, random_key=None, scale=False, **kwargs)
classmethod
#
Computes the concentratable entanglement of a given model.
This method utilizes the Concentratable Entanglement measure from
https://arxiv.org/abs/2104.06923. The swap test is implemented
directly in jaqsi using a 3 * n_qubits circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
int
|
The number of samples to compute the measure for. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples according to the number of qubits. |
False
|
**kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Entangling capability of the given circuit, guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
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 | |
concentratable_entanglement_estimation(model, n_samples, random_key=None, scale=False, **kwargs)
classmethod
#
Computes the concentratable entanglement of a given model.
This method utilizes the Concentratable Entanglement measure from
https://arxiv.org/abs/2104.06923. The swap test is implemented
directly in jaqsi using a 3 * n_qubits circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
int
|
The number of samples to compute the measure for. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples according to the number of qubits. |
False
|
**kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Entangling capability of the given circuit, guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
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 | |
entanglement_of_formation(model, n_samples, random_key=None, scale=False, always_decompose=False, **kwargs)
classmethod
#
This function implements the entanglement of formation for mixed quantum systems. In that a mixed state gets decomposed into pure states with respective probabilities using the eigendecomposition of the density matrix. Then, the Meyer-Wallach measure is computed for each pure state, weighted by the eigenvalue. See e.g. https://doi.org/10.48550/arXiv.quant-ph/0504163
Note that the decomposition is not unique! Therefore, this measure
presents the entanglement for some decomposition into pure states,
not necessarily the one that is anticipated when applying the Kraus
channels.
If a pure state is provided, this results in the same value as the
Entanglement.meyer_wallach function if always_decompose flag is not set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
int
|
Number of samples per qubit. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples. |
False
|
always_decompose
|
bool
|
Whether to explicitly compute the entantlement of formation for the eigendecomposition of a pure state. |
False
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Entangling capacity of the given circuit, guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
meyer_wallach(model, n_samples, random_key=None, scale=False, **kwargs)
classmethod
#
Calculates the entangling capacity of a given quantum circuit using Meyer-Wallach measure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
Optional[int]
|
Number of samples per qubit. If None or < 0, the current parameters of the model are used. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples. |
False
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Entangling capacity of the given circuit, guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
relative_entropy(model, n_samples, n_sigmas, random_key=None, scale=False, **kwargs)
classmethod
#
Calculates the relative entropy of entanglement of a given quantum circuit. This measure is also applicable to mixed state, albeit it might me not fully accurate in this simplified case.
As the relative entropy is generally defined as the smallest relative entropy from the state in question to the set of separable states. However, as computing the nearest separable state is NP-hard, we select n_sigmas of random separable states to compute the distance to, which is not necessarily the nearest. Thus, this measure of entanglement presents an upper limit of entanglement.
As the relative entropy is not necessarily between zero and one, this function also normalises by the relative entroy to the GHZ state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
n_samples
|
int
|
Number of samples per qubit. If <= 0, the current parameters of the model are used. |
required |
n_sigmas
|
int
|
Number of random separable pure states to compare against. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples. |
False
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Entangling capacity of the given circuit, guaranteed to be between 0.0 and 1.0. |
Source code in qml_essentials/entanglement.py
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 | |
Expressibility#
Source code in qml_essentials/expressibility.py
12 13 14 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 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 | |
haar_integral(n_qubits, n_bins, cache=True, scale=False)
classmethod
#
Calculates theoretical probability density function for random Haar states as proposed by Sim et al. (https://arxiv.org/abs/1905.10876) and bins it into a 3D-histogram.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
number of qubits in the quantum system |
required |
n_bins
|
int
|
number of histogram bins |
required |
cache
|
bool
|
whether to cache the haar integral |
True
|
scale
|
bool
|
whether to scale the number of bins |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Tuple[jnp.ndarray, jnp.ndarray]: - x component (bins): the input domain - y component (probabilities): the haar probability density funtion for random Haar states |
Source code in qml_essentials/expressibility.py
kl_divergence_to_haar(model, n_samples, n_bins, random_key=None, scale=False, **kwargs)
classmethod
#
Shortcut method to compute the KL-Divergence bewteen a model and the Haar distribution. The basic steps are: - Sample the state fidelities for randomly initialised parameters. - Calculates the KL divergence between the sampled probability and the Haar probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Function that models the quantum circuit. |
required |
n_samples
|
int
|
Number of parameter sets to generate. |
required |
n_bins
|
int
|
Number of histogram bins. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples and bins. |
False
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]: Tuple containing the input samples, bin edges, and histogram values. |
Source code in qml_essentials/expressibility.py
kullback_leibler_divergence(vqc_prob_dist, haar_dist)
classmethod
#
Calculates the KL divergence between two probability distributions (Haar probability distribution and the fidelity distribution sampled from a VQC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vqc_prob_dist
|
ndarray
|
VQC fidelity probability distribution. Should have shape (n_inputs_samples, n_bins) |
required |
haar_dist
|
ndarray
|
Haar probability distribution with shape. Should have shape (n_bins, ) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Array of KL-Divergence values for all values in axis 1 |
Source code in qml_essentials/expressibility.py
state_fidelities(n_samples, n_bins, model, random_key=None, scale=False, **kwargs)
classmethod
#
Sample the state fidelities and histogram them into a 2D array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of parameter sets to generate. |
required |
n_bins
|
int
|
Number of histogram bins. |
required |
model
|
Callable
|
Function that models the quantum circuit. |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
scale
|
bool
|
Whether to scale the number of samples and bins. |
False
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple[jnp.ndarray, jnp.ndarray]: Tuple containing the bin edges, |
ndarray
|
and histogram values. |
Source code in qml_essentials/expressibility.py
Coefficients#
Source code in qml_essentials/coefficients.py
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 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 | |
evaluate_Fourier_series(coefficients, frequencies, inputs)
classmethod
#
Evaluate the function value of a Fourier series at one point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
ndarray
|
Coefficients of the Fourier series. |
required |
frequencies
|
ndarray
|
Corresponding frequencies. |
required |
inputs
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns: float: The function value at the input point.
Source code in qml_essentials/coefficients.py
get_psd(coeffs)
classmethod
#
Calculates the power spectral density (PSD) from given Fourier coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
ndarray
|
The Fourier coefficients. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: The power spectral density. |
Source code in qml_essentials/coefficients.py
get_spectrum(model, mfs=1, mts=1, shift=False, trim=False, numerical_cap=-1, **kwargs)
classmethod
#
Extracts the coefficients of a given model using a FFT (jnp-fft).
Note that the coefficients are complex numbers, but the imaginary part of the coefficients should be very close to zero, since the expectation values of the Pauli operators are real numbers.
It can perform oversampling in both the frequency and time domain
using the mfs and mts arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model to sample. |
required |
mfs
|
int
|
Multiplicator for the highest frequency. Default is 1. |
1
|
mts
|
int
|
Multiplicator for the number of time samples. Default is 1. |
1
|
shift
|
bool
|
Whether to apply jnp-fftshift. Default is False. |
False
|
trim
|
bool
|
Whether to remove the Nyquist frequency if spectrum is even. Default is False. |
False
|
numerical_cap
|
Optional[float]
|
Numerical cap for the coefficients.
If positive, coefficients with magnitude below the cap are
zeroed and, for a single input feature, frequencies that
vanish entirely are removed from both |
-1
|
kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple[jnp.ndarray, jnp.ndarray]: Tuple containing the coefficients |
ndarray
|
and frequencies. |
Note
The FFT grid is built from the nominal model.degree, which does
not account for frequency scaling via enc_params or
enc_pulse_params. For a model whose effective frequencies exceed
the nominal degree by a factor \(s > 1\), choose mfs at least
\(\lceil s \rceil\) (e.g. mfs=2 covers scalings up to 2),
otherwise the scaled components alias.
Source code in qml_essentials/coefficients.py
Fourier Tree#
Sine-cosine tree representation for the algorithm by Nemkov et al.
Computes the analytical Fourier coefficients/frequencies of a Pauli-Clifford circuit. The symbolic structure of the tree (which Pauli rotations contribute sine/cosine factors to which leaf, and the leaf observables) is built once in NumPy; the parameter-dependent coefficients are then obtained with a small number of vectorised JAX operations, so the result remains jittable / differentiable with respect to the model parameters.
The resulting spectrum is the d-dimensional set of frequency vectors, where \(d\) is the input dimensionality.
Usage:
model = Model(...)
tree = FourierTree(model)
exp = tree() # expectation value
coeff_list, freq_list = tree.get_spectrum()
Source code in qml_essentials/coefficients.py
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 | |
__call__(params=None, inputs=None, **kwargs)
#
Evaluate the expectation value(s) of the model's observables via the sine-cosine tree (equivalent to the circuit expectation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[ndarray]
|
Model parameters. Defaults to the model's parameters. |
None
|
inputs
|
Optional[ndarray]
|
Inputs to the circuit. Defaults to 1. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Expectation value per observable (or their mean if
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For execution types other than "expval" or when noise is requested. |
Source code in qml_essentials/coefficients.py
__init__(model)
#
Tree initialisation, based on the Pauli-Clifford representation of a model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The Model, for which to build the tree. |
required |
Source code in qml_essentials/coefficients.py
get_exact_support(method='tree')
#
Symbolically derive the exact frequency support (no sampling).
A frequency :math:\omega belongs to the exact spectrum iff its
coefficient :math:c_\omega(\theta) = \sum_l W_{\omega l}\,
\text{term}_l\, v_l(\theta) is not identically zero in the
variational parameters :math:\theta.
Two methods are available:
"tree"(default, fully exact): enumerates the explicit tree leaves. Because the branch index strictly decreases along every tree path, each parameter contributes at most one sine or cosine factor per leaf (:math:S_{li}, C_{li} \in \{0, 1\}). Every variational leaf factor :math:v_lis therefore a square-free monomial over :math:\{1, \cos\theta_i, i\sin\theta_i\}, and monomials with distinct signatures are linearly independent functions (no :math:\cos^2 + \sin^2identities can arise without squares). Hence
.. math:: c_\omega \equiv 0 \iff \sum_{l \in g} W_{\omega l}\,\text{term}_l = 0 \quad \text{for every signature group } g.
Since all involved quantities are dyadic rationals times
:math:\{\pm 1, \pm i\}, the group sums are exact in float64 and the
zero-test is exact. The number of leaves can however grow
exponentially with circuit depth.
"dp"(scalable): merges tree nodes with identical(rotation index, observable)— at mostn_params * 4^n_qubitsstates — and tracks, per state, the achievable per-feature sine/cosine count vectors(s_f, c_f)as a mixed-radix bitmask. Each feature's support is the union of the (exact) expansion supports of :math:\cos^{c_f} x_f\, (i \sin x_f)^{s_f}, and the model support is their Cartesian product across features. This is exact per tree path (including interior zero coefficients of the expansions), but unlike"tree"it cannot detect coefficients that cancel identically across paths with identical variational signatures (e.g. directly repeated encodings). It therefore yields a tight superset in such corner cases. Supports any number of input features, but requires unit-magnitude input scaling: per-gate :math:|\omega| \neq 1scalings (e.g. Golomb encodings) are rejected — use"tree".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
|
'tree'
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List[np.ndarray]: For each observable (root), the frequency vectors |
List[ndarray]
|
with not-identically-zero coefficient — shape |
List[ndarray]
|
single input feature, |
Source code in qml_essentials/coefficients.py
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 | |
get_spectrum(force_mean=False)
#
Compute the Fourier spectrum (coefficients and frequencies) of the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_mean
|
bool
|
Average the coefficients over all observables (roots). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[List[ndarray], List[ndarray]]
|
Tuple[List[jnp.ndarray], List[jnp.ndarray]]:
- List of coefficients, one entry per observable (root).
- List of corresponding frequencies, one entry per root.
When |
Source code in qml_essentials/coefficients.py
Fourier Coefficient Correlation#
Source code in qml_essentials/coefficients.py
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 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 | |
calculate_fcc(fourier_fingerprint)
classmethod
#
Method to calculate the FCC based on an existing correlation matrix.
Calculate absolute and then the average over this matrix.
The Fingerprint can be obtained via get_fourier_fingerprint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fourier_fingerprint
|
ndarray
|
Correlation matrix of coefficients |
required |
Returns: float: The FCC
Source code in qml_essentials/coefficients.py
get_fcc(model, n_samples, random_key=None, method='pearson', scale=False, weight=False, trim_redundant=True, **kwargs)
classmethod
#
Shortcut method to get just the FCC.
This includes
1. What is done in get_fourier_fingerprint:
1. Calculating the coefficients (using n_samples)
2. Correlating the result from 1) using method
3. Weighting the correlation matrix (if weight is True)
4. Remove redundancies
2. What is done in calculate_fcc:
1. Absolute of the fingerprint
2. Average
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The QFM model |
required |
n_samples
|
int
|
Number of samples to calculate average of coefficients |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
method
|
Optional[str]
|
Correlation method. Supported values are "pearson", "complex_pearson", "spearman", and "covariance". Defaults to "pearson". |
'pearson'
|
scale
|
Optional[bool]
|
Whether to scale the number of samples. Defaults to False. |
False
|
weight
|
Optional[bool]
|
Whether to weight the correlation matrix. Defaults to False. |
False
|
trim_redundant
|
Optional[bool]
|
Whether to remove redundant correlations. Defaults to False. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The FCC |
Source code in qml_essentials/coefficients.py
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 | |
get_fourier_fingerprint(model, n_samples, random_key=None, method='pearson', scale=False, weight=False, trim_redundant=True, nan_to_one=False, **kwargs)
classmethod
#
Shortcut method to get just the fourier fingerprint.
This includes
1. Calculating the coefficients (using n_samples)
2. Correlating the result from 1) using method
3. Weighting the correlation matrix (if weight is True)
4. Remove redundancies (if trim_redundant is True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The QFM model |
required |
n_samples
|
int
|
Number of samples to calculate average of coefficients |
required |
random_key
|
Optional[PRNGKey]
|
JAX random key for parameter initialization. If None, uses the model's internal random key. |
None
|
method
|
Optional[str]
|
Correlation method. Supported values are "pearson", "complex_pearson", "spearman", and "covariance". Defaults to "pearson". |
'pearson'
|
scale
|
Optional[bool]
|
Whether to scale the number of samples. Defaults to False. |
False
|
weight
|
Optional[bool]
|
Whether to weight the correlation matrix. Defaults to False. |
False
|
trim_redundant
|
Optional[bool]
|
Whether to remove redundant correlations. Defaults to True. |
True
|
nan_to_one
|
Optional[bool]
|
Whether to set nan to 1. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional keyword arguments for the model function. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray]: The fourier |
ndarray
|
fingerprint, the corresponding frequency indices and the |
ndarray
|
corresponding coefficients. If |
Tuple[ndarray, ndarray, ndarray]
|
frequencies are returned as a |
Tuple[ndarray, ndarray, ndarray]
|
labels the two (redundancy-trimmed) matrix axes and the |
Tuple[ndarray, ndarray, ndarray]
|
coefficients as a matching |
Tuple[ndarray, ndarray, ndarray]
|
rows align with those frequencies; otherwise the full frequency |
Tuple[ndarray, ndarray, ndarray]
|
vector and full coefficient array are returned. |
Source code in qml_essentials/coefficients.py
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 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 | |
Datasets#
Source code in qml_essentials/coefficients.py
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 | |
calculate_values(domain_samples, frequencies, coefficients)
classmethod
#
Evaluates the real-valued Fourier series on the domain grid.
Vectorized version of \(f(x) = \sum_{n=0}^{N-1} c_n e^{i \omega_n x}\) that takes the input dimension into account, normalized by the number of coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_samples
|
ndarray
|
Domain samples with shape (n_points, n_input_feat). |
required |
frequencies
|
ndarray
|
Frequency indices with shape (n_freqs, n_input_feat). |
required |
coefficients
|
ndarray
|
Fourier coefficients with shape (n_freqs,). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Real-valued Fourier series samples with shape (n_points,). |
Source code in qml_essentials/coefficients.py
construct_coefficients(random_key, model, coefficients_min=0.0, coefficients_max=1.0, zero_centered=False)
classmethod
#
Samples the conjugate-symmetric Fourier coefficient vector.
Coefficients are drawn from a uniform circle (see uniform_circle).
The offset coefficient (first entry) is either zeroed or made real,
then the spectrum is mirrored to enforce conjugate symmetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_key
|
PRNGKey
|
Random number key for JAX. |
required |
model
|
Model
|
The quantum circuit model. |
required |
coefficients_min
|
float
|
Minimum value for the coefficients. Defaults to 0.0. |
0.0
|
coefficients_max
|
float
|
Maximum value for the coefficients. Defaults to 1.0. |
1.0
|
zero_centered
|
bool
|
Whether to zero-center the coefficients. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Conjugate-symmetric coefficient vector of size \(\prod\) degree. |
Source code in qml_essentials/coefficients.py
construct_domain_samples(model, mts=1, mfs=1)
classmethod
#
Builds the input-domain sample grid for the model spectrum.
Going from \([0, 2 \pi \, \mathrm{mts}]\) with the resolution required for the highest frequency, permuted with the input dimensionality to get an n-d grid of domain samples (a "coordinate system").
The grid follows the same convention as
Coefficients._fourier_transform, so a dataset built here lands on the
bins that Coefficients.get_spectrum analyses with the same mts and
mfs. A target component at \(k + j/r\) has period \(2 \pi r\), hence
mts should be at least \(r\) to cover a full period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
mts
|
int
|
Domain oversampling, i.e. the number of periods covered. Defaults to 1. |
1
|
mfs
|
int
|
Frequency oversampling, i.e. the sample density per period. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Domain samples with shape (mts \(\cdot\) mfs \(\cdot\) \(\prod\) degree, n_input_feat). |
Source code in qml_essentials/coefficients.py
construct_frequencies(model, random_key=None, offgrid_mode='none', offgrid_prob=0.0, offgrid_resolution=2)
classmethod
#
Builds the frequency-index grid for the model spectrum.
This has the same shape as the domain samples returned by
construct_domain_samples.
By default the grid is the model's own comb, so the dataset is exactly representable. The off-grid modes move a controllable fraction of the components off that comb. Offsets are always multiples of \(1/r\) for the given resolution \(r\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
random_key
|
Optional[PRNGKey]
|
Random number key for JAX.
Required unless |
None
|
offgrid_mode
|
str
|
How to displace components off the model comb. "none" keeps the model comb. "index" perturbs each frequency independently, which spans arbitrary combs that are in general not exactly reachable. "generator" perturbs the per-gate generator frequencies and rebuilds the comb as their Minkowski sum, which stays exactly reachable by an encoding pulse configuration. Defaults to "none". |
'none'
|
offgrid_prob
|
float
|
Probability that a single component ("index") or generator ("generator") is displaced. Defaults to 0.0, which reproduces the model comb in every mode. Note that this is the fraction of components that end up off the comb only in "index" mode: a sum of displaced generators can land back on an integer, so "generator" mode displaces noticeably fewer components than asked for and saturates well below one. |
0.0
|
offgrid_resolution
|
int
|
Denominator \(r\) of the offset grid, i.e. offsets are drawn from \(\{\pm j/r\}\) with \(j = 1 \dots r-1\). Defaults to 2, giving half-integer offsets. |
2
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Frequency indices with shape (\(\prod\) degree, n_input_feat). |
Source code in qml_essentials/coefficients.py
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 | |
generate_fourier_series(random_key, model, coefficients_min=0.0, coefficients_max=1.0, zero_centered=False)
classmethod
#
Generates the Fourier series representation of a function.
It uses the model.frequencies property to retrieve the frequency
information. This ensures that the resulting Fourier series is
compatible with the model.
This function is capable of generating \(D\)-dimensional Fourier series
(again defined by model.n_input_feat).
The highest frequency \(N\) is retrieved per dimension.
Samples of the Fourier coefficients are drawn from a uniform circle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_key
|
PRNGKey
|
Random number key for JAX. |
required |
model
|
Model
|
The quantum circuit model. |
required |
coefficients_min
|
float
|
Minimum value for the coefficients. Defaults to 0.0. |
0.0
|
coefficients_max
|
float
|
Maximum value for the coefficients. Defaults to 1.0. |
1.0
|
zero_centered
|
bool
|
Whether to zero-center the coefficients. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Input domain samples with shape ((N,)*D, D) |
ndarray
|
jnp.ndarray: Fourier series values with shape ((N,)*D) |
ndarray
|
jnp.ndarray: Fourier coefficients with shape ((N,)*D) |
Source code in qml_essentials/coefficients.py
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 | |
generator_etas(model, random_key, offgrid_prob, offgrid_resolution)
classmethod
#
The encoding pulse amplitude scalers construct_frequencies applies in
offgrid_mode='generator', one (\(n_\text{layers}, n_\text{qubits}\))
array per input feature.
Call with the same random_key passed to construct_frequencies to
recover the encoding pulse configuration that makes the off-grid target
reachable, e.g. to oracle-initialize or score trained scalers against
it. The per-feature key split mirrors construct_frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The quantum circuit model. |
required |
random_key
|
PRNGKey
|
The key passed to
|
required |
offgrid_prob
|
float
|
Probability that a generator is displaced. |
required |
offgrid_resolution
|
int
|
Denominator \(r\) of the offset grid. |
required |
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List[np.ndarray]: Amplitude scalers \(\eta\) per input feature. |
Source code in qml_essentials/coefficients.py
uniform_circle(random_key, size, low=0.0, high=1.0)
classmethod
#
Random number generator for complex numbers sampled inside the unit circle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_key
|
PRNGKey
|
Random number key for JAX. |
required |
size
|
Union[ndarray, int]
|
Number of samples. If a 2D array is passed, the first dimension will be the number of dimensions. |
required |
low
|
float
|
Minimum Radius. Defaults to 0.0. |
0.0
|
high
|
float
|
Maximum Radius. Defaults to 1.0. |
1.0
|
Returns
jnp.ndarray: Array of complex numbers with shape of size
Source code in qml_essentials/coefficients.py
Topologies#
Generates [control, target] wire-pair lists for two-qubit gates.
All public methods are static and share a small set of private
helpers so that related topologies (e.g. linear / circular,
brick_layer / brick_layer_wrap) re-use the same core logic.
Raises#
ValueError
If n_qubits < 2 is passed to any topology method.
Source code in qml_essentials/topologies.py
8 9 10 11 12 13 14 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
all_pairs(n_qubits)
classmethod
#
all_to_all(n_qubits)
classmethod
#
Every ordered pair (i, j) with i ≠j.
Source code in qml_essentials/topologies.py
graph(n_qubits, *, edges)
classmethod
#
Explicit edge list as a topology.
The given order and orientation are preserved, so the resulting
circuit is deterministic and directed gates act on the wires as
written. Both orientations of the same qubit pair are therefore
allowed; only a repeated (control, target) pair is rejected.
Parameters#
n_qubits : int
Number of qubits.
edges : Sequence[Sequence[int]]
(control, target) qubit pairs.
Returns#
List[Tuple[int, int]]
Raises#
ValueError If an edge leaves the qubit range, is a self-loop or repeats.
Source code in qml_essentials/topologies.py
stairs(n_qubits, offset=0, wrap=False, reverse=True, mirror=True, span=1, stride=1, modulo=True)
classmethod
#
Unified generator for nearest-neighbour and spand pair topologies.
Produces [control, target] pairs of qubits.
The default values, produce an "upstairs" entangling sequence without wrapping around the last gate.
Parameters#
n_qubits : int Number of qubits. offset : Union[int, Callable] Offset for starting the entangling sequence. Can either be a integer or a callable that takes n_qubits as input. wrap : bool Wraps around the entangling gates. reverse : bool Reverses both the iteration direction (upstairs/ downstairs) mirror: bool Flip target/ control qubit span : int Offset between control and target qubit. Defaults to 1 stride : int Step size for entangling gates. Defaults to 1, meaning a stair pattern will be generated. modulo : bool If a gate should be placed when the iterator decreases below 0 or exceeds n_qubits. Defaults to True
Returns#
List[List[int]]
Source code in qml_essentials/topologies.py
Pauli Circuit#
Wrapper for Pauli-Clifford Circuits described by Nemkov et al. (https://doi.org/10.1103/PhysRevA.108.032406). The code is inspired by the corresponding implementation: https://github.com/idnm/FourierVQA.
A Pauli Circuit only consists of parameterised Pauli-rotations and Clifford gates, which is the default for the most common VQCs.
Source code in qml_essentials/pauli.py
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 | |
cliffords_in_observable(operations, original_obs, n_qubits)
staticmethod
#
Integrates Clifford gates into the observables of the original ansatz,
by symbolically conjugating each observable through the final Clifford
sequence (O -> C^dagger O C for each Clifford, applied in reverse).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operations
|
List[Operation]
|
Clifford gates |
required |
original_obs
|
List[Operation]
|
Original observables from the circuit |
required |
n_qubits
|
int
|
Total number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
List[Operation]
|
List[Operation]: Observables with Clifford operations absorbed.
Each carries a cached symbolic |
Source code in qml_essentials/pauli.py
commute_all_cliffords_to_the_end(operations, n_qubits)
staticmethod
#
This function moves all clifford gates to the end of the circuit, accounting for commutation rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operations
|
List[Operation]
|
The operations in the tape of the circuit |
required |
n_qubits
|
int
|
Total number of qubits. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[Operation], List[Operation]]
|
Tuple[List[Operation], List[Operation]]: - List of the resulting Pauli-rotations - List of the resulting Clifford gates |
Source code in qml_essentials/pauli.py
from_parameterised_circuit(tape, observables=None, n_qubits=None)
staticmethod
#
Transforms a list of operations into a Pauli-Clifford circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tape
|
List[Operation]
|
List of operations recorded from the circuit. |
required |
observables
|
Optional[List[Operation]]
|
List of observable operations. If |
None
|
n_qubits
|
Optional[int]
|
Total number of qubits. Inferred from the maximum wire
index if |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[List[Operation], List[Operation]]
|
Tuple[List[Operation], List[Operation]]: The Pauli rotations of the canonical circuit and the (Clifford-evolved) observables. |
Source code in qml_essentials/pauli.py
get_clifford_pauli_gates(tape)
staticmethod
#
This function decomposes all gates in the circuit to clifford and pauli-rotation gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tape
|
List[Operation]
|
List of operations recorded from the circuit. |
required |
Returns:
| Type | Description |
|---|---|
List[Operation]
|
List[Operation]: A list of operations consisting only of clifford and Pauli-rotation gates. |
Source code in qml_essentials/pauli.py
get_parameters(operations)
staticmethod
#
Flatten the parameter values of a tape (list of operations).