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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
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
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 | |
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
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 | |
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
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 | |