TensorLibrary
symbolica.community.spenso Class
TensorLibrary()A library for registering and managing tensor templates and structures.
The TensorLibrary provides a centralized registry for tensor definitions that can be reused across tensor networks and expressions. It manages tensor structures with their associated names and can resolve symbolic references to registered tensors.
from symbolica.community.spenso import Tensor, TensorLibrary, TensorName, Representation
lib = TensorLibrary()
rep = Representation.euc(3)
name = TensorName("my_tensor")
structure = name(rep, rep)
tensor = Tensor.dense(structure, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0])
lib.register(tensor)
tensor_ref = lib[name]Constructor
#Create a new empty tensor library.
Initializes an empty library ready for registering tensor structures. The library automatically manages internal tensor IDs.
Returns
TensorLibrary
A new empty tensor library
Examples
from symbolica.community.spenso import TensorLibrary
lib = TensorLibrary()Member details
construct
Static methodconstruct() -> TensorLibraryCreate a new empty tensor library (static method).
Initializes an empty library ready for registering tensor structures. The library automatically manages internal tensor IDs.
Returns
TensorLibrary
A new empty tensor library
Examples
from symbolica.community.spenso import TensorLibrary
lib = TensorLibrary.construct()register
Methodregister(tensor: Tensor) -> NoneRegister a tensor in the library.
Adds a tensor template to the library that can be referenced by name in tensor networks and symbolic expressions. The tensor must have a name set in its structure.
Examples
from symbolica.community.spenso import Tensor, TensorLibrary, TensorName, Representation
lib = TensorLibrary()
rep = Representation.euc(3)
name = TensorName("my_tensor")
structure = name(rep, rep)
tensor = Tensor.dense(structure, [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0])
lib.register(tensor)
tensor_ref = lib[name]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
tensor | Tensor | — | A named tensor with a fully unresolved interface, or a named scalar |
__getitem__
Method__getitem__(key: TensorExpression | TensorName | Expression | str) -> TensorExpressionRetrieve a registered tensor structure by name.
Looks up a previously registered tensor by its name and returns a reference structure that can be used to create new tensor instances.
Returns
An atomic reference with the requested exact interface, or the registered logical interface for a symbol-only lookup
Raises
RuntimeErrorIf the tensor name is not found in the library
Examples
exact = lib[TensorName("T")(1, Representation.euc(3))]
unique_by_name = lib["T"]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | TensorExpression | TensorName | Expression | str | — | An exact unresolved tensor signature in registered storage order, or a symbol-only convenience key |
hep_lib
Static methodhep_lib() -> TensorLibraryCreate a library pre-loaded with High Energy Physics tensor definitions.
Returns a library containing standard HEP tensors such as gamma matrices, color generators, metric tensors, and other commonly used structures in particle physics calculations. They are floating point tensors with f64 precision.
Returns
TensorLibrary
A TensorLibrary pre-populated with HEP tensor definitions
Examples
import symbolica
from symbolica.community.spenso import TensorLibrary, TensorName
hep_lib = TensorLibrary.hep_lib()
gamma_structure = hep_lib[symbolica.S("spenso::gamma")]hep_lib_atom
Static methodhep_lib_atom() -> TensorLibraryCreate a library pre-loaded with High Energy Physics tensor definitions.
Returns a library containing standard HEP tensors such as gamma matrices, color generators, metric tensors, and other commonly used structures in particle physics calculations. They are tensors with atom numeric entries.
Returns
TensorLibrary
A TensorLibrary pre-populated with HEP tensor definitions
Examples
import symbolica
from symbolica.community.spenso import TensorLibrary, TensorName
hep_lib = TensorLibrary.hep_lib_atom()
gamma_structure = hep_lib[symbolica.S("spenso::gamma")]View generated signature source: docs/api/python/spynso3.pyi:1378