YASTN configuration#
All YASTN tensors have to be provided with configuration, which defines:
linear algebra backend,
how to handle fusion (reshaping) of tensors,
#. default data type (
float64
,complex128
) and device (provided it is supported by backend) of tensors.
The configuration can be provided as a Python module, types.SimpleNamespace, typing.NamedTuple or similar which defines following members
required:
backend
,sym
,optional:
default_device
,default_dtype
,default_fusion
,fermionic
,force_fusion
.
The configuration can be conveninently generated using
- yastn.make_config(**kwargs) NamedTuple [source]#
Create structure with YASTN configuration
- Parameters:
backend (backend module or str) – Specify
backend
providing linear algebra and base dense tensors. Currently supported backends areNumPy as
yastn.backend.backend_np
PyTorch as
yastn.backend.backend_torch
Understands string inputs “np”, “torch”. Defaults to NumPy backend.
sym (symmetry module or compatible object or str) – Specify abelian symmetry. To see how YASTN defines symmetries, see
yastn.sym.sym_abelian
. Defaults toyastn.sym.sym_none
, effectively a dense tensor. For predefined symmetries, takes string input from ‘dense’, ‘Z2’, ‘Z3’, ‘U1’, ‘U1xU1’, ‘U1xU1xZ2’.default_device (str) –
Tensors can be stored on various devices as supported by
backend
NumPy supports only
'cpu'
devicePyTorch supports multiple devices, see https://pytorch.org/docs/stable/tensor_attributes.html#torch.torch.device
If not specified, the default device is
'cpu'
.default_dtype (str) – Default data type (dtype) of YASTN tensors. Supported options are:
'float64'
,'complex128'
. If not specified, the default dtype is'float64'
.fermionic (bool or tuple[bool,…]) – Specify behavior of
yastn.swap_gate()
function, allowing to introduce fermionic symmetries. Allowed values:False
,True
, or a tuple(True, False, ...)
with one bool for each component charge vector, i.e., of length sym.NSYM. Default isFalse
.default_fusion (str) – Specify default strategy to handle leg fusion:
'hard'
or'meta'
. Seeyastn.Tensor.fuse_legs()
for details. Default is'hard'
.force_fusion (str) – Overrides fusion strategy provided in
yastn.Tensor.fuse_legs()
. Default isNone
.
Below is an example of configuration defined as a plain Python module, using NumPy backend and \(U(1)\) symmetry.
import yastn.backend.backend_np as backend
from yastn.sym import sym_U1 as sym
default_device: str = 'cpu'
default_dtype: str = 'float64'
fermionic = False
default_fusion: str = 'hard'
force_fusion: str = None