qten.symbolics
Package reference for qten.symbolics.
symbolics
Symbolic basis, operator, and state-space layer for QTen.
This package hosts the symbolic objects that give QTen tensors their semantic axis metadata: basis states, Hilbert spaces, abstract operators, state spaces, and helper constructors acting on those structures.
Core symbolic values
Multiple is the scalar-times-object wrapper used
for factored symbolic coefficients. U1Basis
is the atomic symbolic basis state, U1Span
is an ordered span of basis states, and HilbertSpace
stores symbolic basis sectors as a state space.
Operators
Opr is the base symbolic operator class.
FuncOpr lifts a Python callable on one
irrep type. Convenience constructors include
translate_opr,
rebase_opr, and
fractional_opr.
State-space utilities
State-space types include StateSpace,
MomentumSpace,
BroadcastSpace,
IndexSpace,
StateSpaceFactorization,
and BzPath. Helper functions include
brillouin_zone,
embedding_order,
permutation_order,
restructure, and
same_rays.
Hilbert-space helpers
Hilbert-space helper functions include
region_hilbert,
hilbert_opr_repr,
match_indices, and
interpolate_reciprocal_path.
Exported API
Multiple
dataclass
Multiple(coef: Number, base: BaseType)
Bases: Generic[BaseType]
Represent a scalar coefficient multiplied by an arbitrary base object.
The class is intentionally minimal: it stores the coefficient and base separately so higher-level symbolic routines can postpone expansion or simplification until needed. This avoids unnecessary SymPy work in hot paths where the structured form is more efficient than immediately building a combined symbolic expression.
Attributes:
| Name | Type | Description |
|---|---|---|
coef |
Number
|
Numeric SymPy coefficient applied to |
base |
BaseType
|
The symbolic or scalar object being multiplied by |
coef
instance-attribute
coef: Number
Numeric SymPy coefficient applied to base, kept separate so callers can
accumulate scalar factors without eagerly rebuilding symbolic expressions.
base
instance-attribute
base: BaseType
The symbolic or scalar object being multiplied by coef, preserved in
structured form for later operator application or simplification.
BzPath
dataclass
BzPath(
k_space: MomentumSpace,
labels: tuple,
waypoint_indices: tuple,
path_order: tuple,
path_positions: tuple,
)
A Brillouin-zone path through high-symmetry waypoints.
Attributes:
| Name | Type | Description |
|---|---|---|
k_space |
MomentumSpace
|
Unique momentum points sampled along the path. |
labels |
tuple
|
Labels for the waypoints in path order. |
waypoint_indices |
tuple
|
Indices into the dense path where each waypoint occurs. |
path_order |
tuple
|
For each dense path sample, index of the corresponding unique momentum
in |
path_positions |
tuple
|
Cumulative Cartesian arc-length coordinate for each dense path sample. |
k_space
instance-attribute
k_space: MomentumSpace
Unique momentum points sampled along the path, with duplicates across segments removed while preserving the path's effective traversal order.
labels
instance-attribute
labels: tuple
Labels for the waypoints in path order, typically high-symmetry point names used for plotting.
waypoint_indices
instance-attribute
waypoint_indices: tuple
Indices into the dense path where each waypoint occurs, suitable for axis ticks or segment markers in band-structure plots.
path_order
instance-attribute
path_order: tuple
For each dense path sample, index of the corresponding unique momentum in
k_space. This maps the full piecewise-linear path back onto the unique
momentum list.
path_positions
instance-attribute
path_positions: tuple
Cumulative Cartesian arc-length coordinate for each dense path sample, used as the continuous x-axis parameter along the path.
BroadcastSpace
dataclass
BroadcastSpace(structure: OrderedDict[T, int])
Bases: StateSpace[_BAxis]
Metadata marker for singleton/broadcast tensor axes.
Design intent
BroadcastSpace represents an axis that behaves like a size-1 axis under
tensor broadcasting. It is used to model dimensions introduced by
unsqueeze, None indexing, or other operations where data may be
expanded without introducing a concrete physical basis.
Structure semantics
BroadcastSpace stores a private singleton marker in structure:
OrderedDict({_BAxis(): 0}).
This keeps the axis dimension at 1 while still providing a stable
coordinate for structure-based index mapping helpers.
Implication for index mapping
For BroadcastSpace -> BroadcastSpace, embedding_order(...) resolves to
(0,). This is intentional and allows consumers that build runtime index
coordinates from structure mappings to treat broadcast axes as a singleton
axis at position 0.
The _BAxis marker is internal implementation detail. It is not a physical
basis element and should not be relied on outside broadcast-axis plumbing.
Compatibility rules
Multimethod rules in this module treat BroadcastSpace as compatible
with any StateSpace in same_rays(...), and as neutral in
__add__(...). The neutral-addition behavior is BroadcastSpace + X -> X,
X + BroadcastSpace -> X, and
BroadcastSpace + BroadcastSpace -> BroadcastSpace.
This makes it suitable as a placeholder axis that can be promoted to a concrete state space during alignment/broadcast operations.
Attributes:
| Name | Type | Description |
|---|---|---|
structure |
OrderedDict
|
Private singleton mapping |
dim
property
dim: int
The total size of the vector space.
structure
class-attribute
instance-attribute
structure: OrderedDict[_BAxis, int] = field(
default_factory=lambda: OrderedDict({_BAxis(): 0}),
init=False,
)
Private singleton mapping OrderedDict({_BAxis(): 0}) used to encode a
size-1 broadcast axis. The stored marker is internal and exists only so
structure-based helpers can consistently refer to the unique broadcast slot.
__str__
class-attribute
instance-attribute
__str__ = __repr__
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
elements
elements() -> tuple[T, ...]
Return the spatial elements as a tuple.
Source code in src/qten/symbolics/state_space.py
83 84 85 86 | |
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
__len__
__len__() -> int
Return the number of spatial elements.
Source code in src/qten/symbolics/state_space.py
88 89 90 | |
__iter__
__iter__() -> Iterator[T]
Iterate over spatial elements.
Source code in src/qten/symbolics/state_space.py
92 93 94 | |
__getitem__
__getitem__(v: int) -> T
__getitem__(v: slice | range) -> Self
__getitem__(v: Sequence[int]) -> Self
Index into the state-space by element position.
Supported forms
space[i] returns a single spatial element by position, including
negative indices. space[start:stop:step] returns a new space with the
selected elements in slice order. space[range(...)] returns a new
space with the range-selected elements. space[[i, j, ...]] returns a
new space with elements in explicit index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[int, slice, range, Sequence[int]]
|
Index selector. Sequences must contain unique integers; negative
integers are normalized relative to |
required |
Returns:
| Type | Description |
|---|---|
Spatial or StateSpace
|
A spatial element for |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an integer index is out of bounds. |
TypeError
|
If |
ValueError
|
If a sequence selector contains duplicate indices. |
Source code in src/qten/symbolics/state_space.py
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 | |
same_rays
same_rays(other: StateSpace) -> bool
Check if this state space has the same rays as another, i.e., they have the same set of spatial keys regardless of order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
The other state space to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both state spaces have the same rays, |
Source code in src/qten/symbolics/state_space.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
map
map(func: Callable[[T], T]) -> Self
Map the spatial elements of this state space using a provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T]
|
A function that takes a spatial element and returns a transformed spatial element. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space with the transformed spatial elements. |
Source code in src/qten/symbolics/state_space.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
filter
filter(pred: Callable[[T], bool]) -> Self
Return the subspace containing elements where pred(element) is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[T], bool]
|
Predicate applied to each element in basis order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space of the same concrete type containing only the selected elements, with indices repacked contiguously. |
Source code in src/qten/symbolics/state_space.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
tensor_product
tensor_product(other: Self) -> Self
Return the tensor-product state space of this space and another space.
This method defines the protocol used by the @ operator on
StateSpace instances. The
base class cannot construct a generic product because it does not know
how to combine two elements of type T. Concrete subclasses must
implement the element-level product and rebuild a contiguous
structure for the resulting basis.
Implementations should preserve deterministic product ordering. The
convention used by concrete tensor-product spaces in QTen is the
Cartesian product order of self.elements() and other.elements(),
where elements from self vary slowest and elements from other vary
fastest. The returned space should be the same concrete state-space
family when the operation is closed over that family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
Right-hand tensor factor. Implementations may require |
required |
Returns:
| Type | Description |
|---|---|
StateSpace
|
New state space representing |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised by the base class. Subclasses that support tensor products must override this method. |
Source code in src/qten/symbolics/state_space.py
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 | |
extract
extract(info_type: type[Any]) -> Any
Extract an object implied by the elements of this state space.
Subclasses may register specialized implementations for supported target types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_type
|
type[Any]
|
Type of metadata or object to extract from this state space. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Extracted object produced by a registered specialization. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no extraction rule is registered for |
Source code in src/qten/symbolics/state_space.py
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 | |
__hash__
__hash__() -> int
Return a hash for the singleton broadcast-axis structure.
BroadcastSpace hashes the
same ordered structure snapshot as
StateSpace. Because the
structure always contains one private _BAxis marker at index 0, the
hash represents this singleton broadcast dimension rather than a
physical basis element.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for the ordered singleton |
Source code in src/qten/symbolics/state_space.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
__repr__
__repr__()
Return the broadcast-axis marker representation.
Returns:
| Type | Description |
|---|---|
str
|
The literal string |
Source code in src/qten/symbolics/state_space.py
771 772 773 774 775 776 777 778 779 780 | |
IndexSpace
dataclass
IndexSpace(structure: OrderedDict[T, int])
Bases: StateSpace[int]
A simple state space where the spatial elements are just integer indices. This can be useful for representing generic tensor dimensions that don't have a specific physical interpretation, such as the virtual bond dimension in a TNS.
dim
property
dim: int
The total size of the vector space.
structure
instance-attribute
structure: OrderedDict[T, int]
An ordered dictionary mapping each spatial component (e.g., Offset,
Momentum) to its single flattened index.
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
elements
elements() -> tuple[T, ...]
Return the spatial elements as a tuple.
Source code in src/qten/symbolics/state_space.py
83 84 85 86 | |
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
__len__
__len__() -> int
Return the number of spatial elements.
Source code in src/qten/symbolics/state_space.py
88 89 90 | |
__iter__
__iter__() -> Iterator[T]
Iterate over spatial elements.
Source code in src/qten/symbolics/state_space.py
92 93 94 | |
__getitem__
__getitem__(v: int) -> T
__getitem__(v: slice | range) -> Self
__getitem__(v: Sequence[int]) -> Self
Index into the state-space by element position.
Supported forms
space[i] returns a single spatial element by position, including
negative indices. space[start:stop:step] returns a new space with the
selected elements in slice order. space[range(...)] returns a new
space with the range-selected elements. space[[i, j, ...]] returns a
new space with elements in explicit index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[int, slice, range, Sequence[int]]
|
Index selector. Sequences must contain unique integers; negative
integers are normalized relative to |
required |
Returns:
| Type | Description |
|---|---|
Spatial or StateSpace
|
A spatial element for |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an integer index is out of bounds. |
TypeError
|
If |
ValueError
|
If a sequence selector contains duplicate indices. |
Source code in src/qten/symbolics/state_space.py
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 | |
same_rays
same_rays(other: StateSpace) -> bool
Check if this state space has the same rays as another, i.e., they have the same set of spatial keys regardless of order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
The other state space to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both state spaces have the same rays, |
Source code in src/qten/symbolics/state_space.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
map
map(func: Callable[[T], T]) -> Self
Map the spatial elements of this state space using a provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T]
|
A function that takes a spatial element and returns a transformed spatial element. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space with the transformed spatial elements. |
Source code in src/qten/symbolics/state_space.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
filter
filter(pred: Callable[[T], bool]) -> Self
Return the subspace containing elements where pred(element) is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[T], bool]
|
Predicate applied to each element in basis order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space of the same concrete type containing only the selected elements, with indices repacked contiguously. |
Source code in src/qten/symbolics/state_space.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
tensor_product
tensor_product(other: Self) -> Self
Return the tensor-product state space of this space and another space.
This method defines the protocol used by the @ operator on
StateSpace instances. The
base class cannot construct a generic product because it does not know
how to combine two elements of type T. Concrete subclasses must
implement the element-level product and rebuild a contiguous
structure for the resulting basis.
Implementations should preserve deterministic product ordering. The
convention used by concrete tensor-product spaces in QTen is the
Cartesian product order of self.elements() and other.elements(),
where elements from self vary slowest and elements from other vary
fastest. The returned space should be the same concrete state-space
family when the operation is closed over that family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
Right-hand tensor factor. Implementations may require |
required |
Returns:
| Type | Description |
|---|---|
StateSpace
|
New state space representing |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised by the base class. Subclasses that support tensor products must override this method. |
Source code in src/qten/symbolics/state_space.py
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 | |
extract
extract(info_type: type[Any]) -> Any
Extract an object implied by the elements of this state space.
Subclasses may register specialized implementations for supported target types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_type
|
type[Any]
|
Type of metadata or object to extract from this state space. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Extracted object produced by a registered specialization. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no extraction rule is registered for |
Source code in src/qten/symbolics/state_space.py
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 | |
__hash__
__hash__() -> int
Return a hash derived from the ordered integer-index structure.
IndexSpace uses the same
structure-based hash as
StateSpace. The hash includes
each integer element and its stored basis index in order. For spaces
produced by linear(size),
this is the hash of the canonical mapping 0 -> 0, 1 -> 1, and so on.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for the ordered |
Source code in src/qten/symbolics/state_space.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | |
linear
staticmethod
linear(size: int) -> IndexSpace
Build a contiguous index space of length size.
The resulting space contains integer keys 0..size-1, each mapped to
the same integer index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of indices in the space. |
required |
Returns:
| Type | Description |
|---|---|
IndexSpace
|
A contiguous |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/qten/symbolics/state_space.py
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 | |
__str__
__str__()
Return a compact index-space summary.
Returns:
| Type | Description |
|---|---|
str
|
Summary containing the index-space size. |
Source code in src/qten/symbolics/state_space.py
870 871 872 873 874 875 876 877 878 879 | |
__repr__
__repr__()
Return the developer representation of this index space.
Returns:
| Type | Description |
|---|---|
str
|
Same value as |
Source code in src/qten/symbolics/state_space.py
881 882 883 884 885 886 887 888 889 890 | |
MomentumSpace
dataclass
MomentumSpace(structure: OrderedDict[T, int])
Bases: StateSpace[Momentum]
Ordered state space of momentum points over one reciprocal lattice.
MomentumSpace is the
reciprocal-space specialization of StateSpace. Its structure
keys are Momentum objects and its
values are the corresponding integer basis indices.
Notes
The class inherits the custom hashing behavior from
StateSpace so instances remain
hashable despite storing an OrderedDict.
dim
property
dim: int
The total size of the vector space.
structure
instance-attribute
structure: OrderedDict[T, int]
An ordered dictionary mapping each spatial component (e.g., Offset,
Momentum) to its single flattened index.
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
elements
elements() -> tuple[T, ...]
Return the spatial elements as a tuple.
Source code in src/qten/symbolics/state_space.py
83 84 85 86 | |
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
__len__
__len__() -> int
Return the number of spatial elements.
Source code in src/qten/symbolics/state_space.py
88 89 90 | |
__iter__
__iter__() -> Iterator[T]
Iterate over spatial elements.
Source code in src/qten/symbolics/state_space.py
92 93 94 | |
__getitem__
__getitem__(v: int) -> T
__getitem__(v: slice | range) -> Self
__getitem__(v: Sequence[int]) -> Self
Index into the state-space by element position.
Supported forms
space[i] returns a single spatial element by position, including
negative indices. space[start:stop:step] returns a new space with the
selected elements in slice order. space[range(...)] returns a new
space with the range-selected elements. space[[i, j, ...]] returns a
new space with elements in explicit index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[int, slice, range, Sequence[int]]
|
Index selector. Sequences must contain unique integers; negative
integers are normalized relative to |
required |
Returns:
| Type | Description |
|---|---|
Spatial or StateSpace
|
A spatial element for |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an integer index is out of bounds. |
TypeError
|
If |
ValueError
|
If a sequence selector contains duplicate indices. |
Source code in src/qten/symbolics/state_space.py
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 | |
same_rays
same_rays(other: StateSpace) -> bool
Check if this state space has the same rays as another, i.e., they have the same set of spatial keys regardless of order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
The other state space to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both state spaces have the same rays, |
Source code in src/qten/symbolics/state_space.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
map
map(func: Callable[[T], T]) -> Self
Map the spatial elements of this state space using a provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T]
|
A function that takes a spatial element and returns a transformed spatial element. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space with the transformed spatial elements. |
Source code in src/qten/symbolics/state_space.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
filter
filter(pred: Callable[[T], bool]) -> Self
Return the subspace containing elements where pred(element) is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[T], bool]
|
Predicate applied to each element in basis order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space of the same concrete type containing only the selected elements, with indices repacked contiguously. |
Source code in src/qten/symbolics/state_space.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
tensor_product
tensor_product(other: Self) -> Self
Return the tensor-product state space of this space and another space.
This method defines the protocol used by the @ operator on
StateSpace instances. The
base class cannot construct a generic product because it does not know
how to combine two elements of type T. Concrete subclasses must
implement the element-level product and rebuild a contiguous
structure for the resulting basis.
Implementations should preserve deterministic product ordering. The
convention used by concrete tensor-product spaces in QTen is the
Cartesian product order of self.elements() and other.elements(),
where elements from self vary slowest and elements from other vary
fastest. The returned space should be the same concrete state-space
family when the operation is closed over that family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
Right-hand tensor factor. Implementations may require |
required |
Returns:
| Type | Description |
|---|---|
StateSpace
|
New state space representing |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised by the base class. Subclasses that support tensor products must override this method. |
Source code in src/qten/symbolics/state_space.py
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 | |
extract
extract(info_type: type[Any]) -> Any
Extract an object implied by the elements of this state space.
Subclasses may register specialized implementations for supported target types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_type
|
type[Any]
|
Type of metadata or object to extract from this state space. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Extracted object produced by a registered specialization. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no extraction rule is registered for |
Source code in src/qten/symbolics/state_space.py
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 | |
__hash__
__hash__() -> int
Return a hash derived from the ordered momentum structure.
MomentumSpace uses the
same structure-based hash as
StateSpace. The hash includes
every Momentum key and its stored
integer basis index in insertion order. This means two momentum spaces
with the same momentum set but different basis order hash differently.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for the ordered |
Source code in src/qten/symbolics/state_space.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
__str__
__str__()
Return a compact momentum-space summary.
Returns:
| Type | Description |
|---|---|
str
|
Summary containing the momentum-space dimension. |
Source code in src/qten/symbolics/state_space.py
535 536 537 538 539 540 541 542 543 544 | |
__repr__
__repr__()
Return a multiline representation with indexed momentum elements.
Returns:
| Type | Description |
|---|---|
str
|
Header plus one line per momentum element in basis order. |
Source code in src/qten/symbolics/state_space.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
StateSpace
dataclass
StateSpace(structure: OrderedDict[T, int])
Bases: Spatial, Convertible, Generic[T], Span[T]
StateSpace is a collection of indices with additional information attached to the elements,
for the case of TNS there are only two types of state spaces: MomentumSpace and HilbertSpace.
MomentumSpace is needed because some tensors are better represented in momentum space, e.g. Hamiltonians
with translational symmetry, while HilbertSpace is needed to represent local degrees of freedom, e.g. spin or fermionic modes.
Attributes:
| Name | Type | Description |
|---|---|---|
structure |
OrderedDict[Spatial, int]
|
An ordered dictionary mapping each spatial component (e.g., |
dim |
int
|
The total dimension of the state space, calculated as the count of elements regardless of their lengths. |
structure
instance-attribute
structure: OrderedDict[T, int]
An ordered dictionary mapping each spatial component (e.g., Offset,
Momentum) to its single flattened index.
dim
property
dim: int
The total size of the vector space.
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
elements
elements() -> tuple[T, ...]
Return the spatial elements as a tuple.
Source code in src/qten/symbolics/state_space.py
83 84 85 86 | |
__len__
__len__() -> int
Return the number of spatial elements.
Source code in src/qten/symbolics/state_space.py
88 89 90 | |
__iter__
__iter__() -> Iterator[T]
Iterate over spatial elements.
Source code in src/qten/symbolics/state_space.py
92 93 94 | |
__hash__
__hash__()
Return a hash derived from the ordered state-space structure.
The hash is computed from tuple(self.structure.items()), so it
depends on both the spatial elements and their stored integer indices in
insertion order. Two state spaces with the same elements but a different
order, or with the same elements mapped to different integer positions,
intentionally produce different hashes.
This custom implementation is required because structure is an
OrderedDict, which is mutable and unhashable by itself. The state-space
dataclasses are frozen, so the tuple snapshot is stable as long as the
contained spatial elements are themselves hashable and immutable.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for the ordered |
Source code in src/qten/symbolics/state_space.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
__getitem__
__getitem__(v: int) -> T
__getitem__(v: slice | range) -> Self
__getitem__(v: Sequence[int]) -> Self
Index into the state-space by element position.
Supported forms
space[i] returns a single spatial element by position, including
negative indices. space[start:stop:step] returns a new space with the
selected elements in slice order. space[range(...)] returns a new
space with the range-selected elements. space[[i, j, ...]] returns a
new space with elements in explicit index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[int, slice, range, Sequence[int]]
|
Index selector. Sequences must contain unique integers; negative
integers are normalized relative to |
required |
Returns:
| Type | Description |
|---|---|
Spatial or StateSpace
|
A spatial element for |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an integer index is out of bounds. |
TypeError
|
If |
ValueError
|
If a sequence selector contains duplicate indices. |
Source code in src/qten/symbolics/state_space.py
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 | |
same_rays
same_rays(other: StateSpace) -> bool
Check if this state space has the same rays as another, i.e., they have the same set of spatial keys regardless of order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
The other state space to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both state spaces have the same rays, |
Source code in src/qten/symbolics/state_space.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
map
map(func: Callable[[T], T]) -> Self
Map the spatial elements of this state space using a provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T]
|
A function that takes a spatial element and returns a transformed spatial element. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space with the transformed spatial elements. |
Source code in src/qten/symbolics/state_space.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
filter
filter(pred: Callable[[T], bool]) -> Self
Return the subspace containing elements where pred(element) is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[T], bool]
|
Predicate applied to each element in basis order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space of the same concrete type containing only the selected elements, with indices repacked contiguously. |
Source code in src/qten/symbolics/state_space.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
tensor_product
tensor_product(other: Self) -> Self
Return the tensor-product state space of this space and another space.
This method defines the protocol used by the @ operator on
StateSpace instances. The
base class cannot construct a generic product because it does not know
how to combine two elements of type T. Concrete subclasses must
implement the element-level product and rebuild a contiguous
structure for the resulting basis.
Implementations should preserve deterministic product ordering. The
convention used by concrete tensor-product spaces in QTen is the
Cartesian product order of self.elements() and other.elements(),
where elements from self vary slowest and elements from other vary
fastest. The returned space should be the same concrete state-space
family when the operation is closed over that family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
Right-hand tensor factor. Implementations may require |
required |
Returns:
| Type | Description |
|---|---|
StateSpace
|
New state space representing |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised by the base class. Subclasses that support tensor products must override this method. |
Source code in src/qten/symbolics/state_space.py
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 | |
extract
extract(info_type: type[Any]) -> Any
Extract an object implied by the elements of this state space.
Subclasses may register specialized implementations for supported target types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_type
|
type[Any]
|
Type of metadata or object to extract from this state space. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Extracted object produced by a registered specialization. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no extraction rule is registered for |
Source code in src/qten/symbolics/state_space.py
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 | |
StateSpaceFactorization
Bases: NamedTuple
Ruleset for factorizing one StateSpace-like tensor dimension.
Attributes:
| Name | Type | Description |
|---|---|---|
factorized |
Tuple[StateSpace, ...]
|
Target factor spaces in |
align_dim |
StateSpace
|
A permutation of the original dimension whose flattened order is
compatible with reshaping into |
factorized
instance-attribute
factorized: tuple[StateSpace, ...]
align_dim
instance-attribute
align_dim: StateSpace
brillouin_zone
cached
brillouin_zone(lattice: ReciprocalLattice) -> MomentumSpace
Enumerate the discrete Brillouin-zone momenta of a reciprocal lattice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lattice
|
ReciprocalLattice
|
Reciprocal lattice whose Cartesian momentum samples should be collected. |
required |
Returns:
| Type | Description |
|---|---|
MomentumSpace
|
Momentum space whose ordering follows
|
Source code in src/qten/symbolics/state_space.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
embedding_order
cached
embedding_order(
sub: StateSpace, sup: StateSpace
) -> tuple[int, ...]
Return the positions of sub elements inside sup.
The returned tuple has one integer for each element of sub, in
sub.elements() order. Each integer is the stored basis index of that same
element in sup.structure. This is useful when a tensor axis represents a
smaller state space and its data must be scattered into, gathered from, or
aligned against a larger state space.
For example, if sup contains elements (a, b, c) with indices
(0, 1, 2) and sub contains (c, a), then this function returns
(2, 0). The result follows the order of sub, not the order of sup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub
|
StateSpace
|
State space whose elements should be located in |
required |
sup
|
StateSpace
|
State space providing the reference element-to-index mapping. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, ...]
|
Indices in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any element of |
Source code in src/qten/symbolics/state_space.py
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 | |
permutation_order
cached
permutation_order(
src: StateSpace, dest: StateSpace
) -> tuple[int, ...]
Return the permutation of src sectors needed to match dest sector order.
This returns a per-sector permutation: each entry corresponds to a key in
dest.structure and gives the index of the same key in src.structure.
The mapping is directly index-based on the current StateSpace structure
and can be used to reorder sector-aligned data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
StateSpace
|
The source state space defining the original ordering. |
required |
dest
|
StateSpace
|
The destination state space defining the target ordering. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, ...]
|
Sector indices mapping each key in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a destination sector key is missing from the source state space. |
Source code in src/qten/symbolics/state_space.py
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 | |
restructure
restructure(
structure: OrderedDict[T, int],
) -> OrderedDict[T, int]
Return a new OrderedDict with contiguous, ordered integer indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
OrderedDict[Spatial, int]
|
The original structure with possibly non-contiguous indices. |
required |
Returns:
| Type | Description |
|---|---|
OrderedDict[Spatial, int]
|
The restructured |
Source code in src/qten/symbolics/state_space.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
same_rays
same_rays(a: HilbertSpace, b: HilbertSpace) -> bool
Check whether two state spaces span the same ray representatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
StateSpace
|
First state space. |
required |
b
|
StateSpace
|
Second state space. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/qten/symbolics/state_space.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
FuncOpr
dataclass
FuncOpr(
T: type[_IrrepType],
func: Callable[
[_IrrepType], _IrrepType | Multiple[_IrrepType]
],
)
Bases: Generic[_IrrepType], Opr
Symbolic operator induced by applying a Python callable to one irrep type.
FuncOpr lifts a plain callable acting on a single irrep/component into an
Opr that acts on the symbolic Hilbert-space objects defined in this module.
The operator is parameterized by:
T is the concrete runtime type of the irrep/component to target. func
is a callable mapping T -> T | Multiple[T].
Registered actions
FuncOpr defines a specialized registration on:
U1Basis. The handler finds the
unique irrep in psi.base whose exact runtime type is T, applies func
to it, and rebuilds the basis state with that component replaced.
For U1Span and HilbertSpace, FuncOpr relies on the inherited generic
Opr lifting in this module, which maps the operator over contained
U1Basis elements.
Semantics
This class is intended for structure-preserving symbolic rewrites such as
"replace each Offset by Offset.fractional()" or "apply a transformation
to each irrep of a basis state". It is not a general-purpose map over
arbitrary Python objects: dispatch exists only for the symbolic container
types registered below.
The callable func is expected to return either a transformed object of
the same concrete type T, or
Multiple(coef, value) where value has type
T.
Return plain T when the transformation only changes the irrep/component
itself. Return Multiple when the transformation also contributes an
explicit scalar factor, such as a phase or gauge coefficient, that should
be accumulated symbolically rather than absorbed into the object.
FuncOpr does not itself validate the semantic correctness of func, but
the surrounding symbolic code assumes the transformation stays within the
same representation family.
Interaction with @
Because FuncOpr is an Opr, it participates in the overloaded @
syntax:
f @ x applies the operator to an object x. f @ g forms a
ComposedOpr.
With the current ComposedOpr semantics, operator composition follows the
standard algebraic order:
(f @ g) @ x == f(g(x)).
So f @ g means "apply g, then apply f".
Interaction with Multiple
If v is Multiple(coef, base), then f(v) applies f to base.
If the result is a plain object base', the output is
Multiple(coef, base'). If the result is
Multiple(coef', base'), the coefficients are
multiplied and simplified, producing
Multiple(simplify(coef * coef'), base').
This behavior is provided centrally by Opr.invoke, so FuncOpr inherits
the same coefficient-lifting semantics as every other operator subclass.
Interaction with Symbolic Containers
FuncOpr treats U1Basis specially: it targets the unique irrep of type
T via psi.irrep_of(T) rather than iterating over all components with
allows(...). This is why FuncOpr keeps a dedicated U1Basis
registration even though U1Span and HilbertSpace can be handled by the
generic Opr lifting.
Examples:
Use FuncOpr(Offset, Offset.fractional) to normalize every Offset
appearing inside a U1Basis, U1Span, or HilbertSpace.
In particular:
fractional @ psi rewrites one basis state. fractional @ space rewrites
every basis state in a Hilbert space. fractional @ t @ space means
fractional(t(space)).
Attributes:
| Name | Type | Description |
|---|---|---|
T |
Type[_IrrepType]
|
Exact runtime type of the irrep/component targeted by this operator. |
func |
Callable[[_IrrepType], _IrrepType | Multiple[_IrrepType]]
|
Callable applied to the targeted irrep. |
func
instance-attribute
func: Callable[
[_IrrepType], _IrrepType | Multiple[_IrrepType]
]
Callable applied to the targeted irrep. It may return either a transformed
irrep directly or a Multiple carrying an
additional scalar factor.
register
classmethod
register(obj_type: type)
Register a function defining the action of the Functional on a specific object type.
This method returns a decorator. The decorated function should accept
the functional instance as its first argument and an object of
obj_type as its second argument. Any keyword arguments passed to
invoke() are forwarded to the
decorated function.
Dispatch is resolved at call time via MRO, so only the exact
(obj_type, cls) key is stored here. Resolution later searches both:
- the MRO of the runtime object type,
- the MRO of the runtime functional type.
This means registrations on a functional superclass are inherited by subclass functionals unless a more specific registration overrides them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_type
|
type
|
The type of object the function applies to. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that registers the function for the specified object type. |
Examples:
@MyFunctional.register(MyObject)
def _(functional: MyFunctional, obj: MyObject) -> MyObject:
...
Source code in src/qten/abstracts.py
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 | |
get_applicable_types
staticmethod
get_applicable_types() -> tuple[type, ...]
Get all object types that can be applied by this Functional.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[Functional]
|
Functional class whose direct registrations should be inspected. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Type, ...]
|
A tuple of all registered object types that this |
Source code in src/qten/abstracts.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
allows
allows(obj: Any) -> bool
Check if this Functional can be applied on the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to check for applicability. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this |
Notes
Applicability is checked using the same inherited dispatch rules as
invoke(): both the object's MRO
and the functional-class MRO are searched.
Source code in src/qten/abstracts.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
invoke
invoke(v: _T, **kwargs: Any) -> _T | Multiple[_T]
Apply the operator while preserving QTen's symbolic output invariants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
_T
|
Input object to transform. |
required |
**kwargs
|
Any
|
Extra keyword arguments forwarded to the resolved registration. |
{}
|
Returns:
| Type | Description |
|---|---|
_T | Multiple[_T]
|
Transformed object, or a factored result carrying an explicit scalar coefficient. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If a registered implementation returns a value outside the expected
same-type / |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
__call__
__call__(obj: Any, **kwargs) -> Any
Apply this functional to obj.
This is a thin wrapper around invoke().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Runtime object to dispatch on. |
required |
**kwargs
|
Any
|
Additional keyword arguments forwarded to the resolved implementation. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Result produced by the resolved registered method. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no registration exists for the runtime pair after MRO fallback. |
See Also
invoke(obj, **kwargs)
Full dispatch method used by this call wrapper.
Source code in src/qten/abstracts.py
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 | |
HilbertSpace
dataclass
HilbertSpace(structure: OrderedDict[T, int])
Bases: HasRays, StateSpace[U1Basis], Span[U1Basis]
Composite local Hilbert space built from states and state spans.
HilbertSpace is the symbolic basis container used by tensor-network style
operators in this module. It extends StateSpace with U1Basis sectors.
The inherited structure mapping stores each sector together with its
integer index in basis order.
Mathematical convention
A Hilbert space is an ordered finite basis
\(\mathcal{H} = \mathrm{span}\{|e_0\rangle,\ldots,|e_{d-1}\rangle\}\),
where each \(|e_i\rangle\) is a U1Basis.
The code-level structure mapping stores the correspondence
U1Basis -> i. That index \(i\) is the coordinate used by
Tensor axes.
Ray normalization removes U(1) prefactors from the labels:
\(\mathrm{ray}(c\,|\rho\rangle) = |\rho\rangle\). Phase information is not lost when constructing overlap maps: it is stored
in the matrix entries produced by cross_gram.
The class provides helpers for common basis-management workflows:
elements() returns the flattened basis states as Tuple[U1Basis, ...].
lookup(query) retrieves
a unique basis state by exact typed-irrep match.
group(**groups)
partitions basis elements into labeled grouped
HilbertSpace values.
As a Span, HilbertSpace supports overlap/mapping computations through
cross_gram, which builds a Tensor map between two spaces using U1Basis
overlap (U1Span.cross_gram). As a HasRays, rays() keeps basis
structure while replacing each element by its canonical ray representative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
OrderedDict[U1Basis, int]
|
Ordered sector mapping inherited from |
required |
Notes
dim is inherited from StateSpace
and equals the total flattened basis size, i.e. the number of indexed basis
sectors. group()
requires disjoint selectors; overlapping grouped spans raise ValueError.
permutation_order and
embedding_order operate on
current structure keys.
dim
property
dim: int
The total size of the vector space.
structure
instance-attribute
structure: OrderedDict[T, int]
An ordered dictionary mapping each spatial component (e.g., Offset,
Momentum) to its single flattened index.
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
elements
elements() -> tuple[T, ...]
Return the spatial elements as a tuple.
Source code in src/qten/symbolics/state_space.py
83 84 85 86 | |
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
__len__
__len__() -> int
Return the number of spatial elements.
Source code in src/qten/symbolics/state_space.py
88 89 90 | |
__iter__
__iter__() -> Iterator[T]
Iterate over spatial elements.
Source code in src/qten/symbolics/state_space.py
92 93 94 | |
__getitem__
__getitem__(v: int) -> T
__getitem__(v: slice | range) -> Self
__getitem__(v: Sequence[int]) -> Self
Index into the state-space by element position.
Supported forms
space[i] returns a single spatial element by position, including
negative indices. space[start:stop:step] returns a new space with the
selected elements in slice order. space[range(...)] returns a new
space with the range-selected elements. space[[i, j, ...]] returns a
new space with elements in explicit index order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[int, slice, range, Sequence[int]]
|
Index selector. Sequences must contain unique integers; negative
integers are normalized relative to |
required |
Returns:
| Type | Description |
|---|---|
Spatial or StateSpace
|
A spatial element for |
Raises:
| Type | Description |
|---|---|
IndexError
|
If an integer index is out of bounds. |
TypeError
|
If |
ValueError
|
If a sequence selector contains duplicate indices. |
Source code in src/qten/symbolics/state_space.py
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 | |
same_rays
same_rays(other: StateSpace) -> bool
Check if this state space has the same rays as another, i.e., they have the same set of spatial keys regardless of order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StateSpace
|
The other state space to compare against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both state spaces have the same rays, |
Source code in src/qten/symbolics/state_space.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
map
map(func: Callable[[T], T]) -> Self
Map the spatial elements of this state space using a provided function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[T], T]
|
A function that takes a spatial element and returns a transformed spatial element. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space with the transformed spatial elements. |
Source code in src/qten/symbolics/state_space.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
filter
filter(pred: Callable[[T], bool]) -> Self
Return the subspace containing elements where pred(element) is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[T], bool]
|
Predicate applied to each element in basis order. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new state space of the same concrete type containing only the selected elements, with indices repacked contiguously. |
Source code in src/qten/symbolics/state_space.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
extract
extract(info_type: type[Any]) -> Any
Extract an object implied by the elements of this state space.
Subclasses may register specialized implementations for supported target types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info_type
|
type[Any]
|
Type of metadata or object to extract from this state space. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Extracted object produced by a registered specialization. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no extraction rule is registered for |
Source code in src/qten/symbolics/state_space.py
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 | |
__hash__
__hash__() -> int
Return a hash derived from the ordered Hilbert-space basis structure.
HilbertSpace uses the
same structure-based hash as
StateSpace. The hash includes
each U1Basis sector and its
stored integer basis index in insertion order. Consequently, two
Hilbert spaces with the same sectors but different basis order hash
differently.
Returns:
| Type | Description |
|---|---|
int
|
Hash value for the ordered |
Source code in src/qten/symbolics/hilbert_space.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
new
staticmethod
new(itr: Iterable[U1Basis]) -> HilbertSpace
Build a HilbertSpace from an ordered basis iterable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itr
|
Iterable[U1Basis]
|
Basis elements to insert into the space in iteration order. Each
element is assigned its zero-based sector index according to its
position in |
required |
Returns:
| Type | Description |
|---|---|
HilbertSpace
|
A new space whose |
Notes
Later duplicate keys in itr overwrite earlier entries in the backing
OrderedDict, while preserving insertion order for the surviving key.
Source code in src/qten/symbolics/hilbert_space.py
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 | |
__str__
__str__() -> str
Return a compact Hilbert-space summary.
Returns:
| Type | Description |
|---|---|
str
|
Summary containing total dimension and sector count. |
Source code in src/qten/symbolics/hilbert_space.py
712 713 714 715 716 717 718 719 720 721 | |
__repr__
__repr__() -> str
Return a multiline representation of indexed basis sectors.
Returns:
| Type | Description |
|---|---|
str
|
Summary header plus one line per basis sector. Empty spaces are
marked as |
Source code in src/qten/symbolics/hilbert_space.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
lookup
lookup(query: dict[type[Any], Any]) -> U1Basis
Return the unique element that exactly matches all typed-irrep query entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Dict[Type[Any], Any]
|
Mapping from irrep runtime type to expected irrep value.
A candidate element matches only if, for every |
required |
Returns:
| Type | Description |
|---|---|
U1Basis
|
The unique matching element. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no element matches, if multiple elements match, or if |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
group
group(
**groups: Callable[[U1Basis], bool] | Any,
) -> FrozenDict[str, HilbertSpace]
Group basis elements into labeled subspaces.
Supported selectors
A Callable[[U1Basis], bool] selector includes states for which the
predicate returns True. An irrep-object selector includes states whose
irrep of the same exact runtime type equals the selector.
Parameters
Parameters
**groups : Union[Callable[[U1Basis], bool], Any]
Label-to-selector mapping used to build grouped subspaces.
Returns
Returns
FrozenDict[str, HilbertSpace]
Frozen mapping from labels to grouped [`HilbertSpace`][qten.symbolics.hilbert_space.HilbertSpace] values.
Each grouped subspace is sorted in ascending [`U1Basis`][qten.symbolics.hilbert_space.U1Basis] order.
Raises
Raises
ValueError
If two selectors include the same basis state.
Source code in src/qten/symbolics/hilbert_space.py
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 | |
group_by
group_by(*T: type) -> tuple[HilbertSpace, ...]
Form groups by matching irrep types keyed by the irreps.
This function will try to group the basis by the irrep in order specified by the types in T.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*T
|
Type
|
The irrep types to group by. The grouping will be performed in the order of the types specified.
For example |
()
|
Returns:
| Type | Description |
|---|---|
Tuple[HilbertSpace, ...]
|
Grouped subspaces in the order their irrep keys first appear in the current basis order. |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
is_homogeneous
is_homogeneous() -> bool
Check if this HilbertSpace is homogeneous, i.e., all basis states share the same irrep types.
Returns:
| Type | Description |
|---|---|
bool
|
True if all basis states in this |
Source code in src/qten/symbolics/hilbert_space.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
canonical_basis_types
canonical_basis_types() -> tuple[type[Any], ...]
Return the canonical irrep-type order shared by this HilbertSpace basis.
A homogeneous Hilbert space has one consistent irrep-type layout across all
basis states (for example (int, str) for every element). This method
returns that layout in canonical order.
For an empty space, the result is the empty tuple ().
Returns:
| Type | Description |
|---|---|
Tuple[Type[Any], ...]
|
The canonical irrep-type sequence of the basis representation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If this space is not homogeneous, i.e. basis states do not share the same canonical irrep-type order. |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
irrep_of
irrep_of(T: Type[_IrrepType]) -> Tuple[_IrrepType, ...]
Return the irrep of type T for each basis state in this space.
This is the HilbertSpace analogue of U1Basis.irrep_of(T), lifted
across the ordered basis of the space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[_IrrepType]
|
Concrete irrep type to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[_IrrepType, ...]
|
The irrep instance of type |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any basis state does not contain an irrep of type |
Source code in src/qten/symbolics/hilbert_space.py
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
factorize
factorize(
*irrep_types: tuple[type, ...],
coef_on: int | None = None,
) -> StateSpaceFactorization
Factorize a homogeneous Hilbert space into irrep-type tensor factors.
Each argument in irrep_types defines one output factor as a tuple of
irrep types to group together. Across all groups, every irrep type in
this space must appear exactly once. The result describes both the
factor spaces and the basis reindexing needed to move between the
original basis order and the factorized tensor-product structure.
Mathematical convention
For a homogeneous basis whose labels split into groups \(a\) and \(b\),
factorization checks that the basis is a complete Cartesian product:
\(\mathcal{H} \cong \mathcal{H}_a \otimes \mathcal{H}_b\), with
\(|a_i,b_j\rangle \leftrightarrow |a_i\rangle \otimes |b_j\rangle\).
More generally, the requested irrep_types define factors
\(\mathcal{H}_0,\ldots,\mathcal{H}_{m-1}\). The returned align_dim
is the original basis reordered so that its flattened order matches
factorized[0] @ ... @ factorized[m-1] in code.
Notes
The input space must be homogeneous, meaning every
U1Basis element has the same
canonical irrep-type layout. The basis must also be a complete
Cartesian product for the requested groups. For example, if factors are
(int,) and (str,), then every observed integer label must appear
with every observed string label.
coef_on controls which output factor receives the original
U1Basis.coef. All other
factors are built with coefficient 1. This is valid only when the
chosen factor uniquely determines each original coefficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*irrep_types
|
Tuple[Type, ...]
|
Factor specification. Each tuple is one output factor containing the irrep types assigned to that factor. Every irrep type present in this homogeneous space must appear exactly once across all factor specifications. |
()
|
coef_on
|
Optional[int]
|
Index of the factor that inherits the original |
None
|
Returns:
| Type | Description |
|---|---|
StateSpaceFactorization
|
Factorization metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the space is not homogeneous. |
ValueError
|
If the space is empty and non-empty factor groups were requested. |
ValueError
|
If any requested factor group is empty. |
ValueError
|
If an irrep type is missing, duplicated, or not present in the homogeneous basis. |
ValueError
|
If |
ValueError
|
If the chosen |
ValueError
|
If the basis is not a complete Cartesian product for the requested groups. |
Examples:
Suppose a Hilbert-space basis is labeled by two independent pieces of
information: a site index (int) and an orbital label (str). The
four basis states below form a complete product of two sites and two
orbitals:
import sympy as sy
from qten.symbolics import HilbertSpace, U1Basis
space = HilbertSpace.new(
U1Basis(sy.Integer(1), (i, label))
for i in (1, 2)
for label in ("a", "b")
)
factorization = space.factorize((int,), (str,))
The first factor contains the unique site labels. The second factor contains the unique orbital labels:
site_factor, orbital_factor = factorization.factorized
assert tuple(state.base for state in site_factor.elements()) == (
(1,),
(2,),
)
assert tuple(state.base for state in orbital_factor.elements()) == (
("a",),
("b",),
)
align_dim records the original basis order arranged so it can be
reshaped as site_factor @ orbital_factor. In this example the input
was already in product order, so align_dim has the same basis labels:
assert tuple(state.base for state in factorization.align_dim.elements()) == (
(1, "a"),
(1, "b"),
(2, "a"),
(2, "b"),
)
Factorization fails if the space is not homogeneous, if the requested
groups omit or add irrep types, if coef_on is out of range, if
coefficient assignment is ambiguous, or if the basis is not a complete
Cartesian product for the requested groups. For example, a basis with
(1, "a"), (1, "b"), (2, "a"), (2, "b"), and (2, "c") cannot
factorize by (int,) and (str,) because the product would also
require (1, "c").
Source code in src/qten/symbolics/hilbert_space.py
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 | |
tensor_product
tensor_product(other: HilbertSpace) -> HilbertSpace
Build the tensor-product space of this space with another HilbertSpace.
The resulting basis is generated by taking every ordered pair
(a, b) from self.elements() and other.elements(), then forming the
basis-level tensor product a @ b for each pair.
Mathematically, if
\(\mathcal{H}_L = \mathrm{span}\{|a_i\rangle\}\) and
\(\mathcal{H}_R = \mathrm{span}\{|b_j\rangle\}\), then the result is
ordered as \(\mathcal{H}_L \otimes \mathcal{H}_R
= \mathrm{span}\{|a_i\rangle \otimes |b_j\rangle\}_{i,j}\).
Ordering follows itertools.product(self.elements(), other.elements()):
basis elements from self vary slowest, and basis elements from other
vary fastest. This deterministic order is important for tensor reshape
and alignment logic that depends on stable axis conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
HilbertSpace
|
Right-hand tensor factor. |
required |
Returns:
| Type | Description |
|---|---|
HilbertSpace
|
A new space whose basis spans |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
rays
rays() -> HilbertSpace
Return the Hilbert space obtained by ray-normalizing every basis state.
The output keeps the same basis order after converting each
U1Basis element to
element.rays(). This removes U(1) coefficients from the symbolic
basis labels while preserving the projective sector structure.
In formula form: \(\{c_i|\rho_i\rangle\}_i \longmapsto \{|\rho_i\rangle\}_i\).
Returns:
| Type | Description |
|---|---|
HilbertSpace
|
Hilbert space built from the ray representatives of this space's basis elements. |
Examples:
import sympy as sy
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import HilbertSpace, U1Basis
affine = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), affine)
hilbert = HilbertSpace.new((U1Basis(sy.Integer(5), (r0,)),))
ray_space = hilbert.rays()
assert ray_space.elements()[0].coef == 1
Source code in src/qten/symbolics/hilbert_space.py
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 | |
cross_gram
cross_gram(
another: HilbertSpace, *, device: Device | None = None
) -> Tensor
Build the cross-Gram overlap matrix between this basis and another basis.
Matrix entries are computed from concrete basis overlaps
\(G_{ij} = \langle \mathrm{self}_i \mid \mathrm{another}_j \rangle\),
so any nontrivial U(1) irrep phase in basis vectors is encoded in
data.
Output dimension convention
The returned tensor uses dims (self, another.rays()).
The target (column) dimension is intentionally replaced by its canonical
ray representative (phase removed)
so the codomain metadata is gauge-fixed, while phase information remains
in matrix elements.
This is equivalent to using a representative of the same ray space (projective Hilbert space) for the target basis labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
another
|
HilbertSpace
|
Right-hand basis supplying ket states. |
required |
device
|
Optional[Device]
|
Device on which to allocate the returned tensor data. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Matrix tensor with dims |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
Opr
dataclass
Opr()
Bases: Functional, Operable, ABC
A composable operator that acts on observable-compatible objects.
Operator combines two core behaviors:
The first behavior is Functional dispatch
and chaining. Implementations are registered via Functional.register for
pairs of (input_type, operator_subclass). At runtime, invoke resolves
the function chain for the concrete input object and executes each function
in order.
The second behavior is Operable
matrix-application syntax. Because Operator is
Operable, it participates in the overloaded
@ operator. This module defines Operable.__matmul__(Operator, U1Basis),
so op @ value applies the operator and returns only the transformed value
component.
Conceptually, an operator application returns either a transformed object
of the same runtime type as the input, or
Multiple(coef, transformed_object) when the
action also contributes a scalar prefactor.
The Multiple form is used when the operator naturally decomposes into a
scalar factor times an object in the same representation family. Typical
examples include phase factors, characters, gauge coefficients, and other
symbolic amplitudes that should stay factored instead of being folded
directly into the transformed object.
Implementation Guidelines
A registered handler should return a plain transformed object when the
operator acts without producing an extra scalar factor. It should return
Multiple(coef, value) when the action produces
a scalar prefactor that should remain explicit. In both cases, the
underlying transformed value must stay in the same representation family as
the input: plain returns should have type(result) is type(input) or a
compatible subclass, while multiple returns should have
type(result.base) is type(input) or a compatible subclass.
Opr.invoke automatically lifts operators over
Multiple. If op(base) -> y, then
op(Multiple(c, base)) -> Multiple(c, y). If
op(base) -> Multiple(c2, y), the coefficients are multiplied to produce
Multiple(simplify(c * c2), y).
For symbolic container inputs such as
U1Basis,
U1Span, and
HilbertSpace, the generic
Opr lifting in this module expects the
final result to stay in-kind and not return
Multiple at the top level. Scalar factors
should instead be attached to the contained irreps/components and
accumulated into the container's internal coefficient structure.
This module provides generic Opr
registrations for U1Basis,
U1Span, and
HilbertSpace. Subclasses
inherit those handlers through Functional
MRO fallback unless they define more specific registrations. If no
registration exists for (type(input), type(operator)) after MRO fallback
on both the input type and the operator type, Functional.invoke raises
NotImplementedError.
Usage Pattern
Define an Operator subclass, register behavior with
@YourOperatorSubclass.register(InputType), and apply it either as
out = op(input_obj) to receive the transformed value or as
out = op @ input_obj using infix syntax.
Return-value Guidance
Return value when the operator only changes the representation/object
itself. Return Multiple(coef, value) when the
operator contributes a symbolic scalar prefactor that should remain
factored.
In particular, for atomic irreps or basis-function-like objects, returning
Multiple is often appropriate. For higher-level symbolic containers such
as U1Basis, U1Span, and HilbertSpace, prefer returning the same
container type directly and let the generic lifting logic accumulate scalar
factors internally.
register
classmethod
register(obj_type: type)
Register a function defining the action of the Functional on a specific object type.
This method returns a decorator. The decorated function should accept
the functional instance as its first argument and an object of
obj_type as its second argument. Any keyword arguments passed to
invoke() are forwarded to the
decorated function.
Dispatch is resolved at call time via MRO, so only the exact
(obj_type, cls) key is stored here. Resolution later searches both:
- the MRO of the runtime object type,
- the MRO of the runtime functional type.
This means registrations on a functional superclass are inherited by subclass functionals unless a more specific registration overrides them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_type
|
type
|
The type of object the function applies to. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A decorator that registers the function for the specified object type. |
Examples:
@MyFunctional.register(MyObject)
def _(functional: MyFunctional, obj: MyObject) -> MyObject:
...
Source code in src/qten/abstracts.py
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 | |
get_applicable_types
staticmethod
get_applicable_types() -> tuple[type, ...]
Get all object types that can be applied by this Functional.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[Functional]
|
Functional class whose direct registrations should be inspected. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Type, ...]
|
A tuple of all registered object types that this |
Source code in src/qten/abstracts.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
allows
allows(obj: Any) -> bool
Check if this Functional can be applied on the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to check for applicability. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this |
Notes
Applicability is checked using the same inherited dispatch rules as
invoke(): both the object's MRO
and the functional-class MRO are searched.
Source code in src/qten/abstracts.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
__call__
__call__(obj: Any, **kwargs) -> Any
Apply this functional to obj.
This is a thin wrapper around invoke().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Runtime object to dispatch on. |
required |
**kwargs
|
Any
|
Additional keyword arguments forwarded to the resolved implementation. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Result produced by the resolved registered method. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no registration exists for the runtime pair after MRO fallback. |
See Also
invoke(obj, **kwargs)
Full dispatch method used by this call wrapper.
Source code in src/qten/abstracts.py
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 | |
invoke
invoke(v: _T, **kwargs: Any) -> _T | Multiple[_T]
Apply the operator while preserving QTen's symbolic output invariants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
_T
|
Input object to transform. |
required |
**kwargs
|
Any
|
Extra keyword arguments forwarded to the resolved registration. |
{}
|
Returns:
| Type | Description |
|---|---|
_T | Multiple[_T]
|
Transformed object, or a factored result carrying an explicit scalar coefficient. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If a registered implementation returns a value outside the expected
same-type / |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
U1Basis
dataclass
U1Basis(coef: Number, base: BaseType)
Bases: Spatial, Multiple[Tuple[Any, ...]], AbstractKet[Expr], HasRays, Convertible
Immutable single-particle basis state built from typed irreps.
U1Basis is a symbolic tensor-product state with U(1) irreducible representation
presented as an ordered tuple of irreps. This object is
intentionally symbolic: it stores basis labels only and does not store amplitudes
or coefficients.
A key invariant is enforced at construction time: for each concrete irrep
type, the state must contain exactly one ket of that type. In other words,
irrep multiplicities must be unity. This guarantees that type-based updates
via replace are unambiguous and fast.
Mathematical convention
A basis state is represented symbolically as
\(|\psi\rangle = c\,|\rho_1,\rho_2,\ldots,\rho_m\rangle\), where coef
stores \(c\), base stores the construction-order tuple
\((\rho_1,\rho_2,\ldots,\rho_m)\), and rep stores the canonical
type-sorted tuple used for equality, hashing, and lookup. The object is a
basis label with a U(1) prefactor, not a dense state vector.
Attributes:
| Name | Type | Description |
|---|---|---|
coef |
Expr
|
Symbolic U(1) coefficient carried by this basis state. |
base |
Tuple[Any, ...]
|
Immutable tuple of irrep labels before canonical sorting. |
rep |
Tuple[Any, ...]
|
Immutable canonical irrep order sorted by concrete irrep type name
( |
Notes
dim is always 1; this type represents one basis vector. Irrep order is
canonicalized at construction, so permutations of the same typed irreps
produce the same internal rep tuple.
replace(irrep) substitutes
the unique irrep with the same concrete runtime type as irrep.
The @ dispatch overload combines two basis states as a symbolic tensor
product. For a @ b, the output coefficient is
simplify(a.coef * b.coef) and the output base tuple is
a.base + b.base in tensor-product construction order. __post_init__
then computes rep by sorting that base tuple by fully-qualified runtime
type name (module.qualname). The original base order is retained for
display and construction semantics, while rep is the canonical sorted
representation used for type-order-sensitive behavior. If either operand
has an empty base, that operand acts as the tensor-product identity and
the other operand is returned unchanged. The resulting
U1Basis is still validated by
__post_init__, so combining states that contain the same concrete irrep
type is rejected by the unity-multiplicity invariant.
In coefficient notation, tensor-product composition multiplies the U(1)
weights as \(c_{a \otimes b} = c_a c_b\). Equivalently,
\((c_a|\alpha\rangle) \otimes (c_b|\beta\rangle)
= c_a c_b\,|\alpha,\beta\rangle\). In code, this is a @ b and is implemented as
U1Basis(simplify(a.coef * b.coef), a.base + b.base).
The | dispatch overloads build a
U1Span of distinct
U1Basis values. Ordering (<,
>) compares the number of irreps, then the tuple of fully-qualified irrep
type names (module.qualname) from self.rep, then the canonical
irrep-value tuple itself. If irrep values of matching types are not
orderable, the comparison raises from the underlying irrep objects.
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised in |
coef
instance-attribute
coef: Number
Numeric SymPy coefficient applied to base, kept separate so callers can
accumulate scalar factors without eagerly rebuilding symbolic expressions.
base
instance-attribute
base: BaseType
The symbolic or scalar object being multiplied by coef, preserved in
structured form for later operator application or simplification.
dim
property
dim: int
The dimension of a single particle state is always 1.
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
__post_init__
__post_init__() -> None
Source code in src/qten/symbolics/hilbert_space.py
162 163 164 165 166 167 168 169 170 171 172 | |
new
staticmethod
new(*rep: Any) -> U1Basis
Build a U1Basis with the given reps and a default U(1) value of 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rep
|
Any
|
Irreps to build the state from. Input order is canonicalized in
|
()
|
Returns:
| Type | Description |
|---|---|
U1Basis
|
A |
Source code in src/qten/symbolics/hilbert_space.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
replace
replace(irrep: Any) -> U1Basis
Return a new state where the irrep of the same concrete type is replaced.
The method searches this state's irrep tuple for the unique irrep whose type has
the same exact runtime type as irrep (using type(x) is type(y)), then
returns a new U1Basis with that irrep substituted. The original instance is
not modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
irrep
|
Any
|
Replacement irrep instance. Its concrete type must already exist in this
state exactly once (enforced by |
required |
Returns:
| Type | Description |
|---|---|
U1Basis
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If this state does not contain any irrep with the same concrete
type as |
Examples:
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import U1Basis
space = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), space)
r1 = Offset(ImmutableDenseMatrix([1]), space)
psi = U1Basis.new(r0, "spin-up")
out = psi.replace(r1)
assert out.irrep_of(Offset) == r1
assert out.irrep_of(str) == "spin-up"
Source code in src/qten/symbolics/hilbert_space.py
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 | |
without
without(*T: type[Any]) -> U1Basis
Return a new state with irreps of the requested concrete types removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*T
|
Type[Any]
|
Concrete irrep types to remove. Matching uses exact runtime type
identity ( |
()
|
Returns:
| Type | Description |
|---|---|
U1Basis
|
A new |
Examples:
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import U1Basis
space = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), space)
psi = U1Basis.new(r0, "spin-up")
local_label = psi.without(Offset)
assert local_label.irrep_of(str) == "spin-up"
Source code in src/qten/symbolics/hilbert_space.py
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 | |
irrep_of
irrep_of(T: type[_IrrepType]) -> _IrrepType
Return the unique irrep in this state whose concrete type is T.
This method performs a direct scan over self.rep and returns the
first irrep satisfying type(irrep) is T. Because
U1Basis.__post_init__ enforces unity multiplicity for each irrep
type, the match is unique whenever it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[_IrrepType]
|
Concrete irrep type to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
_IrrepType
|
The irrep instance of type |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no irrep with concrete type |
Examples:
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import U1Basis
space = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), space)
psi = U1Basis.new(r0, "spin-up")
assert psi.irrep_of(Offset) == r0
assert psi.irrep_of(str) == "spin-up"
Notes
Matching uses exact runtime type identity (type(x) is T), not subclass
checks. Runtime is linear in the number of irreps (O(n)), with no
temporary mapping allocations.
Source code in src/qten/symbolics/hilbert_space.py
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 | |
ket
ket(psi: U1Basis) -> sy.Expr
Return the overlap of this state with another state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psi
|
U1Basis
|
The state to compute the overlap with. |
required |
Returns:
| Type | Description |
|---|---|
Expr
|
The symbolic overlap of this state with |
Source code in src/qten/symbolics/hilbert_space.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
__str__
__str__() -> str
Return a compact ket-style label for this basis state.
Returns:
| Type | Description |
|---|---|
str
|
Tensor-product ket label. If |
Source code in src/qten/symbolics/hilbert_space.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
__repr__
__repr__() -> str
Return the developer representation of this basis state.
Returns:
| Type | Description |
|---|---|
str
|
Same value as |
Source code in src/qten/symbolics/hilbert_space.py
381 382 383 384 385 386 387 388 389 390 | |
rays
rays() -> U1Basis
Return the canonical ray representative with U(1) coefficient 1.
A U1Basis ray ignores the
scalar coef and keeps only the basis labels. This method returns a new
basis state with the same base tuple and coefficient 1. The original
object is unchanged.
Returns:
| Type | Description |
|---|---|
U1Basis
|
Basis state with the same irrep labels and |
Examples:
import sympy as sy
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import U1Basis
space = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), space)
psi = U1Basis(sy.Integer(3), (r0,))
ray = psi.rays()
assert ray.coef == 1
assert ray.base == psi.base
Source code in src/qten/symbolics/hilbert_space.py
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 | |
repr_types
repr_types() -> tuple[type, ...]
Get a tuple of concrete irrep types in this U1Basis in canonical order.
This is the same order as self.rep, which is determined by
sorting on full_typename(type(irrep)).
Returns:
| Type | Description |
|---|---|
Tuple[Type, ...]
|
Tuple of concrete irrep types in deterministic type-name order. |
Source code in src/qten/symbolics/hilbert_space.py
426 427 428 429 430 431 432 433 434 435 436 437 438 | |
U1Span
dataclass
U1Span(span: tuple[U1Basis, ...])
Bases: Span[U1Basis], Spatial, HasRays, Convertible
Finite span of distinct single-particle basis states.
U1Span is the additive container used by U1Basis's * operator. It
stores an ordered tuple of basis states and represents the symbolic span
generated by those states. The object is immutable (frozen=True) and
preserves insertion order.
This type is intentionally lightweight: it does not store amplitudes,
coefficients, or perform linear-algebra simplification. Duplicate handling
is implemented in __or__ overloads, which keep only one copy of an
existing state when building a span.
Mathematical convention
If the span contains basis labels \(\psi_0,\ldots,\psi_{n-1}\), it represents the ordered symbolic basis \(\mathrm{span}\{|\psi_0\rangle,\ldots,|\psi_{n-1}\rangle\}\). The order is part of the object: it determines row/column ordering in Gram matrices and tensor dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
span
|
Tuple[U1Basis, ...]
|
Ordered tuple of |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
span |
Tuple[U1Basis, ...]
|
The underlying immutable sequence of basis states. |
Notes
The dim property returns len(span), i.e., the number of basis states
currently tracked by this symbolic span.
span
instance-attribute
span: tuple[U1Basis, ...]
Ordered tuple of U1Basis elements contained in this span.
dim
property
dim: int
Get the length of this single particle state span.
add_conversion
classmethod
add_conversion(
T: type[B],
) -> Callable[[Callable[[A], B]], Callable[[A], B]]
Register a conversion from cls to T.
The decorated function is stored under (cls, T). When an instance of
cls later calls convert(T),
that function is used to produce the converted object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type produced by the registered conversion function. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[[A], B]], Callable[[A], B]]
|
Decorator that stores the conversion function and returns it unchanged. |
Examples:
@MyType.add_conversion(TargetType)
def to_target(x: MyType) -> TargetType:
...
Source code in src/qten/abstracts.py
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 | |
convert
convert(T: type[B]) -> B
Convert this instance to the requested target type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
Type[B]
|
Destination type to convert into. |
required |
Returns:
| Type | Description |
|---|---|
B
|
Converted object produced by the registered conversion function. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If no conversion function has been registered for
|
Source code in src/qten/abstracts.py
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 | |
register_plot_method
classmethod
register_plot_method(name: str, backend: str = 'plotly')
Register a backend plotting function for this plottable class.
The returned decorator stores the function in the global plotting
registry. Registered functions receive the object being plotted as their
first argument, followed by any extra positional and keyword arguments
supplied to plot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User-facing plot method name, such as |
required |
backend
|
str
|
Backend name that selects the implementation. The |
'plotly'
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the provided plotting function and returns it unchanged. |
Source code in src/qten/plottings/_plottings.py
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 | |
plot
plot(method: str, backend: str = 'plotly', *args, **kwargs)
Dispatch a named plot method to a registered backend implementation.
The dispatcher first loads plotting entry points, then searches the
instance type and its base classes for a matching (type, method,
backend) registration. Additional arguments are forwarded unchanged to
the selected backend function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Plot method name registered for this object's type. |
required |
backend
|
str
|
Backend implementation to use. The |
'plotly'
|
args
|
Positional arguments forwarded to the registered plotting function. |
()
|
|
kwargs
|
Keyword arguments forwarded to the registered plotting function. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
Backend-specific figure object returned by the registered plotting function, such as a Plotly or Matplotlib figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plotting function is registered for the requested method and backend on this object. |
See Also
qten_plots.plottables.PointCloud Public plottable helper object provided by the plotting extension.
Source code in src/qten/plottings/_plottings.py
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 | |
__iter__
__iter__() -> Iterator[U1Basis]
Iterate over states in this span preserving insertion order.
Source code in src/qten/symbolics/hilbert_space.py
521 522 523 | |
elements
elements() -> tuple[U1Basis, ...]
Return the basis states contained in this span.
Returns:
| Type | Description |
|---|---|
Tuple[U1Basis, ...]
|
Ordered immutable tuple of basis states. |
Source code in src/qten/symbolics/hilbert_space.py
525 526 527 528 529 530 531 532 533 534 535 | |
rays
rays() -> U1Span
Return the span obtained by ray-normalizing each basis state.
The output preserves span order and replaces every
U1Basis by
basis.rays(), which sets that basis state's coefficient to 1.
Returns:
| Type | Description |
|---|---|
U1Span
|
Span with the same number of basis states, each replaced by its ray representative. |
Examples:
import sympy as sy
from sympy import ImmutableDenseMatrix
from qten.geometries import AffineSpace, Offset
from qten.symbolics import U1Basis, U1Span
space = AffineSpace(ImmutableDenseMatrix.eye(1))
r0 = Offset(ImmutableDenseMatrix([0]), space)
span = U1Span((U1Basis(sy.Integer(2), (r0,)),))
ray_span = span.rays()
assert ray_span.elements()[0].coef == 1
Source code in src/qten/symbolics/hilbert_space.py
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 | |
cross_gram
cross_gram(ket: U1Span) -> sy.ImmutableDenseMatrix
Compute the overlap matrix between this span and another span.
For left span states \(\psi_i\) and right span states \(\phi_j\), the returned SymPy matrix has entries \(G_{ij} = \langle \psi_i \mid \phi_j \rangle\). The implementation only emits a nonzero entry when the two symbolic states have the same ray; the stored U(1) coefficients supply the overlap phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ket
|
U1Span
|
Right-hand span supplying the ket states. |
required |
Returns:
| Type | Description |
|---|---|
ImmutableDenseMatrix
|
Matrix whose |
Source code in src/qten/symbolics/hilbert_space.py
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |