qten.symbolics.ops
Module reference for qten.symbolics.ops.
ops
Convenience operators for symbolic Hilbert-space transformations.
This module provides small functional constructors for common symbolic operations: translating or rebasing spatial irreps, expanding Bloch Hilbert spaces across real-space regions, constructing Hamiltonian representations, and building basis transforms between position and momentum descriptions.
Repository usage
Use these helpers when composing FuncOpr
or converting between HilbertSpace
representations. The underlying basis, span, and operator classes are defined in
qten.symbolics.hilbert_space.
translate_opr
translate_opr(d: OffsetType) -> FuncOpr[OffsetType]
Build an operator that translates irreps of the same concrete type by d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Offset | Momentum
|
Translation to add to the targeted irrep. |
required |
Returns:
| Type | Description |
|---|---|
FuncOpr
|
Operator applying \(x \mapsto x + d\) to irreps whose concrete type
matches |
Source code in src/qten/symbolics/ops.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
rebase_opr
rebase_opr(space: S) -> FuncOpr[OffsetType]
Build an operator that rebases spatial irreps into space.
For affine spaces this targets Offset irreps. For reciprocal lattices it
targets Momentum irreps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
AffineSpace | ReciprocalLattice
|
Target space into which matching spatial irreps are rebased. |
required |
Returns:
| Type | Description |
|---|---|
FuncOpr
|
Operator applying \(r \mapsto r.\mathrm{rebase}(\mathrm{space})\) to
matching spatial irreps. In code, this calls |
Source code in src/qten/symbolics/ops.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
fractional_opr
fractional_opr() -> FuncOpr[Offset]
fractional_opr(T: type[OffsetType]) -> FuncOpr[OffsetType]
Build an operator that replaces a spatial irrep by its fractional form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
type[Offset] | type[Momentum] | None
|
Exact irrep type to target. Because |
None
|
Returns:
| Type | Description |
|---|---|
FuncOpr
|
Operator replacing matching spatial irreps by |
Source code in src/qten/symbolics/ops.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
region_hilbert
region_hilbert(
bloch_space: HilbertSpace, region: Sequence[Offset]
) -> HilbertSpace
Expand a Bloch HilbertSpace across a real-space region by unit-cell subgroup.
The input bloch_space is first partitioned by the fractional part of each
basis state's Offset irrep, so all sub-basis states that occupy the same
position within the unit cell stay grouped together. Each offset in
region is treated as a full target-site offset that already includes its
unit-cell position. A region site r therefore selects the subgroup whose
fractional offset equals r.fractional(), and every state in that subgroup
is copied with its Offset replaced by r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bloch_space
|
HilbertSpace
|
Source basis to replicate. Each basis element must contain an |
required |
region
|
Sequence[Offset]
|
Full target offsets where the matching unit-cell sub-basis should be placed. |
required |
Returns:
| Type | Description |
|---|---|
HilbertSpace
|
A Hilbert space containing one copied basis state for each compatible
pair of region offset and unit-cell subgroup, with output offsets taken
from |
Raises:
| Type | Description |
|---|---|
ValueError
|
Propagated if a basis element in |
Notes
Grouping is done by fractional Offset, preserving the original basis
order inside each subgroup. Output order follows region.
Source code in src/qten/symbolics/ops.py
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 | |
hilbert_opr_repr
hilbert_opr_repr(
opr: Opr,
space: HilbertSpace,
*,
device: Optional[Device] = None,
) -> Tensor
Return the matrix representation of an operator on a Hilbert-space basis.
Let \(\mathrm{space} = \mathrm{span}\{|e_i\rangle\}\) be the input
HilbertSpace and let opr
act on each basis state to produce
\(\mathrm{span}\{\mathrm{opr}\,|e_j\rangle\}\). In code, the transformed
basis is produced by opr @ space. This function constructs the
corresponding representation matrix
\(M_{ij} = \langle e_i | \mathrm{opr} | e_j \rangle\), implemented as the
cross-Gram matrix between the original basis and its
transformed image. The resulting Tensor therefore represents opr in the
basis supplied by space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opr
|
Opr
|
Operator whose representation is to be computed. |
required |
space
|
HilbertSpace
|
Basis in which the operator is represented. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Square tensor whose entries are the matrix elements of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
The output dimensions are relabeled back onto space, so the returned
tensor can be interpreted directly as an endomorphism of that Hilbert
space.
Source code in src/qten/symbolics/ops.py
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 | |
match_indices
match_indices(
src: StateSpace[T],
dest: StateSpace[T],
matching_func: Callable[[T], T],
*,
device: Optional[Device] = None,
) -> Tensor[torch.LongTensor]
Build destination indices for matching elements of src into dest.
This helper is intended for indexed accumulation patterns such as
index_add, where each element of src is matched to exactly one element
of dest and multiple source elements may map to the same destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
StateSpace[T]
|
Source state space whose element order defines the output index order. |
required |
dest
|
StateSpace[T]
|
Destination state space whose integer positions are used as the returned indices. |
required |
matching_func
|
Callable[[T], T]
|
Function mapping each source element to its matching destination element. |
required |
device
|
Optional[Device]
|
Device to place the returned index tensor on, by default |
None
|
Returns:
| Type | Description |
|---|---|
Tensor[LongTensor]
|
Rank-1 integer tensor with dims |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any source element maps to an element that is not present in |
Source code in src/qten/symbolics/ops.py
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 | |
interpolate_reciprocal_path
interpolate_reciprocal_path(
recip: ReciprocalLattice,
waypoints: Sequence[Union[tuple[float, ...], str]],
n_points: int = 100,
labels: Optional[Sequence[str]] = None,
points: Optional[Dict[str, tuple[float, ...]]] = None,
) -> BzPath
Build a dense reciprocal-space sample along a piecewise-linear path.
Waypoints are interpreted as fractional reciprocal coordinates unless they
are strings. String waypoints are resolved through points and also supply
default labels when labels is omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recip
|
ReciprocalLattice
|
Reciprocal lattice whose basis converts fractional waypoints to Cartesian coordinates for distance allocation. |
required |
waypoints
|
Sequence[tuple[float, ...] | str]
|
At least two waypoint coordinates or names. Named waypoints must appear
in |
required |
n_points
|
int
|
Total number of dense path samples, including all waypoints. |
100
|
labels
|
Optional[Sequence[str]]
|
Labels for waypoints. If omitted, names or coordinate strings are used. |
None
|
points
|
Optional[Dict[str, tuple[float, ...]]]
|
Mapping used to resolve string waypoints to fractional coordinates. |
None
|
Returns:
| Type | Description |
|---|---|
BzPath
|
Path metadata containing the unique momentum space, waypoint labels, dense-sample-to-momentum mapping, and cumulative path positions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than two waypoints are supplied, a named waypoint is missing,
waypoint dimensions do not match the reciprocal lattice, |
Source code in src/qten/symbolics/ops.py
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 | |