Source code for yastn._from_dict
# Copyright 2025 The YASTN Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
""" yastn.from_dict() handling imports off all major classes """
from .tensor import Tensor
from .tn.fpeps import Lattice, Peps, Peps2Layers, DoublePepsTensor
from .tn.fpeps import EnvBoundaryMPS, EnvBP, EnvCTM, EnvCTM_c4v
from .tn.mps import MpsMpoOBC, MpoPBC
types = {"Tensor": Tensor,
"MpsMpoOBC": MpsMpoOBC,
"MpoPBC": MpoPBC,
"Lattice": Lattice,
"Peps": Peps,
"Peps2Layers": Peps2Layers,
"DoublePepsTensor": DoublePepsTensor,
"EnvBoundaryMPS": EnvBoundaryMPS,
"EnvBP": EnvBP,
"EnvCTM": EnvCTM,
"EnvCTM_c4v": EnvCTM_c4v
}
[docs]
def from_dict(d, config=None):
r"""
De-serializes an object from the dictionary ``d``.
Object type is read from ``d``.
Parameters
----------
d : dict
Object stored in form of a dictionary created with ``to_dict`` method.
config : Optional[module | _config(NamedTuple)]
:ref:`YASTN configuration <tensor/configuration:yastn configuration>`
If provided, overrides configuration stored in `d`.
"""
return types[d['type']].from_dict(d, config)