jaxquantum
jaxquantum
DenseImpl
Bases: QarrayImpl
Dense implementation using JAX dense arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
_data |
Array
|
The underlying |
Source code in jaxquantum/core/qarray.py
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 | |
add(other)
Element-wise addition self + other, coercing types as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
441 442 443 444 445 446 447 448 449 450 451 452 453 | |
can_handle_data(arr)
classmethod
Return True for any non-BCOO, non-SparseDIA array.
SparseDiaData objects carry a _is_sparse_dia marker so we can
exclude them without a direct type import (which would be circular).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Raw array. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when arr is a plain dense array (not BCOO, not SparseDiaData). |
Source code in jaxquantum/core/qarray.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
conj()
Element-wise complex conjugate.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
545 546 547 548 549 550 551 | |
dag()
Conjugate transpose.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
480 481 482 483 484 485 486 | |
dag_data(arr)
classmethod
Conjugate transpose for dense arrays.
Swaps the last two axes via :func:jnp.moveaxis and conjugates all
elements. For 1-D inputs only conjugation is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Dense array. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Conjugate transpose with the last two axes swapped. |
Source code in jaxquantum/core/qarray.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
dtype()
Data type of the underlying dense array.
Returns:
| Type | Description |
|---|---|
|
The dtype of |
Source code in jaxquantum/core/qarray.py
513 514 515 516 517 518 519 | |
frobenius_norm()
Compute the Frobenius norm.
Returns:
| Type | Description |
|---|---|
float
|
The Frobenius norm as a scalar. |
Source code in jaxquantum/core/qarray.py
521 522 523 524 525 526 527 | |
from_data(data)
classmethod
Wrap data in a new DenseImpl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array-like input data. |
required |
Returns:
| Type | Description |
|---|---|
'DenseImpl'
|
A |
Source code in jaxquantum/core/qarray.py
411 412 413 414 415 416 417 418 419 420 421 | |
get_data()
Return the underlying dense array.
Source code in jaxquantum/core/qarray.py
423 424 425 | |
imag()
Element-wise imaginary part.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
537 538 539 540 541 542 543 | |
kron(other)
Kronecker product using jnp.kron.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
A |
Source code in jaxquantum/core/qarray.py
578 579 580 581 582 583 584 585 586 587 588 589 590 | |
matmul(other)
Matrix multiply self @ other, coercing types as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
427 428 429 430 431 432 433 434 435 436 437 438 439 | |
mul(scalar)
Scalar multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
Scalar value. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
469 470 471 472 473 474 475 476 477 478 | |
real()
Element-wise real part.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
529 530 531 532 533 534 535 | |
shape()
Shape of the underlying dense array.
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of dimension sizes. |
Source code in jaxquantum/core/qarray.py
505 506 507 508 509 510 511 | |
sub(other)
Element-wise subtraction self - other, coercing types as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/qarray.py
455 456 457 458 459 460 461 462 463 464 465 466 467 | |
tidy_up(atol)
Zero out real/imaginary parts whose magnitude is below atol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atol
|
Absolute tolerance threshold. |
required |
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
to_dense()
Return self (already dense).
Returns:
| Type | Description |
|---|---|
'DenseImpl'
|
This |
Source code in jaxquantum/core/qarray.py
488 489 490 491 492 493 494 | |
to_sparse_bcoo()
Convert to a SparseBCOOImpl via BCOO.fromdense.
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
A |
Source code in jaxquantum/core/qarray.py
496 497 498 499 500 501 502 503 | |
Qarray
Bases: Generic[ImplT]
Quantum array with a pluggable storage backend.
Qarray wraps a QarrayImpl together with quantum-mechanical
dimension metadata (_qdims) and optional batch dimensions
(_bdims). The default backend is dense (DenseImpl); pass
implementation="sparse_bcoo" (or QarrayImplType.SPARSE_BCOO) to
store data as a JAX BCOO sparse array.
Attributes:
| Name | Type | Description |
|---|---|---|
_impl |
ImplT
|
The storage backend holding the raw data. |
_qdims |
Qdims
|
Quantum dimension metadata (bra/ket structure, Hilbert space sizes). |
_bdims |
tuple[int]
|
Tuple of batch dimension sizes (empty tuple = non-batched). |
Example
import jaxquantum as jqt a = jqt.destroy(10, implementation="sparse_bcoo") a.is_sparse_bcoo True
Source code in jaxquantum/core/qarray.py
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 | |
bdims
property
Tuple of batch dimension sizes (empty tuple = non-batched).
data
property
The raw underlying data (dense jnp.ndarray or sparse.BCOO).
dims
property
Quantum dimensions as ((row_dims...), (col_dims...)).
dtype
property
Data type of the underlying storage array.
header
property
One-line header string describing dimensions, shape, and backend.
impl_type
property
The QarrayImplType member of the current storage backend.
is_batched
property
True if this array has one or more batch dimensions.
is_dense
property
True if the storage backend is DenseImpl.
is_sparse_bcoo
property
True if the storage backend is SparseBCOOImpl (BCOO).
is_sparse_dia
property
True if the storage backend is SparseDiaImpl.
qdims
property
The Qdims metadata object for this array.
qtype
property
Quantum type of this array (ket, bra, or operator).
shape
property
Shape of the underlying data array.
shaped_data
property
Data reshaped to bdims + dims[0] + dims[1].
space_dims
property
Hilbert space dimensions for the relevant side (ket row / bra col).
__deepcopy__(memo)
Need to override this when defining getattr.
Source code in jaxquantum/core/qarray.py
1359 1360 1361 1362 1363 1364 1365 1366 | |
__len__()
Length along the first batch dimension.
Returns:
| Type | Description |
|---|---|
|
Size of the leading batch dimension. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the array is not batched. |
Source code in jaxquantum/core/qarray.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
__truediv__(other)
Divide by a scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Scalar divisor. |
required |
Returns:
| Type | Description |
|---|---|
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If other is a |
Source code in jaxquantum/core/qarray.py
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
collapse(mode='sum')
Collapse batch dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Collapse strategy — currently only |
'sum'
|
Returns:
| Type | Description |
|---|---|
|
A non-batched |
Source code in jaxquantum/core/qarray.py
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 | |
conj()
Element-wise complex conjugate.
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 | |
copy(memo=None)
Return a deep copy of this Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memo
|
Optional memo dict forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 | |
cosm()
Matrix cosine.
Source code in jaxquantum/core/qarray.py
1503 1504 1505 | |
create(data, dims=None, bdims=None, implementation=QarrayImplType.DENSE)
classmethod
create(data, dims=None, bdims=None, implementation: Literal[QarrayImplType.DENSE] = QarrayImplType.DENSE) -> 'Qarray[DenseImpl]'
create(data, dims=None, bdims=None, implementation: Literal[QarrayImplType.SPARSE_BCOO] = ...) -> 'Qarray[SparseBCOOImpl]'
create(data, dims=None, bdims=None, implementation=...) -> 'Qarray[DenseImpl]'
Create a Qarray from raw data.
Handles shape normalisation, dimension inference, and tidying of small values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Input data array (dense array-like or |
required | |
dims
|
Quantum dimensions as |
None
|
|
bdims
|
Tuple of batch dimension sizes. Inferred from the leading
dimensions of data when |
None
|
|
implementation
|
Storage backend — |
DENSE
|
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
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 | |
dag()
Conjugate transpose of this array.
Source code in jaxquantum/core/qarray.py
1403 1404 1405 | |
eigenenergies()
Eigenvalues of this operator.
Source code in jaxquantum/core/qarray.py
1534 1535 1536 | |
eigenstates()
Eigenvalues and eigenstates of this operator.
Source code in jaxquantum/core/qarray.py
1530 1531 1532 | |
eigenvalues()
Eigenvalues of this operator (alias for :meth:eigenenergies).
Source code in jaxquantum/core/qarray.py
1538 1539 1540 | |
expm()
Matrix exponential.
Source code in jaxquantum/core/qarray.py
1488 1489 1490 | |
frobenius_norm()
Compute the Frobenius norm directly from the implementation.
Returns:
| Type | Description |
|---|---|
|
The Frobenius norm as a scalar. |
Source code in jaxquantum/core/qarray.py
1440 1441 1442 1443 1444 1445 1446 | |
from_array(qarr_arr)
classmethod
from_array(qarr_arr: 'Qarray[DenseImpl]') -> 'Qarray[DenseImpl]'
from_array(qarr_arr: 'Qarray[SparseBCOOImpl]') -> 'Qarray[SparseBCOOImpl]'
Create a Qarray from a (possibly nested) list of Qarray objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr_arr
|
A |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A |
Qarray
|
of qarr_arr. |
Source code in jaxquantum/core/qarray.py
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 | |
from_list(qarr_list)
classmethod
from_list(qarr_list: List['Qarray[DenseImpl]']) -> 'Qarray[DenseImpl]'
from_list(qarr_list: List['Qarray[SparseBCOOImpl]']) -> 'Qarray[SparseBCOOImpl]'
Create a batched Qarray from a list of same-shaped Qarray objects.
The output implementation is determined by the element with the highest
PROMOTION_ORDER: if all inputs are sparse the result is sparse; if
any input is dense (or types are mixed) all inputs are promoted to dense
and the result is dense.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr_list
|
List[Qarray]
|
List of |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A |
Qarray
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the elements have mismatched |
Source code in jaxquantum/core/qarray.py
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 | |
from_sparse_bcoo(data, dims=None, bdims=None)
classmethod
from_sparse_bcoo(data, dims=None, bdims=None) -> 'Qarray[SparseBCOOImpl]'
Create a Qarray directly from a sparse BCOO array without densifying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
A |
required | |
dims
|
Quantum dimensions. Inferred when |
None
|
|
bdims
|
Batch dimensions. Inferred when |
None
|
Returns:
| Type | Description |
|---|---|
|
A |
Source code in jaxquantum/core/qarray.py
761 762 763 764 765 766 767 768 769 770 771 772 773 | |
from_sparse_dia(data, dims=None, bdims=None)
classmethod
Create a SparseDIA-backed Qarray.
Accepts either a dense array-like (diagonals are auto-detected) or a
:class:~jaxquantum.core.sparse_dia.SparseDiaData container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dense array of shape (*batch, n, n) or a |
required | |
dims
|
Quantum dimensions |
None
|
|
bdims
|
Batch dimension sizes. |
None
|
Returns:
| Type | Description |
|---|---|
'Qarray'
|
A |
Source code in jaxquantum/core/qarray.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
imag()
Element-wise imaginary part.
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
is_dm()
Return True if this array is an operator (density-matrix type).
Source code in jaxquantum/core/qarray.py
1411 1412 1413 | |
is_vec()
Return True if this array is a ket or bra.
Source code in jaxquantum/core/qarray.py
1415 1416 1417 | |
keep_only_diag_elements()
Zero out all off-diagonal elements.
Source code in jaxquantum/core/qarray.py
1427 1428 1429 | |
norm()
Compute the norm of this array.
Source code in jaxquantum/core/qarray.py
1436 1437 1438 | |
powm(n)
Matrix power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
Exponent (integer or float). |
required |
Returns:
| Type | Description |
|---|---|
|
This array raised to the n-th matrix power. |
Source code in jaxquantum/core/qarray.py
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 | |
ptrace(indx)
Partial trace over subsystem indx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indx
|
Index of the subsystem to trace out. |
required |
Returns:
| Type | Description |
|---|---|
|
Reduced density matrix. |
Source code in jaxquantum/core/qarray.py
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 | |
real()
Element-wise real part.
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 | |
reshape_bdims(*args)
Reshape the batch dimensions of this Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
New batch dimension sizes. |
()
|
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | |
reshape_qdims(*args)
Reshape the quantum dimensions of the Qarray.
Note that this does not take in qdims but rather the new Hilbert space dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
New Hilbert dimensions for the Qarray. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Qarray |
reshaped Qarray. |
Source code in jaxquantum/core/qarray.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
resize(new_shape)
Resize the Qarray to a new shape.
TODO: review and maybe deprecate this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_shape
|
Target shape tuple. |
required |
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
sinm()
Matrix sine.
Source code in jaxquantum/core/qarray.py
1507 1508 1509 | |
space_to_qdims(space_dims)
Convert Hilbert space dimensions to full quantum dims tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space_dims
|
List[int]
|
Sequence of per-subsystem Hilbert space sizes, or a
full |
required |
Returns:
| Type | Description |
|---|---|
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in jaxquantum/core/qarray.py
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | |
to_dense()
Return a dense-backed copy of this array.
If the array is already dense, returns self unchanged.
Returns:
| Type | Description |
|---|---|
'Qarray[DenseImpl]'
|
A |
Source code in jaxquantum/core/qarray.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | |
to_dm()
Convert a ket to a density matrix via outer product.
Source code in jaxquantum/core/qarray.py
1407 1408 1409 | |
to_ket()
Convert a bra to a ket (no-op for kets).
Source code in jaxquantum/core/qarray.py
1419 1420 1421 | |
to_sparse_bcoo()
Return a BCOO-sparse-backed copy of this array.
If the array is already sparse BCOO, returns self unchanged.
Returns:
| Type | Description |
|---|---|
'Qarray[SparseBCOOImpl]'
|
A |
Source code in jaxquantum/core/qarray.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 | |
to_sparse_dia()
Return a SparseDIA-backed copy of this array.
If the array is already SparseDIA, returns self unchanged.
Returns:
| Type | Description |
|---|---|
'Qarray'
|
A |
Source code in jaxquantum/core/qarray.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | |
tr(**kwargs)
Full trace.
Source code in jaxquantum/core/qarray.py
1511 1512 1513 | |
trace(**kwargs)
Full trace (alias for :meth:tr).
Source code in jaxquantum/core/qarray.py
1515 1516 1517 | |
transpose(*args)
Transpose subsystem indices.
Source code in jaxquantum/core/qarray.py
1423 1424 1425 | |
unit()
Return the normalised (unit-norm) version of this array.
Source code in jaxquantum/core/qarray.py
1432 1433 1434 | |
QarrayImpl
Bases: ABC
Abstract base class defining the interface every storage backend must implement.
A QarrayImpl wraps a raw data array (dense jnp.ndarray or sparse
BCOO) and provides the mathematical primitives used by Qarray.
Concrete subclasses must implement every @abstractmethod.
Attributes:
| Name | Type | Description |
|---|---|---|
PROMOTION_ORDER |
int
|
Integer priority used by |
Source code in jaxquantum/core/qarray.py
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 | |
data
property
The underlying raw data array.
impl_type
property
The QarrayImplType member corresponding to this instance.
add(other)
abstractmethod
Element-wise addition with other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
Result of |
Source code in jaxquantum/core/qarray.py
194 195 196 197 198 199 200 201 202 203 204 | |
can_handle_data(arr)
abstractmethod
classmethod
Return True if arr is a raw data type natively handled by this impl.
Used by the module-level :func:dag_data dispatcher to route raw
arrays to the correct backend without any isinstance chain outside the
impl classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Raw array — e.g. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this impl can operate on arr without conversion. |
Source code in jaxquantum/core/qarray.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
dag()
abstractmethod
Conjugate transpose.
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
The conjugate transpose of this array as a |
Source code in jaxquantum/core/qarray.py
230 231 232 233 234 235 236 237 | |
dag_data(arr)
abstractmethod
classmethod
Conjugate transpose of raw data in this impl's native format.
Implementations must handle batched arrays (last two axes are swapped) and must not densify sparse arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Raw array in this impl's native format. |
required |
Returns:
| Type | Description |
|---|---|
|
Conjugate transpose with the last two axes swapped. |
Source code in jaxquantum/core/qarray.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
dtype()
abstractmethod
Data type of the underlying array.
Returns:
| Type | Description |
|---|---|
|
A numpy/JAX dtype object. |
Source code in jaxquantum/core/qarray.py
279 280 281 282 283 284 285 286 | |
from_data(data)
abstractmethod
classmethod
Wrap raw data in this impl type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Raw array data (dense |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
A new instance of this implementation wrapping data. |
Source code in jaxquantum/core/qarray.py
169 170 171 172 173 174 175 176 177 178 179 180 | |
get_data()
abstractmethod
Return the underlying raw data array.
Source code in jaxquantum/core/qarray.py
154 155 156 157 | |
kron(other)
abstractmethod
Kronecker (tensor) product with another implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. Mixed-type pairs are handled by
|
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
A new |
Source code in jaxquantum/core/qarray.py
304 305 306 307 308 309 310 311 312 313 314 315 316 | |
matmul(other)
abstractmethod
Matrix multiplication with other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
Result of |
Source code in jaxquantum/core/qarray.py
182 183 184 185 186 187 188 189 190 191 192 | |
mul(scalar)
abstractmethod
Scalar multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
Scalar value to multiply by. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
Result of |
Source code in jaxquantum/core/qarray.py
218 219 220 221 222 223 224 225 226 227 228 | |
shape()
abstractmethod
Shape of the underlying data array.
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of dimension sizes. |
Source code in jaxquantum/core/qarray.py
270 271 272 273 274 275 276 277 | |
sub(other)
abstractmethod
Element-wise subtraction of other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
Result of |
Source code in jaxquantum/core/qarray.py
206 207 208 209 210 211 212 213 214 215 216 | |
tidy_up(atol)
abstractmethod
Zero out values whose magnitude is below atol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atol
|
Absolute tolerance threshold. |
required |
Returns:
| Type | Description |
|---|---|
|
A new |
Source code in jaxquantum/core/qarray.py
292 293 294 295 296 297 298 299 300 301 302 | |
to_dense()
abstractmethod
Convert to a DenseImpl.
Returns:
| Type | Description |
|---|---|
'DenseImpl'
|
A |
Source code in jaxquantum/core/qarray.py
239 240 241 242 243 244 245 246 | |
to_sparse_bcoo()
abstractmethod
Convert to a SparseBCOOImpl (BCOO).
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
A |
Source code in jaxquantum/core/qarray.py
248 249 250 251 252 253 254 255 | |
to_sparse_dia()
Convert to a SparseDiaImpl.
Default implementation goes through dense and auto-detects diagonals. Subclasses may override for a more direct path.
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
A |
Source code in jaxquantum/core/qarray.py
257 258 259 260 261 262 263 264 265 266 267 268 | |
QarrayImplType
Bases: Enum
Enumeration of available Qarray storage backends.
Each member maps one-to-one with a concrete QarrayImpl subclass.
New backends should call QarrayImplType.register(MyImpl, QarrayImplType.MY_TYPE)
immediately after defining their impl class.
Members
DENSE: Standard JAX dense array (jnp.ndarray).
SPARSE_BCOO: JAX experimental BCOO sparse array.
SPARSE_DIA: Diagonal sparse array.
Source code in jaxquantum/core/qarray.py
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 | |
from_impl_class(impl_class)
classmethod
Return the QarrayImplType member associated with impl_class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
impl_class
|
A concrete |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImplType'
|
The corresponding |
Raises:
| Type | Description |
|---|---|
ValueError
|
If impl_class is not in the registry. |
Source code in jaxquantum/core/qarray.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_impl_class()
Return the implementation class registered for this member.
Returns:
| Type | Description |
|---|---|
|
The concrete |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no class has been registered for this member. |
Source code in jaxquantum/core/qarray.py
106 107 108 109 110 111 112 113 114 115 116 117 118 | |
has(x)
classmethod
Return True if x corresponds to a member of QarrayImplType.
Accepts an existing QarrayImplType member, a string equal to the
member name or value (case-insensitive), or an implementation class
(e.g. DenseImpl, SparseBCOOImpl) that has been registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Value to test — a |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Source code in jaxquantum/core/qarray.py
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 | |
register(impl_class, member)
classmethod
Register an implementation class with a QarrayImplType member.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
impl_class
|
The concrete |
required | |
member
|
The |
required |
Source code in jaxquantum/core/qarray.py
50 51 52 53 54 55 56 57 58 | |
QuantumStateTomography
Source code in jaxquantum/core/measurements.py
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 | |
__init__(rho_guess, measurement_basis, measurement_results, complete_basis=None, true_rho=None)
Reconstruct a quantum state from measurement results using quantum state tomography. The tomography can be performed either by direct inversion or by maximum likelihood estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho_guess
|
Qarray
|
The initial guess for the quantum state. |
required |
measurement_basis
|
Qarray
|
The basis in which measurements are performed. |
required |
measurement_results
|
ndarray
|
The results of the measurements. |
required |
complete_basis
|
Optional[Qarray]
|
The complete basis for state |
None
|
true_rho
|
Optional[Qarray]
|
The true quantum state, if known. |
None
|
Source code in jaxquantum/core/measurements.py
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 | |
quantum_state_tomography_direct()
Perform quantum state tomography using direct inversion.
This method reconstructs the quantum state from measurement results by directly solving a system of linear equations. The method assumes that the measurement basis is complete and the measurement results are noise-free.
Returns:
| Name | Type | Description |
|---|---|---|
Qarray |
Qarray
|
Reconstructed quantum state. |
Source code in jaxquantum/core/measurements.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
quantum_state_tomography_mle(L1_reg_strength=0.0, epochs=10000, lr=0.005)
Perform quantum state tomography using maximum likelihood estimation (MLE).
This method reconstructs the quantum state from measurement results by optimizing a likelihood function using gradient descent. The optimization ensures the resulting density matrix is positive semi-definite with trace 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
L1_reg_strength
|
float
|
Strength of L1 |
0.0
|
epochs
|
int
|
Number of optimization iterations. |
10000
|
lr
|
float
|
Learning rate for the Adam optimizer. |
0.005
|
Returns:
| Name | Type | Description |
|---|---|---|
MLETomographyResult |
MLETomographyResult
|
Named tuple containing: - rho: Reconstructed quantum state as Qarray - params_history: List of parameter values during optimization - loss_history: List of loss values during optimization - grads_history: List of gradient values during optimization - infidelity_history: List of infidelities if true_rho was provided, None otherwise |
Source code in jaxquantum/core/measurements.py
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 | |
SparseBCOOImpl
Bases: QarrayImpl
Sparse implementation using JAX experimental BCOO sparse arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
_data |
BCOO
|
The underlying |
Source code in jaxquantum/core/sparse_bcoo.py
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 | |
abs()
Element-wise absolute value.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
233 234 235 236 237 238 239 | |
add(other)
Element-wise addition self + other, coercing types as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
can_handle_data(arr)
classmethod
Return True when arr is a sparse.BCOO array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Raw array. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if arr is a |
Source code in jaxquantum/core/sparse_bcoo.py
254 255 256 257 258 259 260 261 262 263 264 | |
conj()
Element-wise complex conjugate.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
220 221 222 223 224 225 226 | |
dag()
Conjugate transpose without densifying.
Transposes the last two dimensions of the BCOO array and conjugates the stored values.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
dag_data(arr)
classmethod
Conjugate transpose for BCOO sparse arrays without densifying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
BCOO
|
A |
required |
Returns:
| Type | Description |
|---|---|
BCOO
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
dtype()
Data type of the underlying BCOO array.
Returns:
| Type | Description |
|---|---|
|
The dtype of |
Source code in jaxquantum/core/sparse_bcoo.py
173 174 175 176 177 178 179 | |
frobenius_norm()
Compute the Frobenius norm directly from stored values.
Returns:
| Type | Description |
|---|---|
float
|
The Frobenius norm as a scalar. |
Source code in jaxquantum/core/sparse_bcoo.py
181 182 183 184 185 186 187 | |
from_data(data)
classmethod
Wrap data in a new SparseBCOOImpl, converting to BCOO if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
A |
required |
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
31 32 33 34 35 36 37 38 39 40 41 | |
get_data()
Return the underlying BCOO sparse array.
Source code in jaxquantum/core/sparse_bcoo.py
43 44 45 | |
imag()
Element-wise imaginary part.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
207 208 209 210 211 212 213 | |
keep_only_diag()
Zero out off-diagonal stored entries without densifying.
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
311 312 313 314 315 316 317 318 319 320 321 | |
kron(other)
Kronecker product using sparsify(jnp.kron) — stays sparse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'QarrayImpl'
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
'QarrayImpl'
|
A |
'QarrayImpl'
|
operands are sparse; a |
Source code in jaxquantum/core/sparse_bcoo.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
l2_norm_batched(bdims)
Compute the L2 norm per batch element without densifying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bdims
|
tuple
|
Tuple of batch dimension sizes. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar or array of L2 norms. |
Source code in jaxquantum/core/sparse_bcoo.py
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 | |
matmul(other)
Matrix multiply self @ other.
When other is a DenseImpl, JAX's native BCOO @ dense path is
used (no self-densification). When other is also a
SparseBCOOImpl, a sparse @ sparse product is performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
QarrayImpl
|
sparse) containing the matrix product. |
Source code in jaxquantum/core/sparse_bcoo.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
mul(scalar)
Scalar multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
Scalar value. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
102 103 104 105 106 107 108 109 110 111 | |
real()
Element-wise real part.
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
194 195 196 197 198 199 200 | |
shape()
Shape of the underlying BCOO array.
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of dimension sizes. |
Source code in jaxquantum/core/sparse_bcoo.py
165 166 167 168 169 170 171 | |
sub(other)
Element-wise subtraction self - other, coercing types as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
QarrayImpl
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
QarrayImpl
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
tidy_up(atol)
Zero out stored values whose real or imaginary magnitude is below atol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atol
|
Absolute tolerance threshold. |
required |
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
A new |
Source code in jaxquantum/core/sparse_bcoo.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
to_dense()
Convert to a DenseImpl via todense().
Returns:
| Type | Description |
|---|---|
'DenseImpl'
|
A |
Source code in jaxquantum/core/sparse_bcoo.py
135 136 137 138 139 140 141 | |
to_sparse_bcoo()
Return self (already sparse BCOO).
Returns:
| Type | Description |
|---|---|
'SparseBCOOImpl'
|
This |
Source code in jaxquantum/core/sparse_bcoo.py
157 158 159 160 161 162 163 | |
trace()
Compute the trace of the last two matrix dimensions without densifying.
Returns:
| Type | Description |
|---|---|
Array
|
Trace value(s). |
Source code in jaxquantum/core/sparse_bcoo.py
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 | |
SparseDiaData
Lightweight pytree-compatible container for sparse-diagonal raw data.
Returned by SparseDiaImpl.get_data() and consumed by
SparseDiaImpl.from_data(). Registered as a JAX pytree via Flax's
@struct.dataclass; offsets is not a pytree leaf (it is static
compile-time metadata).
Attributes:
| Name | Type | Description |
|---|---|---|
offsets |
tuple
|
Static tuple of diagonal offsets (pytree_node=False). |
diags |
Array
|
JAX array of shape (*batch, n_diags, n) containing the padded diagonal values. |
Source code in jaxquantum/core/sparse_dia.py
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 | |
dtype
property
Dtype of the stored diagonal values.
shape
property
Shape of the represented square matrix (*batch, n, n).
__getitem__(index)
Index into the batch dimension(s), preserving offsets.
Source code in jaxquantum/core/sparse_dia.py
105 106 107 | |
__len__()
Number of elements along the leading batch dimension.
Source code in jaxquantum/core/sparse_dia.py
109 110 111 | |
__matmul__(other)
SparseDIA @ dense → dense (used by mesolve ODE RHS).
Source code in jaxquantum/core/sparse_dia.py
124 125 126 127 128 | |
__rmatmul__(other)
dense @ SparseDIA → dense (used by mesolve ODE RHS).
Source code in jaxquantum/core/sparse_dia.py
130 131 132 | |
reshape(*new_shape)
Reshape batch dimensions while preserving diagonal structure.
new_shape must end with (N, N) (the matrix dims are unchanged).
Only the leading batch dims are reshaped.
Source code in jaxquantum/core/sparse_dia.py
113 114 115 116 117 118 119 120 121 122 | |
SparseDiaImpl
Bases: QarrayImpl
Sparse-diagonal backend storing only diagonal values.
Data layout::
_offsets : tuple[int, ...] — static (pytree_node=False)
_diags : Array[*batch, n_diags, n] — JAX-traced values
For offset k, the convention is:
* k ≥ 0 : valid data at _diags[..., i, k:], zeros at [0:k]
* k < 0 : valid data at _diags[..., i, :n+k], zeros at [n+k:]
In both cases: A[row, row+k] = _diags[..., i, row+k]
Source code in jaxquantum/core/sparse_dia.py
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 | |
add(other)
Element-wise addition.
SparseDIA + SparseDIA stays SparseDIA (union of offsets, static). Otherwise coerces to the higher-order type.
Source code in jaxquantum/core/sparse_dia.py
280 281 282 283 284 285 286 287 288 289 290 291 | |
can_handle_data(arr)
classmethod
Return True only for :class:SparseDiaData objects.
Source code in jaxquantum/core/sparse_dia.py
404 405 406 407 | |
conj()
Element-wise complex conjugate of stored values.
Source code in jaxquantum/core/sparse_dia.py
449 450 451 | |
dag()
Conjugate transpose without densification.
Negates every offset and rearranges the stored values so that the padding convention remains consistent.
Source code in jaxquantum/core/sparse_dia.py
324 325 326 327 328 329 330 331 332 333 334 335 336 | |
dag_data(arr)
classmethod
Conjugate transpose of raw :class:SparseDiaData without densification.
Source code in jaxquantum/core/sparse_dia.py
409 410 411 412 413 414 | |
dtype()
Dtype of the stored diagonal values.
Source code in jaxquantum/core/sparse_dia.py
258 259 260 | |
frobenius_norm()
Frobenius norm computed directly from stored diagonal values.
Source code in jaxquantum/core/sparse_dia.py
431 432 433 | |
from_data(data)
classmethod
Wrap data in a new SparseDiaImpl.
Accepts either a :class:SparseDiaData container (direct wrap) or
a dense array-like (auto-detect non-zero diagonals via numpy, safe
to call before JIT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
A :class: |
required |
Returns:
| Type | Description |
|---|---|
'SparseDiaImpl'
|
A new |
Source code in jaxquantum/core/sparse_dia.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
from_diags(offsets, diags)
classmethod
Directly construct from sorted offsets and padded diagonal array.
This is the preferred factory when diagonal structure is known in
advance (e.g., when building destroy or create operators).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offsets
|
tuple
|
Tuple of integer diagonal offsets (need not be sorted; will be sorted internally). |
required |
diags
|
Array
|
JAX array of shape (batch, n_diags, n) with padded diagonal values matching *offsets. |
required |
Returns:
| Type | Description |
|---|---|
'SparseDiaImpl'
|
A new |
Source code in jaxquantum/core/sparse_dia.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_data()
Return a :class:SparseDiaData container with the raw diagonal data.
Source code in jaxquantum/core/sparse_dia.py
249 250 251 | |
imag()
Element-wise imaginary part of stored values.
Source code in jaxquantum/core/sparse_dia.py
442 443 444 445 446 447 | |
kron(other)
Kronecker product.
SparseDIA ⊗ SparseDIA stays SparseDIA: output offset for pair
(kA, kB) is kA * m + kB where m = dim(B). Fully vectorised —
no loops at JAX level.
Source code in jaxquantum/core/sparse_dia.py
338 339 340 341 342 343 344 345 346 347 348 349 350 | |
matmul(other)
Matrix multiplication.
- SparseDIA @ SparseDIA → SparseDIA (O(d₁·d₂·n))
- SparseDIA @ Dense → Dense (O(d·n²), no densification of self)
- Others → coerce then delegate
Source code in jaxquantum/core/sparse_dia.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
mul(scalar)
Scalar multiplication — scales all diagonal values.
Source code in jaxquantum/core/sparse_dia.py
272 273 274 | |
neg()
Negation.
Source code in jaxquantum/core/sparse_dia.py
276 277 278 | |
powm(n)
Integer matrix power staying SparseDIA via binary exponentiation.
Uses O(log n) SparseDIA @ SparseDIA multiplications rather than densifying. A^0 returns the identity operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Non-negative integer exponent. |
required |
Returns:
| Type | Description |
|---|---|
'SparseDiaImpl'
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n is negative. |
Source code in jaxquantum/core/sparse_dia.py
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 | |
real()
Element-wise real part of stored values.
Source code in jaxquantum/core/sparse_dia.py
435 436 437 438 439 440 | |
shape()
Shape of the represented square matrix (including batch dims).
Source code in jaxquantum/core/sparse_dia.py
253 254 255 256 | |
sub(other)
Element-wise subtraction.
Source code in jaxquantum/core/sparse_dia.py
293 294 295 296 297 298 299 300 | |
tidy_up(atol)
Zero diagonal values whose magnitude is below atol.
Source code in jaxquantum/core/sparse_dia.py
352 353 354 355 356 357 358 359 360 361 | |
to_dense()
Convert to a DenseImpl by summing diagonal contributions.
Source code in jaxquantum/core/sparse_dia.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
to_sparse_bcoo()
Convert to a SparseBCOOImpl (BCOO) via dense.
Source code in jaxquantum/core/sparse_dia.py
383 384 385 | |
to_sparse_dia()
Return self (already SparseDIA).
Source code in jaxquantum/core/sparse_dia.py
387 388 389 | |
trace()
Compute trace directly from the main diagonal (offset 0).
Returns:
| Type | Description |
|---|---|
|
Scalar trace (sum of main diagonal values). |
Source code in jaxquantum/core/sparse_dia.py
420 421 422 423 424 425 426 427 428 429 | |
Ec_to_inv_pF(Ec)
GHz -> 1/picoFarad
Source code in jaxquantum/utils/units.py
81 82 83 84 85 86 87 88 | |
as_series(*arrs)
Return arguments as a list of 1-d arrays.
The returned list contains array(s) of dtype double, complex double, or
object. A 1-d argument of shape (N,) is parsed into N arrays of
size one; a 2-d argument of shape (M,N) is parsed into M arrays
of size N (i.e., is "parsed by row"); and a higher dimensional array
raises a Value Error if it is not first reshaped into either a 1-d or 2-d
array.
Parameters
arrs : array_like 1- or 2-d array_like trim : boolean, optional When True, trailing zeros are removed from the inputs. When False, the inputs are passed through intact.
Returns
a1, a2,... : 1-D arrays A copy of the input data as 1-d arrays.
Source code in jaxquantum/utils/hermgauss.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 | |
basis(N, k, implementation=QarrayImplType.DENSE)
Creates a |k> (i.e. fock state) ket in a specified Hilbert Space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Hilbert space dimension |
required |
k
|
int
|
fock number |
required |
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
|
Fock State |k> |
Source code in jaxquantum/core/operators.py
261 262 263 264 265 266 267 268 269 270 271 272 | |
basis_like(A, ks)
Creates a |k> (i.e. fock state) ket with the same space dims as A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Qarray
|
state or operator. |
required |
k
|
fock number. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Fock State |k> with the same space dims as A. |
Source code in jaxquantum/core/operators.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
cf_wigner(psi, xvec, yvec)
Wigner function for a state vector or density matrix at points
xvec + i * yvec.
Parameters
Qarray
A state vector or density matrix.
array_like
x-coordinates at which to calculate the Wigner function.
array_like
y-coordinates at which to calculate the Wigner function.
Returns
array
Values representing the Wigner function calculated over the specified range [xvec,yvec].
Source code in jaxquantum/core/cfunctions.py
6 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 | |
coherent(N, α)
Coherent state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Hilbert Space Size. |
required |
α
|
complex
|
coherent state amplitude. |
required |
Return
Coherent state |α⟩.
Source code in jaxquantum/core/operators.py
288 289 290 291 292 293 294 295 296 297 298 | |
collapse(qarr, mode='sum')
Collapse the batch dimensions of qarr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Quantum array with optional batch dimensions. |
required |
mode
|
Collapse strategy. Only |
'sum'
|
Returns:
| Type | Description |
|---|---|
Qarray
|
A non-batched |
Source code in jaxquantum/core/qarray.py
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 | |
comb(N, k)
NCk
TODO: replace with jsp.special.comb once issue is closed:
https://github.com/google/jax/issues/9709
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
total items |
required | |
k
|
of items to choose |
required |
Returns:
| Name | Type | Description |
|---|---|---|
NCk |
N choose k |
Source code in jaxquantum/utils/utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
concatenate(qarr_list, axis=0)
Concatenate a list of Qarrays along a specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr_list
|
List[Qarray]
|
List of Qarrays to concatenate. |
required |
axis
|
int
|
Axis along which to concatenate. Default is 0. |
0
|
Returns:
| Type | Description |
|---|---|
Qarray
|
Concatenated Qarray. |
Source code in jaxquantum/core/qarray.py
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 | |
cosm(qarr)
Matrix cosine of a Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array (converted to dense internally). |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A dense |
Source code in jaxquantum/core/qarray.py
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 | |
cosm_data(data, **kwargs)
Matrix cosine of a raw array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Dense matrix array. |
required |
**kwargs
|
Unused; kept for API consistency. |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The matrix cosine computed as |
Source code in jaxquantum/core/qarray.py
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 | |
create(N, implementation=QarrayImplType.DENSE)
creation operator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
Hilbert space size |
required | |
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
creation operator in Hilber Space of size N |
Source code in jaxquantum/core/operators.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
dag(qarr)
Conjugate transpose of qarr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
The conjugate transpose with swapped |
Source code in jaxquantum/core/qarray.py
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 | |
dag_data(arr)
Conjugate transpose of a raw array, dispatching to the right backend.
Iterates through registered :class:QarrayImpl subclasses and delegates
to the first one whose :meth:~QarrayImpl.can_handle_data returns True.
Adding a new backend automatically extends this function — no changes
required here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Input array ( |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Conjugate transpose with the last two axes swapped. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If no registered impl can handle arr. |
Source code in jaxquantum/core/qarray.py
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 | |
destroy(N, implementation=QarrayImplType.DENSE)
annihilation operator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
Hilbert space size |
required | |
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
annilation operator in Hilber Space of size N |
Source code in jaxquantum/core/operators.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
displace(N, α)
Displacement operator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
Hilbert Space Size |
required | |
α
|
Phase space displacement |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Displace operator D(α) |
Source code in jaxquantum/core/operators.py
222 223 224 225 226 227 228 229 230 231 232 233 | |
eigenenergies(qarr)
Eigenvalues of a quantum array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Hermitian operator (converted to dense internally). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Sorted eigenvalues as a JAX array. |
Source code in jaxquantum/core/qarray.py
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 | |
eigenstates(qarr)
Eigenstates of a quantum array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Hermitian operator (converted to dense internally). |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A tuple |
Qarray
|
sorted in ascending order. |
Source code in jaxquantum/core/qarray.py
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 | |
expm(qarr, **kwargs)
Matrix exponential of a Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array (converted to dense internally). |
required |
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Qarray
|
A dense |
Source code in jaxquantum/core/qarray.py
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 | |
expm_data(data, **kwargs)
Matrix exponential of a raw array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Dense matrix array. |
required |
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The matrix exponential. |
Source code in jaxquantum/core/qarray.py
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 | |
extract_dims(arr, dims=None)
Extract dims from a JAX array or Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
JAX array or Qarray. |
required |
dims
|
Optional[Union[DIMS_TYPE, List[int]]]
|
Qarray dims. |
None
|
Returns:
| Type | Description |
|---|---|
|
Qarray dims. |
Source code in jaxquantum/core/conversions.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
fidelity(rho, sigma, force_positivity=False)
Fidelity between two states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
Qarray
|
state. |
required |
sigma
|
Qarray
|
state. |
required |
force_positivity
|
bool
|
force the states to be positive semidefinite |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Fidelity between rho and sigma. |
Source code in jaxquantum/core/measurements.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
hadamard(implementation=QarrayImplType.DENSE)
H
Returns:
| Name | Type | Description |
|---|---|---|
H |
Qarray
|
Hadamard gate |
Source code in jaxquantum/core/operators.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
hermcompanion(c)
Return the scaled companion matrix of c.
The basis polynomials are scaled so that the companion matrix is
symmetric when c is an Hermite basis polynomial. This provides
better eigenvalue estimates than the unscaled case and for basis
polynomials the eigenvalues are guaranteed to be real if
jax.numpy.linalg.eigvalsh is used to obtain them.
Parameters
c : array_like 1-D array of Hermite series coefficients ordered from low to high degree.
Returns
mat : ndarray Scaled companion matrix of dimensions (deg, deg).
Source code in jaxquantum/utils/hermgauss.py
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 | |
identity(*args, implementation=QarrayImplType.DENSE, **kwargs)
Identity matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
Identity matrix. |
Source code in jaxquantum/core/operators.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
identity_like(A, implementation=QarrayImplType.DENSE)
Identity matrix with the same shape as A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Matrix. |
required | |
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
Identity matrix with the same shape as A. |
Source code in jaxquantum/core/operators.py
207 208 209 210 211 212 213 214 215 216 217 218 219 | |
inductance_to_inductive_energy(L)
Convert inductance to inductive energy E_L.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
L
|
float
|
Inductance in nH. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Inductive energy in GHz. |
Source code in jaxquantum/utils/units.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
inductive_energy_to_inductance(El)
Convert inductive energy E_L to inductance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
El
|
float
|
inductive energy in GHz. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Inductance in nH. |
Source code in jaxquantum/utils/units.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
inv_pF_to_Ec(inv_pfarad)
1/picoFarad -> GHz
Source code in jaxquantum/utils/units.py
72 73 74 75 76 77 78 | |
is_dm_data(data)
Check whether data has the shape of a density matrix (square matrix).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Array to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the last two dimensions are equal. |
Source code in jaxquantum/core/qarray.py
2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 | |
jnp2jqt(arr, dims=None)
JAX array -> QuTiP state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jnp_obj
|
JAX array. |
required | |
dims
|
Optional[Union[DIMS_TYPE, List[int]]]
|
Qarray dims. |
None
|
Returns:
| Type | Description |
|---|---|
|
QuTiP state. |
Source code in jaxquantum/core/conversions.py
79 80 81 82 83 84 85 86 87 88 89 90 | |
jqt2qt(jqt_obj)
Qarray -> QuTiP state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jqt_obj
|
Qarray. |
required | |
dims
|
QuTiP dims. |
required |
Returns:
| Type | Description |
|---|---|
|
QuTiP state. |
Source code in jaxquantum/core/conversions.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
keep_only_diag_elements(qarr)
Zero out all off-diagonal elements of qarr.
For sparse Qarray objects the off-diagonal stored values are zeroed
in-place on the BCOO structure — no densification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Non-batched input quantum array. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If qarr has batch dimensions. |
Source code in jaxquantum/core/qarray.py
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 | |
ket2dm(qarr)
Convert a ket to a density matrix via outer product.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Ket, bra, or operator. Operators are returned unchanged. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Density matrix |
Source code in jaxquantum/core/qarray.py
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 | |
mesolve(H, rho0, tlist, saveat_tlist=None, c_ops=None, solver_options=None)
Quantum Master Equation solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
H
|
Union[Qarray, Callable[[float], Qarray]]
|
time dependent Hamiltonian function or time-independent Qarray. |
required |
rho0
|
Qarray
|
initial state, must be a density matrix. For statevector evolution, please use sesolve. |
required |
tlist
|
Array
|
time list |
required |
saveat_tlist
|
Optional[Array]
|
list of times at which to save the state. If -1 or [-1], save only at final time. If None, save at all times in tlist. Default: None. |
None
|
c_ops
|
Optional[Qarray]
|
qarray list of collapse operators |
None
|
solver_options
|
Optional[SolverOptions]
|
SolverOptions with solver options |
None
|
Returns:
| Type | Description |
|---|---|
Qarray
|
list of states |
Source code in jaxquantum/core/solvers.py
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 | |
multi_mode_basis_set(Ns)
Creates a multi-mode basis set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Ns
|
List[int]
|
List of Hilbert space dimensions for each mode. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Multi-mode basis set. |
Source code in jaxquantum/core/operators.py
274 275 276 277 278 279 280 281 282 283 284 285 | |
n_thermal(frequency, temperature)
Calculate the average thermal photon number for a given frequency and temperature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequency
|
float
|
Frequency in GHz. |
required |
temperature
|
float
|
Temperature in Kelvin. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Average thermal photon number. |
Source code in jaxquantum/utils/units.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
norm(qarr)
Compute the norm of a quantum array.
Sparse paths (no densification):
- ket / bra — L2 norm via :meth:
SparseBCOOImpl.l2_norm_batched(handles batch dimensions). - operator — trace norm assuming PSD (nuclear norm = tr(rho) for density matrices). This is exact for density matrices; for general non-PSD operators convert to dense first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The norm as a scalar (or batched array of scalars). |
Source code in jaxquantum/core/qarray.py
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 | |
num(N, implementation=QarrayImplType.DENSE)
Number operator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
Hilbert Space size |
required | |
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
number operator in Hilber Space of size N |
Source code in jaxquantum/core/operators.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
overlap(rho, sigma)
Overlap between two states or operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rho
|
Qarray
|
state/operator. |
required |
sigma
|
Qarray
|
state/operator. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Overlap between rho and sigma. |
Source code in jaxquantum/core/measurements.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
plot_cf(state, pts_x, pts_y=None, axs=None, contour=True, qp_type=WIGNER, cbar_label='', axis_scale_factor=1, plot_cbar=True, plot_grid=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None)
Plot characteristic function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
state with arbitrary number of batch dimensions, result will |
required | |
pts_x
|
x points to evaluate quasi-probability distribution at |
required | |
pts_y
|
y points to evaluate quasi-probability distribution at |
None
|
|
axs
|
matplotlib axes to plot on |
None
|
|
contour
|
make the plot use contouring |
True
|
|
qp_type
|
type of quasi probability distribution ("wigner") |
WIGNER
|
|
cbar_label
|
labels for the real and imaginary cbar |
''
|
|
axis_scale_factor
|
scale of the axes labels relative |
1
|
|
plot_cbar
|
whether to plot cbar |
True
|
|
x_ticks
|
tick position for the x-axis |
None
|
|
y_ticks
|
tick position for the y-axis |
None
|
|
z_ticks
|
tick position for the z-axis |
None
|
|
subtitles
|
subtitles for the subplots |
None
|
|
figtitle
|
figure title |
None
|
Returns:
| Type | Description |
|---|---|
|
axis on which the plot was plotted. |
Source code in jaxquantum/core/visualization.py
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 | |
plot_cf_wigner(state, pts_x, pts_y=None, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, plot_grid=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None)
Plot the Wigner characteristic function of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
state with arbitrary number of batch dimensions, result will |
required | |
pts_x
|
x points to evaluate quasi-probability distribution at |
required | |
pts_y
|
y points to evaluate quasi-probability distribution at |
None
|
|
axs
|
matplotlib axes to plot on |
None
|
|
contour
|
make the plot use contouring |
True
|
|
cbar_label
|
label for the cbar |
''
|
|
axis_scale_factor
|
scale of the axes labels relative |
1
|
|
plot_cbar
|
whether to plot cbar |
True
|
|
x_ticks
|
tick position for the x-axis |
None
|
|
y_ticks
|
tick position for the y-axis |
None
|
|
z_ticks
|
tick position for the z-axis |
None
|
|
subtitles
|
subtitles for the subplots |
None
|
|
figtitle
|
figure title |
None
|
Returns:
| Type | Description |
|---|---|
|
axis on which the plot was plotted. |
Source code in jaxquantum/core/visualization.py
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 | |
plot_qfunc(state, pts_x, pts_y=None, g=2, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None)
Plot the husimi function of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
state with arbitrary number of batch dimensions, result will |
required | |
pts_x
|
x points to evaluate quasi-probability distribution at |
required | |
pts_y
|
y points to evaluate quasi-probability distribution at |
None
|
|
g
|
float, default: 2 |
required | |
related to the value of
|
math: |
required | |
|
math: |
required | |
axs
|
matplotlib axes to plot on |
None
|
|
contour
|
make the plot use contouring |
True
|
|
cbar_label
|
label for the cbar |
''
|
|
axis_scale_factor
|
scale of the axes labels relative |
1
|
|
plot_cbar
|
whether to plot cbar |
True
|
|
x_ticks
|
tick position for the x-axis |
None
|
|
y_ticks
|
tick position for the y-axis |
None
|
|
z_ticks
|
tick position for the z-axis |
None
|
|
subtitles
|
subtitles for the subplots |
None
|
|
figtitle
|
figure title |
None
|
Returns:
| Type | Description |
|---|---|
|
axis on which the plot was plotted. |
Source code in jaxquantum/core/visualization.py
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 | |
plot_qp(state, pts_x, pts_y=None, g=2, axs=None, contour=True, qp_type=WIGNER, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None)
Plot quasi-probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
state with arbitrary number of batch dimensions, result will |
required | |
pts_x
|
x points to evaluate quasi-probability distribution at |
required | |
pts_y
|
y points to evaluate quasi-probability distribution at |
None
|
|
g
|
float, default: 2 |
required | |
related to the value of
|
math: |
required | |
|
math: |
required | |
axs
|
matplotlib axes to plot on |
None
|
|
contour
|
make the plot use contouring |
True
|
|
qp_type
|
type of quasi probability distribution ("wigner", "qfunc") |
WIGNER
|
|
cbar_label
|
label for the cbar |
''
|
|
axis_scale_factor
|
scale of the axes labels relative |
1
|
|
plot_cbar
|
whether to plot cbar |
True
|
|
x_ticks
|
tick position for the x-axis |
None
|
|
y_ticks
|
tick position for the y-axis |
None
|
|
z_ticks
|
tick position for the z-axis |
None
|
|
subtitles
|
subtitles for the subplots |
None
|
|
figtitle
|
figure title |
None
|
Returns:
| Type | Description |
|---|---|
|
axis on which the plot was plotted. |
Source code in jaxquantum/core/visualization.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
plot_wigner(state, pts_x, pts_y=None, g=2, axs=None, contour=True, cbar_label='', axis_scale_factor=1, plot_cbar=True, x_ticks=None, y_ticks=None, z_ticks=None, subtitles=None, figtitle=None)
Plot the wigner function of the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
state with arbitrary number of batch dimensions, result will |
required | |
pts_x
|
x points to evaluate quasi-probability distribution at |
required | |
pts_y
|
y points to evaluate quasi-probability distribution at |
None
|
|
g
|
float, default: 2 |
required | |
related to the value of
|
math: |
required | |
|
math: |
required | |
axs
|
matplotlib axes to plot on |
None
|
|
contour
|
make the plot use contouring |
True
|
|
cbar_label
|
label for the cbar |
''
|
|
axis_scale_factor
|
scale of the axes labels relative |
1
|
|
plot_cbar
|
whether to plot cbar |
True
|
|
x_ticks
|
tick position for the x-axis |
None
|
|
y_ticks
|
tick position for the y-axis |
None
|
|
z_ticks
|
tick position for the z-axis |
None
|
|
subtitles
|
subtitles for the subplots |
None
|
|
figtitle
|
figure title |
None
|
Returns:
| Type | Description |
|---|---|
|
axis on which the plot was plotted. |
Source code in jaxquantum/core/visualization.py
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 | |
powm(qarr, n, clip_eigvals=False)
Matrix power of a Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
n
|
Union[int, float]
|
Exponent. Integer powers use |
required |
clip_eigvals
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Qarray
|
The n-th matrix power as a |
Qarray
|
non-negative exponents when the input is SparseDIA). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n is a float and the matrix has negative eigenvalues
(and clip_eigvals is |
Source code in jaxquantum/core/qarray.py
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 | |
powm_data(data, n)
Integer matrix power of a raw array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Dense square matrix array. |
required |
n
|
int
|
Integer exponent. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The n-th matrix power. |
Source code in jaxquantum/core/qarray.py
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 | |
propagator(H, ts, saveat_tlist=None, solver_options=None)
Generate the propagator for a time dependent Hamiltonian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
H
|
Qarray or callable
|
A Qarray static Hamiltonian OR a function that takes a time argument and returns a Hamiltonian. |
required |
ts
|
float or Array
|
A single time point or an Array of time points. |
required |
saveat_tlist
|
Optional[Array]
|
list of times at which to save the state. If -1 or [-1], save only at final time. If None, save at all times in tlist. Default: None. |
None
|
Returns:
| Type | Description |
|---|---|
|
Qarray or List[Qarray]: The propagator for the Hamiltonian at time t. OR a list of propagators for the Hamiltonian at each time in t. |
Source code in jaxquantum/core/solvers.py
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 | |
ptrace(qarr, indx)
Partial trace over subsystem indx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array (converted to dense internally). |
required |
indx
|
Index of the subsystem to trace out. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Reduced density matrix as a |
Source code in jaxquantum/core/qarray.py
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 | |
qfunc(psi, xvec, yvec, g=2)
Husimi-Q function of a given state vector or density matrix at phase-space
points 0.5 * g * (xvec + i*yvec).
Parameters
state : Qarray A state vector or density matrix. This cannot have tensor-product structure.
xvec, yvec : array_like x- and y-coordinates at which to calculate the Husimi-Q function.
float, default: 2
Scaling factor for a = 0.5 * g * (x + iy). The value of g is
related to the value of :math:\hbar in the commutation relation
:math:[x,\,y] = i\hbar via :math:\hbar=2/g^2.
Returns
jnp.ndarray
Values representing the Husimi-Q function calculated over the specified
range [xvec, yvec].
Source code in jaxquantum/core/qp_distributions.py
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 | |
qt2jqt(qt_obj, dtype=jnp.complex128)
QuTiP state -> Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qt_obj
|
QuTiP state. |
required | |
dtype
|
JAX dtype. |
complex128
|
Returns:
| Type | Description |
|---|---|
|
Qarray. |
Source code in jaxquantum/core/conversions.py
22 23 24 25 26 27 28 29 30 31 32 33 34 | |
qubit_rotation(theta, nx, ny, nz)
Single qubit rotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
rotation angle. |
required |
nx
|
rotation axis x component. |
required | |
ny
|
rotation axis y component. |
required | |
nz
|
rotation axis z component. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Single qubit rotation operator. |
Source code in jaxquantum/core/operators.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
robust_asarray(data)
Convert data to a JAX array, leaving sparse BCOO and SparseDiaData untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Input data — any array-like, |
required |
Returns:
| Type | Description |
|---|---|
Union[Array, BCOO]
|
A |
Source code in jaxquantum/core/qarray.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
sesolve(H, rho0, tlist, saveat_tlist=None, solver_options=None)
Schrödinger Equation solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
H
|
Union[Qarray, Callable[[float], Qarray]]
|
time dependent Hamiltonian function or time-independent Qarray. |
required |
rho0
|
Qarray
|
initial state, must be a density matrix. For statevector evolution, please use sesolve. |
required |
tlist
|
Array
|
time list |
required |
saveat_tlist
|
Optional[Array]
|
list of times at which to save the state. If -1 or [-1], save only at final time. If None, save at all times in tlist. Default: None. |
None
|
solver_options
|
Optional[SolverOptions]
|
SolverOptions with solver options |
None
|
Returns:
| Type | Description |
|---|---|
Qarray
|
list of states |
Source code in jaxquantum/core/solvers.py
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 | |
set_precision(precision)
Set the precision of JAX operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
Literal['single', 'double']
|
'single' or 'double' |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if precision is not 'single' or 'double' |
Source code in jaxquantum/utils/utils.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
sigmam(implementation=QarrayImplType.DENSE)
σ-
Returns:
| Type | Description |
|---|---|
Qarray
|
σ- Pauli Operator |
Source code in jaxquantum/core/operators.py
93 94 95 96 97 98 99 100 101 102 | |
sigmap(implementation=QarrayImplType.DENSE)
σ+
Returns:
| Type | Description |
|---|---|
Qarray
|
σ+ Pauli Operator |
Source code in jaxquantum/core/operators.py
105 106 107 108 109 110 111 112 113 114 | |
sigmax(implementation=QarrayImplType.DENSE)
σx
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
implementation
|
QarrayImplType
|
Qarray implementation type, e.g. "sparse" or "dense". |
DENSE
|
Returns:
| Type | Description |
|---|---|
Qarray
|
σx Pauli Operator |
Source code in jaxquantum/core/operators.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
sigmay(implementation=QarrayImplType.DENSE)
σy
Returns:
| Type | Description |
|---|---|
Qarray
|
σy Pauli Operator |
Source code in jaxquantum/core/operators.py
53 54 55 56 57 58 59 60 61 62 | |
sigmaz(implementation=QarrayImplType.DENSE)
σz
Returns:
| Type | Description |
|---|---|
Qarray
|
σz Pauli Operator |
Source code in jaxquantum/core/operators.py
65 66 67 68 69 70 71 72 73 74 | |
sinm(qarr)
Matrix sine of a Qarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array (converted to dense internally). |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
A dense |
Source code in jaxquantum/core/qarray.py
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 | |
sinm_data(data, **kwargs)
Matrix sine of a raw array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Dense matrix array. |
required |
**kwargs
|
Unused; kept for API consistency. |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The matrix sine computed as |
Source code in jaxquantum/core/qarray.py
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 | |
solve(f, ρ0, tlist, saveat_tlist, args, solver_options=None)
Gets teh desired solver from diffrax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
function defining the ODE |
required | |
ρ0
|
initial state |
required | |
tlist
|
time list |
required | |
saveat_tlist
|
list of times at which to save the state pass in [-1] to save only at final time |
required | |
args
|
additional arguments to f |
required | |
solver_options
|
Optional[SolverOptions]
|
dictionary with solver options |
None
|
Returns:
| Type | Description |
|---|---|
|
solution |
Source code in jaxquantum/core/solvers.py
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 | |
squeeze(N, z)
Single-mode Squeezing operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
Hilbert Space Size |
required | |
z
|
squeezing parameter |
required |
Returns:
| Type | Description |
|---|---|
|
Sqeezing operator |
Source code in jaxquantum/core/operators.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
tensor(*args, **kwargs)
Tensor (Kronecker) product of two or more Qarray objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
|
()
|
|
**kwargs
|
Optional keyword arguments. Pass |
{}
|
Returns:
| Type | Description |
|---|---|
Qarray
|
The tensor product as a |
Qarray
|
determined by the highest |
Qarray
|
inputs → sparse output; any dense input → dense output. This holds for |
Qarray
|
both |
Note
parallel=True uses an einsum-based batched outer product. The
einsum is always computed on dense data for efficiency, but the result
is then wrapped in the appropriate backend (sparse when all inputs are
sparse, dense otherwise). For the default (parallel=False) path
each backend's kron method is used directly.
Source code in jaxquantum/core/qarray.py
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 | |
tensor_basis(single_basis, n)
Construct n-fold tensor product basis from a single-system basis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
single_basis
|
Qarray
|
The single-system operator basis as a Qarray. |
required |
n
|
int
|
Number of tensor copies to construct. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Qarray containing the n-fold tensor product basis operators. |
Qarray
|
The resulting basis has b^n elements where b is the number |
Qarray
|
of operators in the single-system basis. |
Source code in jaxquantum/core/measurements.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 | |
thermal_dm(N, n)
Thermal state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Hilbert Space Size. |
required |
n
|
float
|
average photon number. |
required |
Return
Thermal state.
Source code in jaxquantum/core/operators.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
to_ket(qarr)
Convert qarr to a ket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
A ket (returned as-is) or bra (conjugate-transposed). |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
The ket form of qarr. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If qarr is an operator. |
Source code in jaxquantum/core/qarray.py
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
tr(qarr, **kwargs)
Full trace of qarr.
For sparse Qarray objects the trace is computed natively on the BCOO
data using a masked scatter — no densification. Custom axis arguments
are ignored for sparse (the last two dimensions are always the matrix
dimensions in jaxquantum's convention).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The trace as a scalar (or batched array of scalars). |
Source code in jaxquantum/core/qarray.py
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 | |
trace(qarr, **kwargs)
Full trace (alias for :func:tr).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
**kwargs
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
Array
|
The trace as a scalar (or batched array of scalars). |
Source code in jaxquantum/core/qarray.py
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 | |
transpose(qarr, indices)
Transpose subsystem indices of the quantum array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
indices
|
List[int]
|
New ordering of subsystem indices. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Transposed |
Source code in jaxquantum/core/qarray.py
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 | |
unit(qarr)
Normalize qarr to unit norm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qarr
|
Qarray
|
Input quantum array. |
required |
Returns:
| Type | Description |
|---|---|
Qarray
|
Normalized quantum array. |
Source code in jaxquantum/core/qarray.py
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 | |
wigner(psi, xvec, yvec, method='clenshaw', g=2)
Wigner function for a state vector or density matrix at points
xvec + i * yvec.
Parameters
Qarray
A state vector or density matrix.
array_like
x-coordinates at which to calculate the Wigner function.
array_like
y-coordinates at which to calculate the Wigner function.
float, default: 2
Scaling factor for a = 0.5 * g * (x + iy), default g = 2.
The value of g is related to the value of hbar in the commutation
relation [x, y] = i * hbar via hbar=2/g^2.
string {'clenshaw', 'iterative', 'laguerre', 'fft'}, default: 'clenshaw'
Only 'clenshaw' is currently supported.
Select method 'clenshaw' 'iterative', 'laguerre', or 'fft', where 'clenshaw'
and 'iterative' use an iterative method to evaluate the Wigner functions for density
matrices :math:|m><n|, while 'laguerre' uses the Laguerre polynomials
in scipy for the same task. The 'fft' method evaluates the Fourier
transform of the density matrix. The 'iterative' method is default, and
in general recommended, but the 'laguerre' method is more efficient for
very sparse density matrices (e.g., superpositions of Fock states in a
large Hilbert space). The 'clenshaw' method is the preferred method for
dealing with density matrices that have a large number of excitations
(>~50). 'clenshaw' is a fast and numerically stable method.
Returns
array
Values representing the Wigner function calculated over the specified range [xvec,yvec].
References
Ulf Leonhardt, Measuring the Quantum State of Light, (Cambridge University Press, 1997)
Source code in jaxquantum/core/qp_distributions.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |