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.
import symbolica
from symbolica.community.spenso import TensorLibrary, LibraryTensor, TensorStructure, Representation
lib = TensorLibrary()
rep = Representation.euc(3)
name = symbolica.S("my_tensor")
structure = TensorStructure(rep, rep, name=name)
tensor = LibraryTensor.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 | LibraryTensor) -> 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
import symbolica
from symbolica.community.spenso import TensorLibrary, LibraryTensor, TensorStructure, Representation
lib = TensorLibrary()
rep = Representation.euc(3)
name = symbolica.S("my_tensor")
structure = TensorStructure(rep, rep, name=name)
tensor = LibraryTensor.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 | LibraryTensor | — | The tensor to register - can be a LibraryTensor or regular Tensor |
__getitem__
Method__getitem__(key: Expression | int | str | float | complex | str) -> TensorStructureRetrieve 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
A TensorStructure representing the registered tensor template
Raises
RuntimeErrorIf the tensor name is not found in the library
Examples
structure = lib["T"]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | Expression | int | str | float | complex | str | — | The tensor name - can be a string or symbolic expression |
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:1134