Initialization and creation operations ====================================== Building MPS/MPO manually ------------------------- The tensor making up MPS/MPO can be assigned manually, setting them one by one. Note that the virtual dimensions/spaces of the neighboring MPS/MPO tensors should be consistent. Ground state of spin-1 AKLT model ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Here, as an example, we set up a well-known exact MPS: A ground state of `Affleck-Kennedy-Lieb-Tasaki (AKLT) model `_. :: import numpy as np import yastn import yastn.tn.mps as mps .. literalinclude:: /../../tests/mps/test_measurement.py :pyobject: build_aklt_state_manually Hamiltonian for nearest-neighbor hopping/XX model ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The same can be done for MPOs. Here, we show a construction of a simple nearest-neighbour hopping Hamiltonian with hopping amplitude :math:`t` and on-site energy :math:`\mu` with different realizations of explicit symmetry. .. literalinclude:: /../../tests/mps/test_build_mpo_manually.py :pyobject: build_mpo_nn_hopping_manually Building MPO using Hterm ------------------------ Hamiltonian is typically given as a sum of products of local operators. We can specify a single such product using :code:`mps.tn.mps.Hterm`. Hamiltonian is generated by a function :code:`yastn.tn.mps.generate_mpo` which takes an identity MPO and a `Sequence[Hterm]`. Spinless fermions with long-range hopping (Hterm) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: /../../tests/mps/test_generate_mpo.py :pyobject: build_mpo_hopping_Hterm Generator class for MPO/MPS --------------------------- The MPO can be constructed automatically using dedicated :class:`yastn.tn.mps.Generator` supplied with the set of local operators. Automatic generator creates MPO with symmetries inherited from local operators. `Generator` can be also used to create random MPS and MPO, where local Hilbert spaces are read from identity operators defined in the Generator. Building random MPS/MPO ^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: /../../tests/mps/test_initialization.py :pyobject: random_mps_spinless_fermions Hamiltonian for nearest-neighbor hopping/XX model (Generator) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: /../../tests/mps/test_generator_class.py :pyobject: mpo_nn_hopping_latex Save and load MPS/MPO --------------------- MPS/MPO can be saved/loaded either to/from a dictionary or an HDF5 file. :ref:`YASTN configuration` with matching symmetry has to be provided for on-site MPS/MPO tensors when loading either from a dictionary or HDF5 file. Using Python's dictionary ^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: /../../tests/mps/test_save_load.py :pyobject: save_load_mps_dict Using HDF5 format ^^^^^^^^^^^^^^^^^ :: import os import h5py .. literalinclude:: /../../tests/mps/test_save_load.py :pyobject: save_load_mps_hdf5