qten.bands
Module reference for qten.bands.
bands
Band-structure helpers for momentum-resolved QTen tensors.
This module provides utilities for transforming, folding, unfolding, filling,
and selecting bands represented as Tensor
objects. The common convention is that a band tensor has dimensions
(MomentumSpace, HilbertSpace, HilbertSpace): the
MomentumSpace axis indexes
crystal momenta and the two
HilbertSpace axes form the
Hamiltonian or operator matrix at each momentum.
Mathematical convention
A band tensor represents a family of matrices indexed by crystal momentum: \(H : k \mapsto H(k)\), with \(H(k)_{ab} = \langle a | H(k) | b \rangle\).
In code this is stored as a rank-3 Tensor with
dims (K, B_left, B_right), where K is a
MomentumSpace and the two
Hilbert-space axes provide the row and column basis labels for each matrix
block.
Geometry transformations act on both parts of this object: \(k \mapsto k'\) and \(H(k) \mapsto U(k)\,H(k)\,U(k)^\dagger\).
where the \(k\)-dependent change-of-basis matrix \(U(k)\) is assembled from symbolic Hilbert-space relabeling and finite Fourier transforms.
Repository usage
The functions here sit between geometry, symbolic Hilbert-space labels, and linear algebra. Geometry objects provide real and reciprocal lattice structure, symbolic state spaces label tensor axes, and linear algebra routines diagonalize the momentum-sector matrices when filling or selecting bands.
interpolate_path
interpolate_path(
recip: ReciprocalLattice,
waypoints: Sequence[str],
points: KPointSet,
n_points: int = 100,
wrap_fractional: bool = True,
) -> BzPath
Build a sampled Brillouin-zone path in a reciprocal lattice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recip
|
ReciprocalLattice
|
Reciprocal lattice in which waypoint coordinates are interpreted. |
required |
waypoints
|
Sequence[str]
|
Waypoint names in path order, e.g. |
required |
n_points
|
int
|
Number of samples used along the full interpolated path. |
100
|
points
|
KPointSet
|
Named reciprocal-space points carrying their source reciprocal lattice.
They are rebased to |
required |
wrap_fractional
|
bool
|
If True, wrap each rebased waypoint into the canonical fractional cell before interpolation. Set to False to preserve raw rebased coordinates. |
True
|
Returns:
| Type | Description |
|---|---|
BzPath
|
Sampled Brillouin-zone path with momentum space, waypoint labels, and path-order metadata. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If fewer than two waypoints are supplied, if a named waypoint is not
present in |
Examples:
path = interpolate_path(
recip,
waypoints=["G", "X", "M"],
points=KPointSet.from_points(
recip,
{"G": (0.0, 0.0), "X": (0.5, 0.0), "M": (0.5, 0.5)},
),
)
path = interpolate_path(
recip=new_recip,
waypoints=["G", "X", "M"],
points=original_kpoints, # KPointSet tied to old reciprocal basis
)
Source code in src/qten/bands.py
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 | |
get_band_transform
get_band_transform(
t: Opr,
tensor: Tensor,
side: Literal["left", "right"] = "left",
) -> MomentumBlockTensor
get_band_transform(
t: Opr,
kspace: MomentumSpace,
target_space: HilbertSpace,
*,
device: Optional[Device] = None,
) -> MomentumBlockTensor
Construct a reusable one-sided geometric basis-change operator for a momentum-resolved band tensor.
Supported forms
get_band_transform(t, tensor, side=...)
Build the transform from a rank-3 band tensor with dims
(MomentumSpace, HilbertSpace, HilbertSpace), using side to choose
which Hilbert-space leg is sampled.
get_band_transform(t, kspace, target_space, device=...)
Build the same transform directly from an explicit
MomentumSpace kspace
and sampled HilbertSpace
target_space, without first packaging them into a rank-3 tensor.
Use cases
This helper is useful when the geometric action should be materialized once
and then reused across multiple band tensors, when only one matrix leg of a
non-Hermitian or rectangular band object should be transformed, or when the
transform itself should be inspected as a
MomentumBlockTensor rather than applied
immediately.
For example, a caller may build the left and right transforms separately, cache them, and apply them to several tensors sharing the same symbolic momentum and Hilbert spaces.
This function factors one side of the geometric basis change performed by
bandtransform into an explicit
MomentumBlockTensor \(T_g\). For a
momentum-resolved operator \(H\), the one-sided transformed tensor is
recovered by \(T_g H\) when side="left" and by
\(H T_g^\dagger\) when side="right". Applying both sides requires
composing the two separately constructed transforms.
The leading axis of \(T_g\) is a
MomentumBlockSpace
storing ordered pairs (t @ k, k): each block describes the basis map from
the source momentum sector k to the transformed sector t @ k.
Behavior
This function does not transform tensor data directly. Instead it builds a block operator whose momentum-pair axis records how source sectors feed transformed sectors. The Hilbert-space block at each such pair combines:
- the symbolic action of
ton the sampled basis, - fractional wrapping back to the home unit cell, and
- the Fourier phase needed to keep Bloch conventions consistent after the geometric relabeling.
The returned transform is therefore the reusable one-sided ingredient of
bandtransform, not merely a permutation of
momentum labels.
Basis sampling
The input tensor may have dims (K, B_left, B_right) with potentially
different left and right Hilbert spaces. The side argument chooses which
matrix leg supplies the canonical Hilbert space used to assemble \(T_g\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Opr
|
required | |
tensor
|
Tensor
|
Rank-3 momentum-space tensor with dims
|
required |
side
|
Literal['left', 'right']
|
Which matrix leg to sample when constructing the transform basis.
|
'left'
|
Returns:
| Type | Description |
|---|---|
MomentumBlockTensor
|
Block transform tensor with dims
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the tensor dims do not have the required
|
Notes
The generated API docs for this module show overload signatures, but the
prose is rendered from this public implementation docstring. The explicit
space overload accepts kspace and target_space directly, then
dispatches here through the shared construction path.
Examples:
Build and apply only the left transform:
T_left = get_band_transform(t, tensor, side="left")
routed = T_left @ tensor
Build both one-sided transforms explicitly and compose them:
T_left = get_band_transform(t, tensor, side="left")
T_right = get_band_transform(t, tensor, side="right")
transformed = T_left @ tensor @ T_right.h(-2, -1)
Build the transform directly from symbolic spaces:
T_left = get_band_transform(t, kspace, hilbert_space, device=device)
See Also
bandtransform(t, tensor, opt=...)
Public wrapper that applies one-sided or two-sided band transforms.
get_band_fold(transform, tensor, side=...)
Folding analogue that builds the corresponding block transform for a
basis-change-induced Brillouin-zone fold.
Source code in src/qten/bands.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
get_band_fold
get_band_fold(
transform: BasisTransform,
tensor: Tensor,
side: Literal["left", "right"] = "left",
) -> MomentumBlockTensor
get_band_fold(
transform: BasisTransform,
k_space: MomentumSpace,
target_space: HilbertSpace,
*,
device: Optional[Device] = None,
) -> MomentumBlockTensor
Construct a reusable one-sided Brillouin-zone folding operator for a momentum-resolved band tensor.
Supported forms
get_band_fold(transform, tensor, side=...)
Build the folding transform from a rank-3 band tensor with dims
(MomentumSpace, HilbertSpace, HilbertSpace), using side to choose
which Hilbert-space leg is sampled.
get_band_fold(transform, k_space, target_space, device=...)
Build the same folding transform directly from an explicit
MomentumSpace k_space
and sampled HilbertSpace
target_space, without first packaging them into a rank-3 tensor.
Use cases
This helper is useful when Brillouin-zone folding should be factored into a reusable one-sided operator, when left and right Hilbert-space legs should be folded independently, or when the folding map itself should be examined as a block tensor before applying it to data.
Typical workflows include caching folded-cell transforms for repeated use, applying folding to only one matrix leg of a tensor, or explicitly constructing the left and right folded operators before composing them.
This function factors one side of the Brillouin-zone folding operation
into an explicit MomentumBlockTensor \(T_g\).
For a momentum-resolved operator \(H\), the one-sided folded tensor is
recovered by \(T_g H\) when side="left" and by
\(H T_g^\dagger\) when side="right". Folding both sides requires
composing the two separately constructed transforms.
Each block of \(T_g\) is labelled by a pair
\((k_{\mathrm{fold}}, k)\) on its leading
MomentumBlockSpace,
where \(k\) is a momentum of the original Brillouin zone and
\(k_{\mathrm{fold}}\) is the momentum sector it maps to in the folded
zone.
The Hilbert-space legs encode the Fourier-based change of basis between the
original unit cell and the enlarged transformed cell.
Behavior
Folding changes both the momentum grid and the real-space basis. This helper builds the one-sided block operator that performs those two tasks together:
- each source momentum sector is routed to its folded-zone momentum,
- the sampled Hilbert-space basis is enlarged to the transformed unit cell, and
- the corresponding Fourier change of basis is assembled into each block.
The result is not just a relabeling of momentum sectors. It is the
reusable one-sided ingredient of bandfold that
carries both sector routing and enlarged-cell basis conversion.
When multiple basis states share the same fractional site within the
sampled Hilbert space, all of them are preserved in the enlarged folded
basis.
Basis sampling
The input tensor may have dims (K, B_left, B_right) with potentially
different left and right Hilbert spaces. The side argument chooses which
leg supplies the canonical basis from which the folding transform is built.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
BasisTransform
|
Direct-lattice basis transformation that defines the folded Brillouin zone. |
required |
tensor
|
Tensor
|
Rank-3 momentum-space tensor with dims
|
required |
side
|
Literal['left', 'right']
|
Which matrix leg to sample when constructing the folding basis.
|
'left'
|
Returns:
| Type | Description |
|---|---|
MomentumBlockTensor
|
Block folding tensor with dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the tensor dims do not have the required
|
Notes
The generated API docs for this module show overload signatures, but the
prose is rendered from this public implementation docstring. The explicit
space overload accepts k_space and target_space directly, then
dispatches here through the shared folding construction path.
Examples:
Build and apply only the right folding transform:
T_right = get_band_fold(transform, tensor, side="right")
routed = tensor @ T_right.h(-2, -1)
Build both one-sided folding transforms explicitly:
T_left = get_band_fold(transform, tensor, side="left")
T_right = get_band_fold(transform, tensor, side="right")
folded = T_left @ tensor @ T_right.h(-2, -1)
Build the folding transform directly from symbolic spaces:
T_left = get_band_fold(transform, k_space, hilbert_space, device=device)
See Also
bandfold(transform, tensor, opt=...)
Public wrapper that applies this block folding transform to a band
tensor.
get_band_transform(t, tensor, side=...)
Symmetry-transform analogue that constructs a momentum-block transform
without Brillouin-zone folding.
Source code in src/qten/bands.py
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 | |
bandtransform
bandtransform(
t: Opr,
tensor: Tensor,
opt: Literal["left", "right", "both"] = "both",
) -> Tensor
Apply a basis transform to a momentum-resolved operator tensor.
The expected tensor shape is (K, B_left, B_right) where K is a
MomentumSpace and
B_left, B_right are
HilbertSpace axes. This
function applies the operator-induced basis transform on the selected
Hilbert-space legs of the band tensor.
For each transformed side, a k-dependent matrix is built from the action of
t on the Hilbert-space basis and Fourier transforms that connect Bloch and
real-space sectors.
Mathematical action
Let \(B_{\mathrm{left}}\) and \(B_{\mathrm{right}}\) be the input Hilbert-space bases and let the corresponding transformed bases be \(tB_{\mathrm{left}}\) and \(tB_{\mathrm{right}}\). After wrapping transformed sites back to the home unit cell, the finite Fourier transform contributes a momentum-dependent phase. The resulting basis-change matrices are denoted \(U_t^{(\mathrm{left})}(k)\) and \(U_t^{(\mathrm{right})}(k)\). When routed contributions are collapsed back onto the transformed momentum grid, the transformed band block is one of:
opt="left":
\(H'(t k) = U_t^{(\mathrm{left})}(k)\,H(k)\)
opt="right":
\(H'(t k) = H(k)\,U_t^{(\mathrm{right})}(k)^\dagger\)
opt="both":
\(H'(t k) = U_t^{(\mathrm{left})}(k)\,H(k)\,U_t^{(\mathrm{right})}(k)^\dagger\)
Momentum handling
The action on Momentum is treated as
a relabeling or permutation of sectors. For opt="both", the output
tensor carries the transformed momentum axis
mapped_kspace = {t @ k | k in kspace}. For opt="left" and
opt="right", the implementation instead preserves a routed
MomentumBlockSpace pair
axis so each source block remains attached to its transformed target
sector. In either case, the selected Hilbert-space transforms are applied
before any optional collapse back to a plain
MomentumSpace.
Notes
This function accepts a general Opr, but not every Opr is valid here.
In practice, t must act coherently across the real-space and
momentum-space labels carried by the tensor:
t @ k must be defined for each
Momentum in the first tensor axis.
t @ psi must be defined for each
U1Basis in the Hilbert-space
axes, in particular for the
Offset irrep stored inside each basis
state.
The Hilbert-space action and momentum action must be dual-compatible, so
that the Fourier transform remains consistent after applying t.
For each selected side, after applying
FuncOpr(Offset, Offset.fractional),
the transformed Hilbert space must have the same rays as the sampled input
basis on that side. Otherwise the transformed basis does not close on that
band leg and this function raises ValueError.
Operators that only act on abstract U1Basis values or only on Momentum
values are not sufficient. The operator must provide matching actions on
site offsets and crystal momentum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Opr
|
Operator to apply. It must satisfy the compatibility conditions described in the notes below. |
required |
tensor
|
Tensor
|
Momentum-space tensor with dims
|
required |
opt
|
Literal['left', 'right', 'both']
|
Which matrix legs to transform. |
'both'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the tensor dims do not have the required
|
Source code in src/qten/bands.py
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 | |
bandfold
bandfold(
transform: BasisTransform,
tensor: Tensor,
opt: Literal["left", "right", "both"] = "both",
) -> Tensor
Fold a momentum-resolved band tensor into the Brillouin zone of a transformed lattice basis.
The input tensor is expected to have dimensions
(MomentumSpace, HilbertSpace, HilbertSpace). The basis transformation is
applied to the direct lattice underlying the
MomentumSpace axis, which
produces a new Brillouin zone and a corresponding momentum remapping. One
or both HilbertSpace legs
are enlarged to match the transformed unit cell, Fourier-space changes of
basis are applied, and the momentum sectors are then gathered into the new
momentum grid. If multiple basis states share the same site offset in the
sampled Hilbert space, folding preserves all of them at the corresponding
folded-cell site.
Mathematical action
A forward basis transform coarsens the direct lattice basis, so the reciprocal Brillouin zone shrinks and multiple old momenta fold onto one new momentum sector. If \(F_{\mathrm{left}}(k)\) and \(F_{\mathrm{right}}(k)\) are the Fourier-based change-of-basis maps on the selected tensor legs, then, after routed contributions are collapsed onto the folded momentum grid, the folded block is one of:
opt="left":
\(H_{\mathrm{fold}}(k') \mathrel{+}= F_{\mathrm{left}}(k)^\dagger H(k)\)
opt="right":
\(H_{\mathrm{fold}}(k') \mathrel{+}= H(k) F_{\mathrm{right}}(k)\)
opt="both":
\(H_{\mathrm{fold}}(k') \mathrel{+}= F_{\mathrm{left}}(k)^\dagger H(k) F_{\mathrm{right}}(k)\)
with \(k' = \mathrm{fold}(k)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
BasisTransform
|
Basis change applied to the direct lattice associated with the momentum axis. |
required |
tensor
|
Tensor
|
Rank-3 tensor with dimensions
|
required |
opt
|
Literal['left', 'right', 'both']
|
Which matrix legs to fold. |
'both'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the tensor is not rank-3, if the momentum space is empty, or if the momentum axis does not belong to a single Brillouin zone. Also raised if the sampled Hilbert basis on a selected side has no states at a required unit-cell offset during the folding construction. |
TypeError
|
If the momentum axis is not a
|
Source code in src/qten/bands.py
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 | |
bandunfold
bandunfold(
inverse_transform: InverseBasisTransform, tensor: Tensor
) -> Tensor
Unfold a folded momentum-resolved band tensor using an inverse basis transform.
The input is expected to have dimensions (MomentumSpace, HilbertSpace,
HilbertSpace) where the
MomentumSpace axis lives on a
transformed (folded) Brillouin zone. The inverse transform maps that folded
lattice back to the primitive one and recovers dimensions
(K_primitive, B_primitive, B_primitive).
Mathematical action
Unfolding routes each primitive momentum \(k\) to its parent folded
momentum \(\bar{k}\), gathers \(H_{\mathrm{fold}}(\bar{k})\), and then
projects it back to the primitive-cell basis with a Fourier map \(F(k)\):
\(H_{\mathrm{unfold}}(k)
= F(k)\,H_{\mathrm{fold}}(\bar{k})\,F(k)^\dagger\). In code, the parent-sector lookup is tensor.data[k_indices.data], and the
final basis projection is f @ gathered @ f.h(-2, -1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inverse_transform
|
InverseBasisTransform
|
Inverse basis transform that maps the folded direct lattice back to the primitive lattice. |
required |
tensor
|
Tensor
|
Rank-3 folded band tensor with dimensions
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Unfolded tensor on the primitive Brillouin-zone
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in src/qten/bands.py
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 | |
bandcounts
bandcounts(tensor: Tensor) -> Tensor
Count nonzero columns in each momentum-sector matrix.
The input tensor is expected to have dimensions
(MomentumSpace, HilbertSpace, StateSpace). For each momentum sector, the
trailing two axes are treated as a matrix with rows labelled by the
HilbertSpace axis and
columns labelled by the trailing
StateSpace axis. A column is
counted if any entry in that column is nonzero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
Rank-3 tensor with dimensions |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Integer-valued tensor with dimensions |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the tensor axes are not |
Source code in src/qten/bands.py
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 | |
bandfillings
bandfillings(tensor: Tensor, frac: float) -> Tensor
Return eigenvectors for occupied bands up to a filling fraction.
The input tensor is expected to have dimensions
(MomentumSpace, HilbertSpace, HilbertSpace), where the
MomentumSpace axis indexes
momentum sectors and the two
HilbertSpace axes form the
Hamiltonian matrix at each momentum. The tensor is diagonalized at each
momentum, then eigenvectors with energies below the global filling
threshold are packed into an output
IndexSpace.
Mathematical convention
Each momentum block is diagonalized as \(H(k) V(k) = V(k) E(k)\), and the eigenvectors whose energies fall below the global filling threshold
are retained. If frac = f, the target number of occupied states is
\(N_{\mathrm{occ}} = \left\lfloor f\,N_k\,N_b \right\rfloor\), where \(N_k\) is the number of momentum sectors and \(N_b\) is the number of bands per sector. Degenerate states at the threshold are included together.
Degenerate threshold behavior
If one state in a degenerate set is filled, all states in that set are filled. The output index dimension is therefore the maximum number of filled states over all momentum sectors, and sectors with fewer filled states are padded with zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
Band-resolved tensor with dimensions
|
required |
frac
|
float
|
Filling fraction in the inclusive range |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Eigenvector tensor with dimensions |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the tensor axes are not |
ValueError
|
If |
Source code in src/qten/bands.py
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 | |
svd_projection
svd_projection(
target: Tensor[Any],
source: Tensor[Any],
svd_threshold: float = 0.1,
infer_lattice: bool = False,
) -> Tensor[Any]
Align target states to a source-defined gauge via sectorwise SVD.
This function computes the sectorwise overlap between target and source states, extracts the polar/unitary factor of that overlap via SVD, and rotates the target columns into the source-selected gauge.
Mathematical convention
For each momentum sector \(k\), collect the target columns into a matrix \(T(k)\) and the source columns into a matrix \(S(k)\). If the target Hilbert dimension is \(N\), the target rank is \(r_t\), and the source rank is \(r_s\), then \(T(k) \in \mathbb{C}^{N \times r_t}\) and \(S(k) \in \mathbb{C}^{N \times r_s}\).
The method proceeds sector by sector:
-
Form the overlap matrix \(M(k) = T(k)^\dagger S(k)\), so \(M(k) \in \mathbb{C}^{r_t \times r_s}\).
-
Compute the singular value decomposition \(M(k) = U(k)\,\Sigma(k)\,V(k)^\dagger\).
-
Discard the singular values and keep only the unitary/polar factor \(Q(k) = U(k)\,V(k)^\dagger\).
-
Rotate the target states by that factor: \(T_{\mathrm{proj}}(k) = T(k)\,Q(k)\).
This output has the same row space as the target states, but its column gauge is chosen to optimally match the source states in the orthogonal Procrustes sense. Equivalently, \(Q(k)\) solves \(\min_Q \|T(k)Q - S(k)\|_F\) over partial isometries \(Q\) of the form \(Q = U V^\dagger\) induced by the SVD of \(T(k)^\dagger S(k)\).
When \(r_t \neq r_s\), the overlap \(M(k)\) is rectangular, so the method still makes sense: it returns the best SVD-induced alignment from the target column space toward the source column space without requiring equal rank.
If either target or source uses zero-padded columns to represent
an inconsistent number of states across the Brillouin zone, those padded
columns are ignored on a per-momentum basis when forming the SVD. The
projection therefore acts only on the intersection of nonzero target
columns and nonzero source columns at each momentum sector.
In the default branch, or whenever the source metadata is insufficient to
infer a lattice-backed column space, the result is a plain rank-3
Tensor with the input
MomentumSpace axis preserved.
If infer_lattice=True and the source column space is a
HilbertSpace carrying
Offset labels, the function tries to
build a lattice description directly from those labels.
A simple example is:
- suppose the source-side basis contains states such as \(|r_1\rangle \otimes |\alpha\rangle\), \(|r_2\rangle \otimes |\beta\rangle\), \(|r_1\rangle \otimes |\gamma\rangle\);
- then the new unit cell is built from the distinct site positions \(r_1, r_2\) in the order they first appear;
- the extra labels \(|\alpha\rangle\), \(|\beta\rangle\), \(|\gamma\rangle\) are kept, but they are now understood as living on that newly built unit cell.
More concretely, the construction:
- rebases the source offsets onto the direct lattice of the input momentum grid;
- converts those offsets to fractional coordinates;
- uses the distinct fractional positions as the sites of a new unit cell;
- keeps the same overall lattice basis and boundary conditions, so only the unit-cell contents are being rebuilt.
In that branch, the return value becomes a
MomentumBlockTensor. Its leading
MomentumBlockSpace
stores pairs (k_old, k_new), where k_old is the original momentum
sector from the input tensor and k_new is the momentum sector in the
newly created reciprocal lattice with the same fractional momentum
coordinate.
The last two tensor legs also become more specific:
- the middle leg stays in the original target/band Hilbert space;
- the last leg becomes the Bloch space built from the newly created lattice, so its basis states now refer to the newly constructed unit-cell sites rather than the original source labels.
If this lattice inference cannot be carried out, the function simply falls back to the plain rank-3 projected tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Tensor
|
Target states with dims
|
required |
source
|
Tensor
|
Source states with dims |
required |
svd_threshold
|
float
|
Warn if the minimum singular value of the overlap drops below this threshold, which signals linearly dependent source states or poor projection onto the target subspace after zero-padded columns have been ignored. |
0.1
|
infer_lattice
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Projected states. The fallback result has dims
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If either input tensor is not rank 3. |
TypeError
|
If either input tensor does not have
|
Source code in src/qten/bands.py
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 | |
bandselect
bandselect(
tensor: Tensor,
**kwargs: Dict[
str,
Union[
slice,
Tuple[int, ...],
Tuple[float, float],
Callable[[float], bool],
],
],
) -> Dict[str, Tensor]
Select specific bands from a band-resolved Tensor based on criteria provided in kwargs.
The input Tensor is diagonalized at each
MomentumSpace sector. Each
keyword argument defines one named selection criterion, and the returned
dictionary maps each name to a tensor containing the matching eigenvectors.
Outputs have dimensions (MomentumSpace, HilbertSpace, IndexSpace), where
HilbertSpace labels the band
basis and IndexSpace labels the
selected states for each criterion.
Mathematical convention
For each momentum sector, \(H(k) v_n(k) = \epsilon_n(k) v_n(k)\), and each criterion selects a subset of band labels \(n\). The returned
tensor packs the matching eigenvectors \(v_n(k)\) into an
IndexSpace, padding sectors with
fewer matches by zero columns.
Supported criteria
slice: select bands by sorted energy index, such asslice(0, 2)for the two lowest-energy bands.Tuple[int, ...]: select explicit sorted band indices, such as(0, 2)for the lowest and third-lowest bands.Tuple[float, float]: select an inclusive energy range.Callable[[float], bool]: select energies for which the callable returnsTrue.
If a criterion matches no bands in all momentum sectors, the corresponding
output tensor has an IndexSpace of dimension zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
Band-resolved tensor with dimensions
|
required |
kwargs
|
Dict[str, Union[slice, Tuple[int, ...], Tuple[float, float], Callable[[float], bool]]]
|
Named band-selection criteria. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Tensor]
|
Mapping from criterion name to selected eigenvector tensor with
dimensions |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the tensor axes are not |
ValueError
|
If |
IndexError
|
If an explicit integer band index is outside the available band range. |
Source code in src/qten/bands.py
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 | |
nearest_bands
nearest_bands(
h_k: Tensor,
point: Union[str, Sequence[float]] = "Gamma",
close_to: float = 0.0,
tol: float = 1e-06,
points: Optional[Dict[str, Sequence[float]]] = None,
) -> Tensor
Project a momentum-resolved Hamiltonian onto bands selected at one k-point.
The input h_k is diagonalized at a single anchor momentum \(k_0\).
Eigenvectors whose anchor eigenvalues lie within tol of close_to are
collected into a rectangular matrix \(V\). If the input Hilbert dimension is
\(N\) and \(S\) bands are selected, then V has shape (N, S) and the
returned tensor stores \(V^\dagger H(k) V\) for every momentum \(k\).
Projection convention
At the selected anchor sector, the code computes
eigenvalues, eigenvectors = torch.linalg.eigh(H_anchor). The columns of
eigenvectors with \(|\epsilon_n(k_0) - \mathrm{close\_to}| \le \mathrm{tol}\)
form \(V\). The projected block at each momentum is
\(H_{\mathrm{proj}}(k) = V^\dagger H(k) V\).
In implementation terms, this projection is the einsum
torch.einsum("ia,kab,bj->kij", V_dag, h_k.data, V).
Anchor selection
- A string
pointis looked up inpoints. "Gamma"defaults to the fractional origin when absent frompoints.- A coordinate sequence is interpreted directly as fractional coordinates.
- Fractional-coordinate differences are wrapped by subtracting the nearest integer, so equivalent periodic coordinates select the same anchor.
If no eigenvalue falls inside the tolerance window, the result has two
zero-dimensional IndexSpace axes
and data shape (len(kspace), 0, 0).
Notes
The selected subspace is fixed by the anchor momentum only. The same anchor eigenvector matrix \(V\) is applied to every \(H(k)\); this is a projection onto an anchor-defined subspace, not a separately diagonalized band selection at each momentum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h_k
|
Tensor
|
Hamiltonian tensor with dims
( |
required |
point
|
str or Sequence[float]
|
Anchor k-point. String labels are resolved through |
"Gamma"
|
close_to
|
float
|
Target eigenvalue for the subspace selection. |
0.0
|
tol
|
float
|
Half-width of the eigenvalue window around |
1e-6
|
points
|
dict[str, Sequence[float]]
|
Mapping from labels to fractional coordinates. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Projected Hamiltonian with dims
( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If the input dimensions are not
|
KeyError
|
If |
Source code in src/qten/bands.py
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 | |
proj_wannierization
proj_wannierization(
eigenvectors: Tensor[Any],
seeds: Tensor[Any],
svd_threshold: float = 0.1,
wannierize_lattice: bool = True,
) -> Tensor[Any]
Perform projective Wannierization from localized real-space trial orbitals.
This helper implements the standard two-stage projective-Wannier workflow:
- Fourier transform localized seed states into momentum space.
- At each momentum sector, rotate the target band subspace into the gauge that best matches those transformed seeds via the polar/SVD factor of the overlap matrix.
The function is therefore a thin orchestration layer around
fourier_transform() and
svd_projection().
Mathematical convention
Let
\(k \in \mathcal{K}\) denote a sampled momentum,
let \(\{|b\rangle\}_{b=1}^{N_b}\) be the Bloch basis stored on the second
axis of eigenvectors, and let
\(\{|r\rangle\}_{r=1}^{N_r}\) be the localized basis stored on the first
axis of seeds.
Suppose the seed tensor stores coefficients \(A_{r n}\), where \(n = 1, \dots, N_s\) labels the trial orbitals. In matrix form, \(A \in \mathbb{C}^{N_r \times N_s}\).
The discrete Fourier-transform tensor returned by
fourier_transform(k_space, bloch_space, local_seed_space)
is a rank-3 object with entries
where the Kronecker-style matching factor indicates that only localized and Bloch basis states with matching non-offset irreps are connected. In the repository's fractional-coordinate convention, this phase is equivalently \(\exp(-2\pi\mathrm{i}\,\kappa \cdot n)\).
For each momentum sector, the real-space seeds are lifted to Bloch form as
with \(S(k) \in \mathbb{C}^{N_b \times N_s}\).
The input eigenvectors stores the target subspace as matrices
whose columns span the band manifold to be Wannierized.
The gauge-fixing step then forms the overlap
computes its singular value decomposition
discards the singular values, and keeps only the polar/unitary factor
The projected Wannier-gauge states are then
This is exactly the orthogonal-Procrustes solution used by
svd_projection(): it preserves the target
column space while choosing the column gauge that best aligns the target
states with the Fourier-transformed trial orbitals.
Step-by-step behavior
Given eigenvectors and seeds, the code performs:
- Read the shared momentum grid
k_space = eigenvectors.dims[0]. - Read the Bloch Hilbert space
bloch_space = eigenvectors.dims[1]. - Read the localized seed row basis
local_seed_space = seeds.dims[0]. - Build the discrete Fourier transform tensor
F = fourier_transform(k_space, bloch_space, local_seed_space). - Convert localized trial orbitals into momentum-resolved trial orbitals
by the tensor contraction
crystal_seeds = F @ seeds. - Call
svd_projection(eigenvectors, crystal_seeds, svd_threshold, infer_lattice=wannierize_lattice). - Return the projected states.
Interpretation of the tensor legs
eigenvectorsmust have dims(MomentumSpace, HilbertSpace, D_target), where the first two axes represent momentum and Bloch basis, and the last axis enumerates the target band columns.seedsmust have dims(HilbertSpace_local, D_seed), where the first axis is a localized real-space basis containingOffsetlabels, and the second axis enumerates trial orbitals.- After Fourier transformation,
crystal_seedshas dims(MomentumSpace, HilbertSpace, D_seed).
Here D_target and D_seed may be different state-space types. The most
common case is that both are
IndexSpace, but the seed-column
space may also be a
HilbertSpace.
Lattice-aware output
The wannierize_lattice flag is forwarded to
svd_projection(), but lattice rebuilding is
only possible when the column space of the transformed seeds still
carries a HilbertSpace
with meaningful Offset labels.
Concretely:
- if
seeds.dims[1]is anIndexSpace, projection still works exactly as described above, but no lattice-backed output basis can be inferred, so the result remains a plain rank-3 tensor; - if
seeds.dims[1]is aHilbertSpace, then after Fourier transformation the source columns retain those symbolic labels, andsvd_projection(..., infer_lattice=True)may return aMomentumBlockTensorwhose final Hilbert leg has been rebuilt on the inferred Wannier lattice.
Numerical behavior
The SVD warning threshold is interpreted exactly as in
svd_projection(): if the minimum singular
value of the overlap becomes smaller than svd_threshold, a warning is
emitted because the trial orbitals may poorly span the target subspace or
may be nearly linearly dependent after projection. Zero-padded columns, if
present in the target or source, are ignored sector by sector by the
underlying projection routine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eigenvectors
|
Tensor
|
Target band states with dims
|
required |
seeds
|
Tensor
|
Localized trial orbitals with dims
|
required |
svd_threshold
|
float
|
Warning threshold passed to
|
0.1
|
wannierize_lattice
|
bool
|
Forwarded as |
True
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Projected Wannier-gauge states. Usually this is a rank-3 tensor with
dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
Source code in src/qten/bands.py
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 | |