References
Ansaetze#
Source code in qml_essentials/ansaetze.py
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 | |
Circuit#
Bases: ABC
Abstract base class for quantum circuit ansätze.
Source code in qml_essentials/ansaetze.py
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 | |
__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
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 | |
__init__(gate, topology=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
|
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
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 | |
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(omegas)
#
Returns the number of frequencies required for the encoding strategy. This includes positive and negative side.
Parameters#
omegas : int The number of frequencies to encode.
Returns#
int The number of frequencies required for the encoding strategy.
Source code in qml_essentials/ansaetze.py
get_spectrum(omegas)
#
Spectrum for one of the following encoding strategies:
Hamming: {-n_q -(n_q-1), ..., n_q} Binary: {-2^{n_q}+1, ..., 2^{n_q}-1} Ternary: {-floor(3^{n_q}/2), ..., floor(3^(n_q)/2)} Golomb: all pairwise differences of Golomb ruler marks, scaled by the number of encoding applications
See https://doi.org/10.22331/q-2023-12-20-1210 for more details.
Parameters#
omegas : int The number of frequencies to encode.
Returns#
np.ndarray The spectrum of the encoding strategy.
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 Gates.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 + 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
Gates#
As the structure of the different classes used to realize pulse and unitary gates can be a bit confusing, the following diagram might help:

Dynamic accessor for quantum Gates.
Routes calls like Gates.RX(...) to either UnitaryGates or PulseGates
depending on the gate_mode keyword (defaults to 'unitary').
During circuit building, the pulse manager can be activated via
pulse_manager_context, which slices the global model pulse parameters
and passes them to each gate. Model pulse parameters act as element-wise
scalers on the gate's optimized pulse parameters.
Parameters#
gate_mode : str, optional Determines the backend. 'unitary' for UnitaryGates, 'pulse' for PulseGates. Defaults to 'unitary'.
Examples#
Gates.RX(w, wires) Gates.RX(w, wires, gate_mode="unitary") Gates.RX(w, wires, gate_mode="pulse") Gates.RX(w, wires, pulse_params, gate_mode="pulse")
Source code in qml_essentials/gates.py
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 | |
pulse_manager_context(pulse_params)
classmethod
#
Temporarily set the global pulse manager for circuit building.
Source code in qml_essentials/gates.py
Unitary Gates#
Collection of unitary quantum gates with optional noise simulation.
Source code in qml_essentials/unitary.py
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 | |
CPhase(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled phase shift gate with optional noise.
This is a generalization of the CZ gate, applying a phase shift of exp(i*w) to the |11⟩ state. When w=π, this reduces to CZ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Phase shift angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CRX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled X-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CRY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled Y-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CRZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled Z-rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CX(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-NOT (CNOT) gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CY(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Y gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
CZ(wires, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Z gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Control and target qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
GateError(w, noise_params=None, random_key=None)
staticmethod
#
Apply gate error noise to rotation angle(s).
Adds Gaussian noise to gate rotation angles to simulate imperfect gate implementations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle(s) in radians. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Dictionary with optional "GateError" key specifying standard deviation of Gaussian noise. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for stochastic noise generation. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, PRNGKey]
|
Tuple[jnp.ndarray, jax.random.PRNGKey]: Tuple containing: - Modified rotation angle(s) with applied noise - Updated JAX random key |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If noise_params contains "GateError" but random_key is None. |
Source code in qml_essentials/unitary.py
GolombEncoding(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply Golomb encoding as a diagonal unitary on all given wires.
Implements S(x) = exp(-i H x) where
H = diag(g_0, g_1, ..., g_{d-1}) and the g_j are the marks
of a Golomb ruler of order d = 2^len(wires). This produces a
maximally non-degenerate Fourier spectrum with
|\Omega| = d(d-1) + 1 distinct frequencies, each with degeneracy
|R(k)| = 1.
See Peters et al., arXiv:2209.05523, Sec. 3.1 and Appendix C.4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray]
|
Scalar input value (the data point x to encode). |
required |
wires
|
Union[int, List[int]]
|
Qubit indices this encoding acts on. All qubits are acted upon simultaneously via a single multi-qubit diagonal gate. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Optional noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for stochastic noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
H(wires, noise_params=None, random_key=None)
staticmethod
#
Apply Hadamard gate with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
NQubitDepolarizingChannel(p, wires)
staticmethod
#
Generate Kraus operators for n-qubit depolarizing channel.
The n-qubit depolarizing channel models uniform depolarizing noise acting on n qubits simultaneously, useful for simulating realistic multi-qubit noise affecting entangling gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Total probability of depolarizing error (0 ≤ p ≤ 1). |
required |
wires
|
List[int]
|
Qubit indices on which the channel acts. Must contain at least 2 qubits. |
required |
Returns:
| Type | Description |
|---|---|
QubitChannel
|
op.QubitChannel: QubitChannel with Kraus operators representing the depolarizing noise channel. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If p is not in [0, 1] or if fewer than 2 qubits provided. |
Source code in qml_essentials/unitary.py
Noise(wires, noise_params=None)
staticmethod
#
Apply noise channels to specified qubits.
Applies various single-qubit and multi-qubit noise channels based on the provided noise parameters dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices to apply noise to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Dictionary of noise parameters. Supported keys: - "BitFlip" (float): Bit flip error probability - "PhaseFlip" (float): Phase flip error probability - "Depolarizing" (float): Single-qubit depolarizing probability - "MultiQubitDepolarizing" (float): Multi-qubit depolarizing probability (applies if len(wires) > 1) All parameters default to 0.0 if not provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Noise channels are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
PauliRot(theta, pauli, wires, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation gate with optional noise.
Applies a three-angle rotation Rot(phi, theta, omega) with optional gate errors and noise channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
Union[float, ndarray, List[float]]
|
Second rotation angle. |
required |
pauli
|
str
|
Pauli operator to apply. Must be "X", "Y", or "Z". |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. Supports BitFlip, PhaseFlip, Depolarizing, and GateError. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply X-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RXX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit XX rotation with optional noise.
Implements RXX(theta) = exp(-i theta/2 X ⊗ X).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply Y-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RYY(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit YY rotation with optional noise.
Implements RYY(theta) = exp(-i theta/2 Y ⊗ Y).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply Z-axis rotation with optional noise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RZX(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit ZX rotation with optional noise.
Implements RZX(theta) = exp(-i theta/2 Z ⊗ X), with Z acting
on the first wire and X on the second wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
RZZ(w, wires, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit ZZ rotation with optional noise.
Implements RZZ(theta) = exp(-i theta/2 Z ⊗ Z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
Union[float, ndarray, List[float]]
|
Rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Two qubit indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
Rot(phi, theta, omega, wires, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation gate with optional noise.
Applies a three-angle rotation Rot(phi, theta, omega) with optional gate errors and noise channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
Union[float, ndarray, List[float]]
|
First rotation angle. |
required |
theta
|
Union[float, ndarray, List[float]]
|
Second rotation angle. |
required |
omega
|
Union[float, ndarray, List[float]]
|
Third rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. Supports BitFlip, PhaseFlip, Depolarizing, and GateError. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate and noise are applied in-place to the circuit. |
Source code in qml_essentials/unitary.py
Pulse Gates#
Pulse-level implementations of quantum gates.
Implements quantum gates using time-dependent Hamiltonians and pulse
sequences, following the approach from https://doi.org/10.5445/IR/1000184129.
The active pulse envelope is selected via
:meth:PulseInformation.set_envelope.
Attributes:
| Name | Type | Description |
|---|---|---|
omega_q |
Qubit frequency (10π). |
|
omega_c |
Carrier frequency (10π). |
|
_active_envelope |
str
|
Name of the currently active envelope shape. |
Source code in qml_essentials/pulses.py
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 | |
CPhase(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled phase shift via decomposition.
Decomposes CPhase(φ) into RZ and CX gates: RZ(φ/2) on control, RZ(φ/2) on target, CX, RZ(-φ/2) on target, CX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Phase shift angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in qml_essentials/pulses.py
CRX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RX via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in qml_essentials/pulses.py
CRY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RY via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in qml_essentials/pulses.py
CRZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-RZ via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in qml_essentials/pulses.py
CX(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply CNOT gate via decomposition: H(target) · CZ · H(target).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate is applied in-place to the circuit. |
Source code in qml_essentials/pulses.py
CY(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Y via decomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices [control, target]. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in qml_essentials/pulses.py
CZ(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply controlled-Z using ZZ coupling Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
List[int]
|
Control and target qubit indices. |
required |
pulse_params
|
Optional[float]
|
Time or duration parameter for the pulse evolution. If None, uses optimized value. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in qml_essentials/pulses.py
H(wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Hadamard gate using pulse decomposition.
Decomposes as RZ(π) · RY(π/2) followed by a correction phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility (not used in this gate). |
None
|
Source code in qml_essentials/pulses.py
PauliRot(pauli, theta, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Not implemented as a PulseGate.
Source code in qml_essentials/pulses.py
RX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply X-axis rotation using the active pulse envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
pulse_params
|
Optional[ndarray]
|
Envelope parameters |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in qml_essentials/pulses.py
RXX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RXX rotation via decomposition.
Implements RXX(theta) = exp(-i theta/2 X ⊗ X) as
(H ⊗ H) · RZZ(theta) · (H ⊗ H).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in qml_essentials/pulses.py
RY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Y-axis rotation using the active pulse envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices. |
required |
pulse_params
|
Optional[ndarray]
|
Envelope parameters |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Source code in qml_essentials/pulses.py
RYY(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RYY rotation via decomposition.
Implements RYY(theta) = exp(-i theta/2 Y ⊗ Y) by conjugating the
RZZ skeleton with RX(pi/2) rotations on both wires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in qml_essentials/pulses.py
RZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply Z-axis rotation using pulse-level implementation.
Implements RZ rotation using virtual Z rotations (phase tracking) without physical pulse application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
pulse_params
|
Optional[float]
|
Duration parameter for the pulse. Rotation angle = w * 2 * pulse_params. Defaults to 0.5 if None. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gate is applied in-place to the circuit. |
Source code in qml_essentials/pulses.py
RZX(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RZX rotation via decomposition.
Implements RZX(theta) = exp(-i theta/2 Z ⊗ X) (Z on the first
wire, X on the second) by conjugating the RZZ skeleton with a
Hadamard on the target wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in qml_essentials/pulses.py
RZZ(w, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply two-qubit RZZ rotation via decomposition.
Implements RZZ(theta) = exp(-i theta/2 Z ⊗ Z) as
CX · RZ(theta)_target · CX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
float
|
Rotation angle in radians. |
required |
wires
|
List[int]
|
Two qubit indices. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for noise. |
None
|
Source code in qml_essentials/pulses.py
Rot(phi, theta, omega, wires, pulse_params=None, noise_params=None, random_key=None)
staticmethod
#
Apply general rotation via decomposition: RZ(phi) · RY(theta) · RZ(omega).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
float
|
First rotation angle. |
required |
theta
|
float
|
Second rotation angle. |
required |
omega
|
float
|
Third rotation angle. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or indices to apply rotation to. |
required |
pulse_params
|
Optional[ndarray]
|
Pulse parameters for the composing gates. If None, uses optimized parameters. |
None
|
noise_params
|
Optional[Dict[str, float]]
|
Noise parameters dictionary. |
None
|
random_key
|
Optional[PRNGKey]
|
JAX random key for compatibility |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Gates are applied in-place to the circuit. |
Source code in qml_essentials/pulses.py
Pulse Structure#
Container for hierarchical pulse parameters.
Leaf nodes hold direct parameters; composite nodes hold a list of
:class:DecompositionStep objects that describe how the gate is
built from simpler gates.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Gate identifier (e.g. |
|
decomposition |
List of :class: |
Source code in qml_essentials/pulses.py
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 | |
childs
property
#
Get direct children of this node.
Returns:
| Type | Description |
|---|---|
List[PulseParams]
|
List[PulseParams]: List of child PulseParams objects, or empty list if this is a leaf node. |
is_leaf
property
#
Check if this is a leaf node (direct parameters, no children).
leaf_params
property
writable
#
Get parameters from all leaf nodes.
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Concatenated parameters from all leaf nodes. |
leafs
property
#
Get all leaf nodes in the hierarchy.
Recursively collects all leaf PulseParams objects in the tree.
Returns:
| Type | Description |
|---|---|
List[PulseParams]
|
List[PulseParams]: List of unique leaf nodes. |
params
property
writable
#
Get or compute pulse parameters.
For leaf nodes, returns internal pulse parameters. For composite nodes, returns concatenated parameters from all children.
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Pulse parameters array. |
shape
property
#
Get the shape of pulse parameters.
For leaf nodes, returns list with parameter count. For composite nodes, returns nested list of child shapes.
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: Parameter shape specification. |
size
property
#
Get the total parameter count (alias for len).
__getitem__(idx)
#
Access pulse parameter(s) by index.
For leaf gates, returns the parameter at the given index. For composite gates, returns parameters of the child at the given index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index to access. |
required |
Returns:
| Type | Description |
|---|---|
Union[float, ndarray]
|
Union[float, jnp.ndarray]: Parameter value or child parameters. |
Source code in qml_essentials/pulses.py
__init__(name='', params=None, decomposition=None)
#
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Gate name. |
''
|
params
|
Optional[ndarray]
|
Direct pulse parameters (leaf gates). Mutually exclusive with decomposition. |
None
|
decomposition
|
Optional[List[DecompositionStep]]
|
List of :class: |
None
|
Source code in qml_essentials/pulses.py
__len__()
#
Get the total number of pulse parameters.
For composite gates, returns the accumulated count from all children.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Total number of pulse parameters. |
__repr__()
#
__str__()
#
split_params(params=None, leafs=False)
#
Split parameters into sub-arrays for children or leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Optional[ndarray]
|
Parameters to split. If None, uses internal parameters. |
None
|
leafs
|
bool
|
If True, splits across leaf nodes; if False, splits across direct children. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List[jnp.ndarray]: List of parameter arrays for children or leaves. |
Source code in qml_essentials/pulses.py
Pulse Envelope#
Registry of pulse envelope shapes.
Each envelope is a pure function (p, t, t_c) -> amplitude that
computes the pulse envelope without carrier modulation. The carrier
cos(omega_c * t + phi_c) is applied separately in the coefficient
functions built by :meth:build_coeff_fns.
Attributes:
| Name | Type | Description |
|---|---|---|
REGISTRY |
Mapping from envelope name to metadata dict containing
|
Source code in qml_essentials/pulses.py
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 | |
available()
staticmethod
#
build_coeff_fns(envelope_fn, omega_c, omega_q, rwa=True, frame='drive')
staticmethod
#
Build the four interaction-picture coefficient functions.
The lab-frame Hamiltonian is
H(t,Π) = H_static + Σ_j S_j(t;Π) H_j ,
S_j(t;Π) = E_j(t;Π) · cos(ω_c·t + φ_c) ,
and the interaction-picture transform with respect to
H_static = (ω_q/2)·Z produces
H̃_j(t) = exp(+i H_static t) H_j exp(-i H_static t) ,
H_I(t) = Σ_j S_j(t) H̃_j(t) .
For a single qubit driven on X, H̃_X(t) = cos(ω_q·t) X
− sin(ω_q·t) Y, so
H_I(t) = Ω(t) · cos(ω_c·t + φ) ·
[ cos(ω_q·t) · X − sin(ω_q·t) · Y ] .
rwa=True (default) drops the fast (~2·ω_q on resonance) terms and
keeps only the slow envelope, yielding the analytical RWA
H_I^RWA(t) = (Ω(t)/2) · [ cos(φ) X + sin(φ) Y ] .
For RX (φ = 0) this reduces to (Ω/2)·X; for RY
(φ = +π/2) to (Ω/2)·Y. This is dramatically cheaper to
integrate (no fast oscillations → adaptive ODE solver takes
large steps).
rwa=False keeps both the slow and the fast
counter-rotating components.
Each returned function has a unique __code__ object so the
jaqsi solver cache assigns separate compiled XLA programs per
envelope shape and per (gate, component) pair.
The rotation angle w is expected as the last element of
the parameter array p (i.e. p[-1]). Envelope parameters
occupy p[:-1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope_fn
|
Callable
|
Pure envelope function |
required |
omega_c
|
float
|
Carrier frequency. |
required |
omega_q
|
float
|
Qubit frequency (interaction-picture rotation rate). |
required |
rwa
|
bool
|
When |
True
|
frame
|
str
|
Algebraic representation of the exact (non-RWA) coefficients. Mathematically equivalent options:
Ignored when |
'drive'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Tuple |
Callable
|
of coefficient functions for the X- and Y-components of the |
Callable
|
RX and RY interaction-picture Hamiltonians. |
Source code in qml_essentials/pulses.py
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 | |
cosine(p, t, t_c)
staticmethod
#
drag(p, t, t_c)
staticmethod
#
DRAG (Derivative Removal by Adiabatic Gate). p = [A, beta, sigma].
Source code in qml_essentials/pulses.py
gaussian(p, t, t_c)
staticmethod
#
get(name)
staticmethod
#
Look up envelope metadata by name.
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not registered. |
Source code in qml_essentials/pulses.py
sech(p, t, t_c)
staticmethod
#
Pulse Information#
Stores pulse parameter counts and optimized pulse parameters.
Call :meth:set_envelope to switch the active pulse shape. This
rebuilds all :class:PulseParams trees so that parameter counts
and defaults match the selected envelope.
Source code in qml_essentials/pulses.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 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 | |
get_envelope()
classmethod
#
get_frame()
classmethod
#
get_rwa()
classmethod
#
preserve_state()
classmethod
#
Temporarily preserve global pulse state across scoped mutations.
reset_defaults(envelope=None, rwa=None, frame=None)
classmethod
#
Reset pulse globals to canonical defaults or explicit values.
Source code in qml_essentials/pulses.py
restore_state(snapshot)
classmethod
#
Restore a snapshot produced by :meth:snapshot_state.
Source code in qml_essentials/pulses.py
set_envelope(name, rwa=None, frame=None)
classmethod
#
Switch pulse envelope and rebuild all PulseParams trees.
Also updates the coefficient functions used by :class:PulseGates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
One of :meth: |
required |
rwa
|
Optional[bool]
|
If given, also update the RWA flag. If |
None
|
frame
|
Optional[str]
|
If given, also update the coefficient frame
( |
None
|
Source code in qml_essentials/pulses.py
set_frame(frame)
classmethod
#
Switch the algebraic representation of the (non-RWA) coefficients.
"lab" (default) and "drive" are mathematically
identical (no information lost, no RWA applied) — see
:meth:PulseEnvelope.build_coeff_fns for when "drive" is
useful. Rebuilds the coefficient functions for the currently
active envelope so the change takes effect immediately.
Source code in qml_essentials/pulses.py
set_rwa(rwa)
classmethod
#
Toggle the rotating-wave approximation for pulse coefficients.
Rebuilds the coefficient functions for the currently active
envelope so the change takes effect immediately. Default is
False (exact interaction picture).
See :meth:PulseEnvelope.build_coeff_fns for details
Source code in qml_essentials/pulses.py
snapshot_state()
classmethod
#
Return an immutable snapshot of the active pulse configuration.
Source code in qml_essentials/pulses.py
Model#
A quantum circuit model.
Source code in qml_essentials/model.py
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 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 | |
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). If the model was not called before, it returns (1, 1, 1).
Returns:
| Type | Description |
|---|---|
Tuple[int, ...]
|
Tuple[int, ...]: Tuple of (input_batch, param_batch, pulse_batch). Returns (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.
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. |
output_qubit
property
writable
#
Get the output qubit indices for measurement.
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='unitary')
#
Execute the quantum circuit (callable interface).
Provides a convenient callable interface for circuit execution, delegating to the _forward method.
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 pulse-mode gate execution. |
None
|
enc_params
|
Optional[ndarray]
|
Encoding parameters of shape (n_qubits, n_input_feat). If None, uses model's encoding parameters. |
None
|
data_reupload
|
Union[bool, List[List[bool]], List[List[List[bool]]]]
|
Data reupload configuration. If None, uses previously set reupload configuration. |
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
|
str
|
Gate execution backend, "unitary" or "pulse". Defaults to "unitary". |
'unitary'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Circuit output with shape depending on execution_type: - "expval": (n_output_qubits,) or scalar - "density": (2^n_output, 2^n_output) - "probs": (2^n_output,) or (n_pairs, 2^pair_size) - "state": (2^n_qubits,) |
Source code in qml_essentials/model.py
__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=-1, shots=None, random_seed=1000, remove_zero_encoding=True, repeat_batch_axis=[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'
|
data_reupload
|
Union[bool, List[bool], List[List[bool]]]
|
Whether to reupload data to the quantum device on each layer and qubit. Detailed re-uploading instructions can be given as a list/array of 0/False and 1/True with shape (n_qubits, n_layers) to specify where to upload the data. Defaults to True for applying data re-uploading to the full circuit. |
True
|
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. op.RX). Defaults to op.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)
|
The index of the output qubit (or qubits). When set to -1 all qubits are measured, or a global measurement is conducted, depending on the execution type. |
-1
|
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
|
remove_zero_encoding
|
bool
|
whether to remove the zero encoding from the circuit. Defaults to True. |
True
|
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]. Defaults to [True, True, True], meaning that batching is enabled over all axes. |
[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
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 | |
__repr__()
#
__str__()
#
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.
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 (single input
feature only) 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
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 | |
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
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 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 | |
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
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 | |
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
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 | |
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
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 | |
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
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 | |
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 | |
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 2. |
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. |
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
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 | |
__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 the achievable input sine/cosine count pairs(s, c)per state. The support is the union of the (exact) expansion supports of :math:\cos^c x\, (i \sin x)^sover all achievable pairs. 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. Currently restricted to a single input feature.
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
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 | |
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
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 | |
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
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 | |
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]: The fourier fingerprint and the |
ndarray
|
corresponding frequency indices. If |
Tuple[ndarray, ndarray]
|
frequencies are returned as a |
Tuple[ndarray, ndarray]
|
labels the two (redundancy-trimmed) matrix axes; otherwise the |
Tuple[ndarray, ndarray]
|
full frequency vector is returned. |
Source code in qml_essentials/coefficients.py
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 | |
Datasets#
Source code in qml_essentials/coefficients.py
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 | |
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
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 | |
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
7 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 | |
all_to_all(n_qubits)
classmethod
#
Every ordered pair (i, j) with i ≠ j.
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
Operations#
Base class for any quantum operation or observable.
Further gates should inherit from this class to realise more specific
operations. Generally, operations are created by instantiation inside a
circuit function passed to :class:Script; the instance is
automatically appended to the active tape.
An Operation can also serve as an observable: its matrix is used to
compute expectation values via apply_to_state / apply_to_density.
Attributes:
| Name | Type | Description |
|---|---|---|
_matrix |
ndarray
|
Class-level default gate matrix. Subclasses set this to their
fixed unitary. Instances may override it via the matrix argument
to |
_num_wires |
Optional[int]
|
Expected number of wires for this gate. Subclasses set
this to enforce wire count validation. |
_param_names |
Tuple[str, ...]
|
Tuple of attribute names for the gate parameters.
Used by :attr: |
Source code in qml_essentials/operations.py
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 | |
matrix
property
#
Return the base matrix of this operation (before lifting).
Returns:
| Type | Description |
|---|---|
ndarray
|
The gate matrix as a JAX array. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the subclass has not defined |
parameters
property
#
Return the list of numeric parameters for this operation.
Uses the declarative _param_names tuple to collect parameter
values in a canonical order. Non-parametrized gates return an
empty list.
Returns:
| Type | Description |
|---|---|
list
|
List of parameter values (floats or JAX arrays). |
wires
property
writable
#
Qubit indices this operation acts on.
Returns:
| Type | Description |
|---|---|
List[int]
|
List of integer qubit indices. |
__add__(other)
#
Element-wise addition of two operations on the same wires.
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the wire sets differ. |
Source code in qml_essentials/operations.py
__init__(wires=0, matrix=None, record=True, name=None)
#
Initialise the operation and optionally register it on the active tape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this operation acts on. |
0
|
matrix
|
Optional[ndarray]
|
Optional explicit gate matrix. When provided it overrides
the class-level |
None
|
record
|
bool
|
If |
True
|
name
|
Optional[str]
|
Optional explicit name for this operation. When |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in qml_essentials/operations.py
__matmul__(other)
#
Tensor (Kronecker) product or matrix product of two operations.
The resulting operation acts on the union of both wire sets. If the wire sets are disjoint, this is a Kronecker product. If the wire sets overlap, the corresponding matrices are multiplied.
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Operation
|
operation on the unified wire set. |
Source code in qml_essentials/operations.py
__mul__(other)
#
Return a new operation, the product between U and a scalar (U*x)
or the composition of two operations.
Usage inside a circuit function::
PauliX(wires=0) * x
PauliX(wires=0) * PauliZ(wires=0)
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Operation
|
or the composed matrix acting on the appropriate wires. |
Source code in qml_essentials/operations.py
__repr__()
#
Return a human-readable representation of this operation.
Returns:
| Type | Description |
|---|---|
str
|
A string like |
Source code in qml_essentials/operations.py
apply_to_density(rho, n_qubits)
#
Apply this gate to a density matrix via \rho -> U\rho U\dagger.
The density matrix (shape (2**n, 2**n)) is treated as a rank-2n
tensor with n "ket" axes (0..n-1) and n "bra" axes (n..2n-1).
U acts on the ket half; U* acts on the bra half. Both contractions
use the shared :func:_contract_and_restore helper, keeping the
operation allocation-free with respect to building full unitaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
ndarray
|
Density matrix of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated density matrix of shape |
Source code in qml_essentials/operations.py
apply_to_state(state, n_qubits)
#
Apply this gate to a statevector via tensor contraction.
The statevector (shape (2**n,)) is reshaped into a rank-n tensor
of shape (2,)*n. The gate (shape (2**k, 2**k)) is reshaped to
(2,)*2k and contracted against the k target wire axes.
Memory footprint is O(2**n) and the operation supports arbitrary k. The implementation is fully differentiable through JAX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
Statevector of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated statevector of shape |
Source code in qml_essentials/operations.py
apply_to_state_tensor(psi, n_qubits)
#
Apply this gate to a statevector already in tensor form.
Like :meth:apply_to_state but expects the state in rank-n tensor
form (2,)*n and returns the result in the same form. This avoids
the reshape calls at the per-gate level when the simulation loop
keeps the state in tensor form throughout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
ndarray
|
Statevector tensor of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated statevector tensor of shape |
Source code in qml_essentials/operations.py
dagger()
#
Return a new operation, the conjugate transpose (U\dagger)
Usage inside a circuit function::
RX(0.5, wires=0).dagger()
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in qml_essentials/operations.py
decompose()
#
Decompose this operation into a list of more primitive operations.
The returned operations are created with record=False so the caller
controls where they are placed. Reused e.g. by
:meth:~qml_essentials.pauli.PauliCircuit.get_clifford_pauli_gates to
express composite gates in terms of Clifford + Pauli-rotation primitives.
Returns:
| Type | Description |
|---|---|
List[Operation]
|
List of :class: |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the gate has no decomposition (it is itself primitive). |
Source code in qml_essentials/operations.py
lifted_matrix(n_qubits)
#
Return the full 2**n x 2**n matrix embedding this gate.
Embeds the k-qubit gate matrix into the n-qubit Hilbert space
by applying it to the identity matrix via :meth:apply_to_state.
This is useful for computing Tr(O·\rho ) directly without vmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The |
Source code in qml_essentials/operations.py
power(power)
#
Return a new operation, the power (U^power)
Usage inside a circuit function::
PauliX(wires=0).power(2)
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in qml_essentials/operations.py
prod(*ops)
#
Construct the generalized product (tensor or matrix) of this operation with others.
The resulting operation acts on the union of all wire sets. If the wire sets are disjoint, this is a Kronecker product. If the wire sets overlap, the corresponding matrices are multiplied.
Usage::
res = op1.prod(op2, op3)
# or
res = Operation.prod(op1, op2, op3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*ops
|
Operation
|
Variable number of :class: |
()
|
Returns:
| Type | Description |
|---|---|
Operation
|
A new :class: |
Source code in qml_essentials/operations.py
Hermitian#
Bases: Operation
A generic Hermitian observable or gate defined by an arbitrary matrix.
Example
obs = Hermitian(matrix=my_matrix, wires=0)
Source code in qml_essentials/operations.py
__init__(matrix, wires=0, record=True)
#
Initialise a Hermitian operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
The Hermitian matrix defining this operator. |
required |
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this operator acts on. |
0
|
record
|
bool
|
If |
True
|
Source code in qml_essentials/operations.py
__rmul__(coeff_fn)
#
Support coeff_fn * Hermitian -> :class:ParametrizedHamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff_fn
|
Callable
|
A callable |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ParametrizedHamiltonian |
ParametrizedHamiltonian
|
A :class: |
Raises:
| Type | Description |
|---|---|
TypeError
|
If coeff_fn is not callable. |
Source code in qml_essentials/operations.py
evolve(name=None, **odeint_kwargs)
#
Return a gate factory for static evolution U = exp(-i t H).
Thin delegator to :meth:qml_essentials.evolution.Evolution.evolve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Optional name for the produced :class: |
None
|
**odeint_kwargs
|
Unused for static evolution (accepted for a
uniform signature with :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory |
Source code in qml_essentials/operations.py
Kraus Channel#
Bases: Operation
Base class for noise channels defined by a set of Kraus operators.
A Kraus channel \phi(\rho ) = \sigma_k K_k \rho K_k\dagger is the most general physical operation on a quantum state. For a pure unitary gate there is a single operator K_0 = U satisfying K_0\daggerK_0 = I; for noisy channels there are multiple operators.
Subclasses must implement :meth:kraus_matrices and return a list of JAX
arrays. :meth:apply_to_state is intentionally left unimplemented:
Kraus channels require a density-matrix representation and cannot be
applied to a pure statevector in general.
Source code in qml_essentials/operations.py
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 | |
matrix
property
#
Raises TypeError — noise channels have no single unitary matrix.
Raises:
| Type | Description |
|---|---|
TypeError
|
Always raised; use :meth: |
apply_to_density(rho, n_qubits)
#
Apply \phi(\rho ) = \sigma_k K_k \rho K_k\dagger using tensor-contraction.
Uses the shared :func:_contract_and_restore helper, summing the
result over all Kraus operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
ndarray
|
Density matrix of shape |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Updated density matrix of shape |
Source code in qml_essentials/operations.py
apply_to_state(state, n_qubits)
#
Raises TypeError — noise channels require density-matrix simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
ndarray
|
Statevector (unused). |
required |
n_qubits
|
int
|
Number of qubits (unused). |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
Always raised; use |
Source code in qml_essentials/operations.py
apply_to_state_tensor(psi, n_qubits)
#
Raises TypeError — noise channels require density-matrix simulation.
Source code in qml_essentials/operations.py
kraus_matrices()
#
Return the list of Kraus operators for this channel.
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
List of 2-D JAX arrays, each of shape |
List[ndarray]
|
is the number of target qubits. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Subclasses must override this method. |
Source code in qml_essentials/operations.py
Parametrized Hamiltonian#
A time-dependent Hamiltonian as a sum of coeff * Hermitian terms.
Mathematically::
H(t) = \sum_i f_i(params_i, t) * H_i
Construction is always done from an explicit list of
(coeff_fn, H_mat, wires) triples passed as terms. The
common single-term shorthand is the operator form
coeff_fn * Hermitian(matrix, wires) (see
:meth:Hermitian.__rmul__), which returns a one-term instance.
Multi-term Hamiltonians are composed with + between
:class:ParametrizedHamiltonian instances::
H1 = coeff_x * Hermitian(X, wires=0)
H2 = coeff_y * Hermitian(Y, wires=0)
H_td = H1 + H2
# evolve under the composite Hamiltonian; coeff_args is a list of
# parameter sets, one per term, in the order the terms were added:
H_td.evolve()([px, py], T=1.0)
Attributes:
| Name | Type | Description |
|---|---|---|
coeff_fns |
Tuple[Callable, ...]
|
Tuple of callables |
H_mats |
Tuple[ndarray, ...]
|
Tuple of static Hermitian matrices, one per term. |
wires |
List[int]
|
Wires this Hamiltonian acts on (union across all terms; for now all terms are required to share the same wire set). |
Source code in qml_essentials/operations.py
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 | |
H_mats
property
#
Tuple of Hermitian matrices, one per term.
coeff_fns
property
#
Tuple of coefficient functions, one per term.
n_terms
property
#
Number of terms in the Hamiltonian.
__add__(other)
#
Concatenate term lists: H = H1 + H2.
Source code in qml_essentials/operations.py
__init__(terms)
#
Build a (possibly multi-term) parametrized Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terms
|
List[Tuple[Callable, ndarray, Union[int, List[int]]]]
|
List of |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the term list is empty, or if terms act on
differing wire sets (multi-wire broadcasting is
deferred — see :mod: |
Source code in qml_essentials/operations.py
__neg__()
#
Negate every coefficient: -H = sum of (-f_i) * H_i.
Source code in qml_essentials/operations.py
evolve(name=None, **odeint_kwargs)
#
Return a gate factory for time-dependent evolution.
Solves dU/dt = -i [sum_i f_i(p_i, t) H_i] U. Thin delegator to
:meth:qml_essentials.evolution.Evolution.evolve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
Optional name for the produced :class: |
None
|
**odeint_kwargs
|
Solver options forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory |
Source code in qml_essentials/operations.py
Pauli Rotation#
Bases: Operation
Multi-qubit Pauli rotation: exp(-i \theta/2 P) for a Pauli word P.
The Pauli word is given as a string of 'I', 'X', 'Y', 'Z'
characters (one per qubit). The rotation matrix is computed as
cos(\theta/2) I - i sin(\theta/2) P where P is the tensor product of the
corresponding single-qubit Pauli matrices.
Example::
PauliRot(0.5, "XY", wires=[0, 1])
Source code in qml_essentials/operations.py
__init__(theta, pauli_word, wires=0, **kwargs)
#
Initialise a PauliRot gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Rotation angle in radians. |
required |
pauli_word
|
str
|
A string of |
required |
wires
|
Union[int, List[int]]
|
Qubit index or list of qubit indices this gate acts on. |
0
|
Source code in qml_essentials/operations.py
generator()
#
Return the generator Pauli tensor product as an :class:Operation.
The generator of PauliRot(\theta, word, wires) is the tensor product
of single-qubit Pauli matrices specified by word. The returned
:class:Hermitian wraps that matrix and the gate's wires.
Returns:
| Type | Description |
|---|---|
Operation
|
class: |
Source code in qml_essentials/operations.py
Pauli Word#
Symbolic n-qubit Pauli operator in the stabilizer-tableau (symplectic) representation.
A Pauli word is stored as
.. math:: P = i^{\text{phase}} \prod_{q} X_q^{x_q} Z_q^{z_q},
with bit arrays x, z \in \{0, 1\}^n and an integer phase taken mod 4
(tracking the scalar i^{phase}). Single-qubit Paulis map as
I=(0,0), X=(1,0), Z=(0,1), Y=(1,1) (since Y = i X Z).
This replaces the matrix-based Clifford conjugation
(:func:evolve_pauli_with_clifford + :func:pauli_decompose) with O(n)
symbolic updates, and is shared by both
:class:~qml_essentials.pauli.PauliCircuit and the Fourier-tree algorithm.
All operations use NumPy (integer arithmetic), not JAX — this is symbolic bookkeeping, not numeric computation.
Source code in qml_essentials/operations.py
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 | |
is_diagonal
property
#
Whether the word is diagonal (only I/Z, i.e. no X component).
n_qubits
property
#
Number of qubits this Pauli word spans.
xy_mask
property
#
Boolean mask of qubits carrying an X or Y (i.e. x bits set).
__init__(x, z, phase=0)
#
Initialise a Pauli word.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Integer/boolean array of X-component bits, length |
required |
z
|
ndarray
|
Integer/boolean array of Z-component bits, length |
required |
phase
|
int
|
Exponent of the global |
0
|
Source code in qml_essentials/operations.py
commutes_with(other)
#
Return whether this Pauli word commutes with other.
Two Paulis commute iff their symplectic inner product vanishes mod 2.
Source code in qml_essentials/operations.py
compose(other)
#
Return the operator product self @ other as a new Pauli word.
Uses the exact symplectic product rule
.. math:: (X^{x_1} Z^{z_1})(X^{x_2} Z^{z_2}) = (-1)^{z_1 \cdot x_2}\, X^{x_1 \oplus x_2} Z^{z_1 \oplus z_2},
combined with the i^{phase} scalars (-1 = i^2).
Source code in qml_essentials/operations.py
conjugate_by_clifford(clifford, adjoint_left=False)
#
Return the Clifford conjugation of this Pauli word.
Computes C P C^\dagger (adjoint_left=False) or
C^\dagger P C (adjoint_left=True) symbolically, where C is one
of the supported Clifford gates H, S, CX, CZ or a Pauli gate
PauliX/PauliY/PauliZ.
The conjugation is realised by substituting the images of the
single-qubit generators X_q and Z_q and re-composing in canonical
order, so all phases are tracked exactly by :meth:compose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clifford
|
Operation
|
The Clifford operation to conjugate by. |
required |
adjoint_left
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
PauliWord
|
The conjugated :class: |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If clifford is not a supported gate. |
Source code in qml_essentials/operations.py
from_matrix(matrix)
classmethod
#
Build a Pauli word from a matrix that is a single (signed) Pauli.
Recovers the dominant Pauli string and folds its (unit) coefficient
c = i^k into the word's phase. Intended for matrices that are
exactly a Pauli up to a {\pm 1, \pm i} scalar (e.g. the result of
Clifford conjugation of a Pauli); the dominant term is returned for
general inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
A |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in qml_essentials/operations.py
from_operation(op, n_qubits)
classmethod
#
Build a Pauli word from a Pauli-like operation.
Supports :class:PauliX/:class:PauliY/:class:PauliZ/:class:Id,
:class:PauliRot (via its pauli_word), and any operation carrying a
_pauli_label (e.g. produced by :func:pauli_decompose) or otherwise
decomposable by :func:pauli_string_from_operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
Operation
|
The operation to convert. |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in qml_essentials/operations.py
from_pauli_string(pauli_string, wires, n_qubits)
classmethod
#
Build a Pauli word from a Pauli string and its wires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pauli_string
|
str
|
String over |
required |
wires
|
List[int]
|
Qubit indices the characters act on. |
required |
n_qubits
|
int
|
Total number of qubits in the circuit. |
required |
Returns:
| Type | Description |
|---|---|
PauliWord
|
The corresponding :class: |
Source code in qml_essentials/operations.py
identity(n_qubits)
classmethod
#
leading_phase()
#
Return the scalar c such that P = c * (bare Pauli string).
Because the bare string already contains i^{n_Y} from its Y factors,
c = i^{phase - n_Y}.
Source code in qml_essentials/operations.py
to_list_repr()
#
Return the legacy int list representation (I=-1, X=0, Y=1, Z=2).
Source code in qml_essentials/operations.py
to_matrix()
#
Return the dense operator matrix i^{phase} \bigotimes_q X^{x_q} Z^{z_q}.
The per-qubit factor is the symplectic product X^{x} Z^{z} (so the
(1, 1) factor is XZ = -iY; the Y-vs-XZ phase is carried by
i^{phase}). Inverse of :meth:from_matrix.
Source code in qml_essentials/operations.py
to_pauli_string()
#
Return the bare Pauli string (ignoring the global phase).
to_pauli_string_and_phase()
#
zero_expectation()
#
Return <0|P|0> for the all-zero computational basis state.
Non-zero only for diagonal words (I/Z only), in which case it equals the
global phase i^{phase}.
Source code in qml_essentials/operations.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
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 | |
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).
Math#
from qml_essentials.math import quantum_fisher_information, fubini_study_metric, fidelity, trace_distance, phase_difference
Compute the Quantum Fisher Information (QFI) at a parameter point.
The QFI is the metric tensor of the state manifold evaluated at
params. It therefore requires the state as a function of the
parameters rather than a single state; the Jacobian is obtained with
forward-mode automatic differentiation (:func:jax.jacfwd), which yields
the complex Jacobian directly for real-valued parameters.
Both pure and mixed states are supported and dispatched on the kind of
object returned by state_fn (state vector vs. density matrix), mirroring
:func:fidelity:
- state vector of shape
(d,)-> Fubini-Study formula (see :func:_qfi_statevector), - density matrix of shape
(d, d)-> symmetric logarithmic derivative formula (see :func:_qfi_density).
The returned matrix has shape (P, P) where P is the total number of
parameters (the parameter axes of params are flattened).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_fn
|
Callable mapping params to a normalised quantum state.
Typically |
required | |
params
|
ndarray
|
Parameters at which the QFI is evaluated. Must be passed in the
shape expected by state_fn (e.g. the model's batched
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Real, symmetric QFI matrix of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state_fn returns neither a state vector nor a square density matrix. |
Source code in qml_essentials/math.py
Compute the Fubini-Study metric tensor at a parameter point.
The Fubini-Study metric is the real part of the quantum geometric tensor on
the manifold of pure states and equals the pure-state quantum Fisher
information up to a factor of four, :math:F_{ij} = 4\,g_{ij}:
.. math::
g_{ij} = \mathrm{Re}\left[
\braket{\partial_i\psi | \partial_j\psi}
- \braket{\partial_i\psi | \psi}\braket{\psi | \partial_j\psi}
\right]
It is only defined for pure states; state_fn must therefore return a
normalised state vector. See :func:quantum_fisher_information for the
calling convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_fn
|
Callable mapping params to a normalised state vector.
Typically |
required | |
params
|
ndarray
|
Parameters at which the metric is evaluated. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Real, symmetric metric of shape |
ndarray
|
number of parameters. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state_fn does not return a state vector. |
Source code in qml_essentials/math.py
Compute the fidelity between two quantum states.
Accepts either state vectors or density matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
State vector or density matrix. |
required |
state1
|
ndarray
|
State vector or density matrix (same kind as state0). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Fidelity (scalar or shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the two states have incompatible shapes or different representations (vector vs. matrix). |
Source code in qml_essentials/math.py
Compute the trace distance between two quantum states.
Supports single density matrices of shape (2**N, 2**N) and batched
density matrices of shape (B, 2**N, 2**N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
Density matrix of shape |
required |
state1
|
ndarray
|
Density matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Trace distance (scalar or shape |
Source code in qml_essentials/math.py
Compute the phase difference between two state vectors.
A value of zero indicates the two states are related by at most a
real global factor (i.e. no relative phase). The result lies in
:math:[-\pi, 1 + \pi].
Supports single state vectors of shape (2**N,) and batched state
vectors of shape (B, 2**N).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state0
|
ndarray
|
State vector of shape |
required |
state1
|
ndarray
|
State vector of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Phase difference (scalar or shape |
Source code in qml_essentials/math.py
Quantum Optimal Control#
Quantum Optimal Control for pulse-level gate synthesis.
Optimises pulse parameters to reproduce the unitary of standard quantum gates using a two-stage strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
GATES_1Q |
List[str]
|
Names of supported single-qubit gates. |
GATES_2Q |
List[str]
|
Names of supported two-qubit gates. |
DEFAULT_PARAM_RANGES |
Default parameter ranges for each gate. |
Source code in qml_essentials/qoc.py
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 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 | |
__init__(envelope, cost_fns, t_target, n_steps, n_samples, learning_rate, log_interval=50, file_dir=None, warmup_ratio=0.0, end_lr_ratio=1.0, n_restarts=1, restart_noise_scale=0.5, grad_clip=1.0, random_seed=42, scan_steps=0, scan_grid_size=5, scan_ranges=None, log_scale_params=None, early_stop_patience=0, early_stop_min_delta=0.0, plot=False)
#
Initialize Quantum Optimal Control with Pulse-level Gates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
str
|
Pulse envelope shape to use for optimization. Must be one of the registered envelopes in PulseEnvelope (e.g. 'gaussian', 'square', 'cosine', 'drag', 'sech'). |
required |
cost_fns
|
list
|
List of |
required |
t_target
|
float
|
Target evolution time for the
|
required |
n_steps
|
int
|
Number of steps in optimization. |
required |
n_samples
|
int
|
Number of parameter samples per step. |
required |
learning_rate
|
float
|
Peak learning rate for AdamW. When a warmup/decay schedule is active this is the maximum LR reached after the warmup phase. |
required |
log_interval
|
int
|
Interval for logging. |
50
|
file_dir
|
str
|
Directory to save results. |
None
|
warmup_ratio
|
float
|
Fraction of |
0.0
|
end_lr_ratio
|
float
|
The final learning rate is
|
1.0
|
n_restarts
|
int
|
Number of random restarts for the optimisation. The first run uses the initial parameters as-is; subsequent runs add scaled random perturbations. The best result across all restarts is kept. Set to 1 to disable restarts (default behaviour). |
1
|
restart_noise_scale
|
float
|
Standard deviation of the
Gaussian noise added to the initial parameters for each
restart (relative to the absolute value of each parameter).
Defaults to 0.5 (50 % relative perturbation). Note that
the package-level default in |
0.5
|
grad_clip
|
float
|
Maximum global gradient norm. Gradients
are clipped to this value before being passed to the
optimiser, which stabilises training when the loss
landscape has steep regions. Set to |
1.0
|
random_seed
|
int
|
Base random seed for generating restart perturbations. Defaults to 42. |
42
|
scan_steps
|
int
|
Number of short gradient-descent steps to run for each candidate in the coarse grid search (Stage 0). Set to 0 to disable the grid scan entirely and rely solely on restarts. A value of 20-50 is usually enough to identify promising basins. Defaults to 0. |
0
|
scan_grid_size
|
int
|
Number of points per parameter
dimension in the coarse grid. The total number of
candidates is |
5
|
scan_ranges
|
Optional[List[Tuple[float, float]]]
|
Per-
parameter |
None
|
log_scale_params
|
Optional[List[int]]
|
Indices of pulse
parameters that should be optimised in log-space. For
these parameters the optimizer sees |
None
|
early_stop_patience
|
int
|
Number of consecutive
Stage-1 steps with no improvement greater than
|
0
|
early_stop_min_delta
|
float
|
Minimum decrease in loss
that counts as an improvement for the early-stopping
patience counter. Defaults to |
0.0
|
plot
|
bool
|
If |
False
|
Source code in qml_essentials/qoc.py
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 | |
create_CPhase()
#
Create pulse and target circuits for the CPhase gate.
Source code in qml_essentials/qoc.py
optimize(wires)
#
Decorator factory that optimises pulse parameters for a gate.
Usage::
opt = qoc.optimize(wires=1)
best_params, loss_history = opt(qoc.create_RX)()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wires
|
int
|
Number of qubits the gate acts on. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that accepts a circuit-factory function and |
Callable
|
returns a callable ``(init_pulse_params=None) -> |
Callable
|
(best_params, loss_history)``. |
Source code in qml_essentials/qoc.py
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 | |
optimize_all(sel_gates, make_log)
#
Optimise all selected gates and optionally write a log CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sel_gates
|
str
|
Comma-separated gate names or |
required |
make_log
|
bool
|
If |
required |
Source code in qml_essentials/qoc.py
optimize_joint(target_gates=None, leaf_names=None, weights=None)
#
Joint composite-aware optimisation of leaf pulse parameters.
Optimises a single shared parameter vector theta (containing
the concatenated leaf params for leaf_names) against a
weighted sum of unitary-cost terms over target_gates.
Composite gates back-propagate into the shared leaves; leaf
terms keep the standalone fidelity acceptable. CZ is omitted
from the default targets because the PulseGates.CZ
implementation is a static diagonal-Hamiltonian evolution
(H_CZ = π·|11⟩⟨11|, t=1) that is structurally exact and
unaffected by any leaf re-tuning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_gates
|
Optional[List[str]]
|
Gates whose unitary cost contributes to the
joint objective. Defaults to
:pyattr: |
None
|
leaf_names
|
Optional[List[str]]
|
Leaf gates whose parameters are jointly
optimised. Defaults to :pyattr: |
None
|
weights
|
Optional[Dict[str, float]]
|
Optional mapping |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ndarray
|
|
|
Dict[str, slice]
|
results are also written to |
|
via |
list
|
meth: |
Source code in qml_essentials/qoc.py
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 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 | |
plot_loss_curve(gate_name, loss_history)
#
Save a training-loss curve figure for the Phase-1 optimisation.
Shows loss vs. optimisation step on a log y-scale with a dashed horizontal line at the minimum achieved loss.
The figure is saved to {file_dir}/{gate_name}_loss_curve.png.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_name
|
str
|
Name of the gate being optimised (e.g. |
required |
loss_history
|
list
|
Sequence of loss values, one per step (including the initial loss at index 0). |
required |
Source code in qml_essentials/qoc.py
plot_loss_landscape(gate_name, grid_axes, landscape_data)
#
Save a loss-landscape figure for the Phase-0 grid scan.
The visualisation adapts to the number of pulse parameters:
- 1 parameter: line/scatter plot (param value vs. loss).
- 2 parameters: 2-D heatmap (param₀ × param₁, colour = loss).
- ≥ 3 parameters: horizontal scatter sorted by ascending loss with the best candidate highlighted.
The figure is saved to {file_dir}/{gate_name}_loss_landscape.png.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_name
|
str
|
Name of the gate being optimised (e.g. |
required |
grid_axes
|
List[ndarray]
|
Per-parameter 1-D arrays that span the scan grid. |
required |
landscape_data
|
list
|
List of |
required |
Source code in qml_essentials/qoc.py
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 | |
save_results(gate, fidelity, pulse_params)
#
Save optimised pulse parameters and fidelity for a gate to CSV.
If the gate already exists in the file, its entry is overwritten regardless of whether the new fidelity is higher. A warning is logged when the existing fidelity was better.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate
|
str
|
Name of the gate (e.g. |
required |
fidelity
|
float
|
Achieved fidelity of the optimised pulse. |
required |
pulse_params
|
ndarray
|
Optimised pulse parameters for the gate. |
required |
Source code in qml_essentials/qoc.py
stage_0_opt(init_pulse_params, total_cost)
#
Run the coarse grid-scan phase (Stage 0).
Evaluates a Cartesian grid of parameter candidates using the full weighted cost (fidelity + phase, plus any other registered terms) — the same objective as Stage 1. Each candidate is refined with a few fast gradient steps. Returns the best-found parameters.
Sharing the objective with Stage 1 prevents the grid scan from landing in a basin that has high fidelity but a biased phase which Adam then has to migrate out of (the previous fidelity-only scan caused exactly this failure mode for RX/RY, whose phase residuals compounded in the CRX decomposition).
Robustness: candidates that produce a non-finite loss (e.g. when
the underlying pulse drives the integrator into a NaN — typical
for very narrow DRAG envelopes) are skipped with a warning. For
the duration of the scan, :class:qml_essentials.evolution.Evolution is
switched into throw=False mode so a single bad candidate
cannot abort the loop with MaxStepsReached; the previous
defaults are restored on exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_pulse_params
|
ndarray
|
Initial pulse parameters to compare against. |
required |
total_cost
|
Callable
|
Combined cost callable (same as Stage 1). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of: |
Optional[Tuple[List[ndarray], list]]
|
|
Tuple[ndarray, Optional[Tuple[List[ndarray], list]]]
|
|
Source code in qml_essentials/qoc.py
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 | |
stage_1_opt(best_scan_params, total_costs)
#
Run multi-restart gradient optimisation (Stage 1).
Performs n_restarts independent AdamW runs with the full
(weighted) cost function. The first restart uses
best_scan_params directly; subsequent restarts add random
perturbations. Parameters specified in log_scale_params are
optimised in log-space.
When n_restarts == 1 we keep the original single-restart
Python loop (it preserves per-step log.info granularity
and avoids the vmap/scan compilation overhead). When
n_restarts > 1 we vmap the optimiser over restarts and
run the inner step loop with :func:jax.lax.scan, fusing all
n_restarts × n_steps steps into a single XLA program.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_scan_params
|
ndarray
|
Starting parameters (typically from Stage 0). |
required |
total_costs
|
Callable
|
Combined cost callable. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of |
list
|
best restart. |
Source code in qml_essentials/qoc.py
Cost Functions#
Weighted wrapper around a cost function.
Combines a cost callable with a scalar or tuple weight and optional
constant keyword arguments. Multiple Cost instances can be
composed via the + operator to build a combined objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Callable
|
Callable |
required |
weight
|
Union[float, Tuple]
|
Scalar or tuple of per-component weights. |
required |
ckwargs
|
Optional[dict]
|
Constant keyword arguments injected into every call. |
None
|
Source code in qml_essentials/qoc.py
__add__(other)
#
Compose two cost terms into a single callable that sums them.
Source code in qml_essentials/qoc.py
__call__(*args, **kwargs)
#
Evaluate the cost function with injected kwargs and apply weights.
Source code in qml_essentials/qoc.py
Cost Function Registry#
Registry of cost functions available for pulse optimisation.
Use :meth:register to add new cost functions at runtime and
:meth:get / :meth:available to query them.
Source code in qml_essentials/qoc.py
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 | |
available()
classmethod
#
get(name)
classmethod
#
Look up cost-function metadata by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered cost function name. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Metadata dict with keys |
dict
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not registered. |
Source code in qml_essentials/qoc.py
parse_cost_arg(spec)
classmethod
#
Parse a "name:w1,w2,..." CLI string into (name, weight).
If a tuple is provided, it is returned directly.
If the weight part is omitted the default weight from the registry is used. A single-component weight is returned as a float; multi-component weights are returned as a tuple of floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Union[str, Tuple]
|
A string of the form |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, Union[float, Tuple[float, ...]]]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the name is unknown or the number of weight
components does not match the ones in |
Source code in qml_essentials/qoc.py
Evolution Engine#
Source code in qml_essentials/evolution.py
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 | |
clear_evolve_solver_cache()
classmethod
#
Drop every cached compiled evolve solver.
Call this whenever the coefficient functions referenced by the
cache keys are rebuilt (e.g. when :class:PulseGates swaps in
a new pulse envelope, RWA flag or frame). Without an explicit
eviction the cache keeps the old code objects alive and would
also retain XLA programs that no longer match any active
coefficient function.
Source code in qml_essentials/evolution.py
evolve(hamiltonian, name=None, **odeint_kwargs)
classmethod
#
Return a gate-factory for Hamiltonian time evolution.
Engine for the :meth:Hermitian.evolve / :meth:ParametrizedHamiltonian.evolve
methods (the usual entry point); it dispatches on the Hamiltonian type.
Supports two modes:
Static — when hamiltonian is a :class:Hermitian::
gate = Hermitian(H_mat, wires=0).evolve()
gate(t=0.5) # U = exp(-i*0.5*H)
Time-dependent — when hamiltonian is a
:class:ParametrizedHamiltonian (created via coeff_fn * Hermitian)::
H_td = coeff_fn * Hermitian(H_mat, wires=0)
gate = H_td.evolve()
gate([A, sigma], T) # U via ODE: dU/dt = -i f(p,t) H * U
The time-dependent case solves the Schrödinger equation numerically
using diffrax.diffeqsolve with a Dopri8 adaptive Runge-Kutta
solver
All computations are pure JAX and fully differentiable with
jax.grad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hamiltonian
|
Union[Hermitian, ParametrizedHamiltonian]
|
Either a :class: |
required |
**odeint_kwargs
|
Any
|
Extra keyword arguments. Recognised keys:
|
{}
|
Returns:
| Type | Description |
|---|---|
Callable
|
A callable gate factory. Signature depends on the mode: |
Callable
|
|
Callable
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If hamiltonian is neither |
Source code in qml_essentials/evolution.py
set_solver_defaults(max_steps=None, throw=None, solver=None, magnus_steps=None)
classmethod
#
Update class-level solver defaults; return the previous values.
The returned dictionary is suitable for restoring the previous
defaults via set_solver_defaults(**prev).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
Optional[int]
|
New default for |
None
|
throw
|
Optional[bool]
|
New default for |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with the previous values of the updated keys. |
Source code in qml_essentials/evolution.py
Script#
Circuit container and executor backed by pure JAX kernels.
Script takes a callable f representing a quantum circuit.
Within f, :class:~qml_essentials.operations.Operation objects are
instantiated and automatically recorded onto a tape. The tape is then
simulated using either a statevector or density-matrix kernel depending on
whether noise channels are present.
The stateless simulation/measurement kernels live in
:mod:qml_essentials.simulation and the memory-estimation/chunking helpers
in :mod:qml_essentials.memory; this class orchestrates recording,
batching, caching, and drawing around them.
Attributes:
| Name | Type | Description |
|---|---|---|
f |
The circuit function whose body instantiates |
|
_n_qubits |
Optionally pre-declared number of qubits. When |
Example
def circuit(theta): ... RX(theta, wires=0) ... PauliZ(wires=1) script = Script(circuit, n_qubits=2) result = script.execute(type="expval", obs=[PauliZ(0)])
Source code in qml_essentials/script.py
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 | |
__init__(f, n_qubits=None)
#
Initialise a Script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[..., None]
|
A function whose body instantiates |
required |
n_qubits
|
Optional[int]
|
Number of qubits. If |
None
|
Source code in qml_essentials/script.py
draw(figure='text', args=(), kwargs=None, **draw_kwargs)
#
Draw the quantum circuit.
Records the tape by calling the circuit function with the given arguments, then renders the resulting gate sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figure
|
str
|
Rendering backend. One of:
|
'text'
|
args
|
tuple
|
Positional arguments forwarded to the circuit function to record the tape. |
()
|
kwargs
|
Optional[dict]
|
Keyword arguments forwarded to the circuit function. |
None
|
**draw_kwargs
|
Any
|
Extra options forwarded to the rendering backend:
|
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, Any]
|
Depends on figure: |
Union[str, Any]
|
|
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/script.py
execute(type='expval', obs=None, *, args=(), kwargs=None, in_axes=None, shots=None, key=None)
#
Execute the circuit and return measurement results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
Measurement type. One of:
|
'expval'
|
obs
|
Optional[List[Operation]]
|
Observables required when type is |
None
|
args
|
tuple
|
Positional arguments forwarded to the circuit function f. |
()
|
kwargs
|
Optional[dict]
|
Keyword arguments forwarded to f. |
None
|
in_axes
|
Optional[Tuple]
|
Batch axes for each element of args, following the same
convention as
When provided, :meth: |
None
|
shots
|
Optional[int]
|
Number of measurement shots for stochastic sampling.
If |
None
|
key
|
Optional[ndarray]
|
JAX PRNG key for shot sampling. If |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Without in_axes: shape determined by type. |
ndarray
|
With in_axes: shape |
Source code in qml_essentials/script.py
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 | |
pulse_events(*args, **kwargs)
#
Run the circuit and collect pulse events emitted by PulseGates.
Activates both the normal operation tape (so gates execute) and
a pulse-event tape that captures
:class:~qml_essentials.drawing.PulseEvent objects from leaf
pulse gates (RX, RY, RZ, CZ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Forwarded to the circuit function. |
()
|
**kwargs
|
Any
|
Forwarded to the circuit function. |
{}
|
Returns:
| Type | Description |
|---|---|
list
|
List of :class: |
Source code in qml_essentials/script.py
Drawing#
Wrapper around a quantikz LaTeX string with export helpers.
Source code in qml_essentials/drawing.py
export(destination, full_document=False, mode='w')
#
Export a LaTeX document with a quantum circuit in stick notation.
Parameters#
quantikz_strs : str or list[str] LaTeX string for the quantum circuit or a list of LaTeX strings. destination : str Path to the destination file.
Source code in qml_essentials/drawing.py
wrap_figure()
#
Wraps the quantikz string in a LaTeX figure environment.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A formatted LaTeX string representing the TikZ figure containing |
str
|
the quantum circuit diagram. |
Source code in qml_essentials/drawing.py
Single pulse applied to one or more wires.
Attributes:
| Name | Type | Description |
|---|---|---|
gate |
str
|
Gate label, e.g. |
wires |
List[int]
|
Target qubit wire(s). |
envelope_fn |
Any
|
Pure envelope function |
envelope_params |
Any
|
Envelope-shape parameters (excluding |
w |
float
|
Rotation angle passed to the gate. |
duration |
float
|
Pulse duration (evolution time). |
carrier_phase |
float
|
Phase offset for the carrier cosine. |
parent |
Optional[str]
|
Optional high-level gate name that decomposed into this event. |
Source code in qml_essentials/drawing.py
Tape#
Context manager that creates a fresh tape for recording operations.
Operations instantiated inside this block will be appended to the
returned tape list (via :func:active_tape). Nesting is supported:
each with recording() pushes a new tape onto the per-thread stack,
and the previous tape is restored on exit.
Yields:
| Type | Description |
|---|---|
List['Operation']
|
A new empty list that will be populated with |
Source code in qml_essentials/tape.py
Context manager that collects pulse events emitted by PulseGates.
Yields:
| Type | Description |
|---|---|
list
|
A list that will be populated with |
list
|
class: |