YASTN configuration#
All YASTN tensors have to be provided with configuration, which defines:
linear algebra backend
default data type (
float64
,complex128
) and device (provided it is supported by backend) of a tensorfermionic statistics (controlling action of
yastn.swap_gate()
)
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
,fermionic
,default_fusion
,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
The above backends can be specified as strings: “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 ‘none’ (or ‘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 statistics. Allowed values:False
,True
, or a tuple(True, False, ...)
with one bool for each component charge vector, i.e., of length sym.NSYM. The default isFalse
.default_fusion (str) – Specify default strategy to handle leg fusion:
'hard'
or'meta'
. Seeyastn.Tensor.fuse_legs()
for details. The default is'hard'
.force_fusion (str) – Overrides fusion strategy provided in
yastn.Tensor.fuse_legs()
. The default isNone
.tensordot_policy (str) –
Contraction approach used by
yastn.tensordot()
'fuse_to_matrix'
Tensordot involves suitable permutation of each tensor while performing a fusion of each tensor into a sequence of matrices and calling matrix-matrix multiplication. Postprocessing includes unfusioning the remaining legs in the result, which often copy data adding extra overhead.'fuse_contracted'
Tensordot involves suitable permutation of each tensor while performing a fusion of to-be-contracted legs of each tensor and calling multiplication. It involves a larger number of multiplication calls for smaller objects, but unfusing the legs of the result is not needed.'no_fusion'
Tensordot involves suitable permutation of tensor blocks and calling matrix-matrix multiplication for a potentially large number of small objects. Resulting contributions to new blocks get added. However, overheads of initial fusion (copying data) can sometimes be avoided in this approach.
Example
config = yastn.make_config(backend='np', sym='U1')
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