Page 1 of 1

Newcomer of tenpy having an issue with my code

Posted: 17 Jul 2022, 07:44
by yhang
I have written a code in tenpy to simulate the 1D heisenberg chain, but it looks like finally my code does not create any "dynamic properties" at all(Both my energy and my entanglement entropy does not change at all). Can anyone help me with that? Thank you guys so much!Attached are my codes and my plots.

My codes:

Code: Select all

import numpy as np
import tenpy
import time
from tenpy.networks.mps import MPS
from tenpy.models.xxz_chain import XXZChain
from tenpy.algorithms import dmrg
import matplotlib.pyplot as plt

def example_DMRG_heisenberg_infinite_S_xi_scaling(Jz):
    model_params = dict(L=20, Jxx=1., Jz=Jz, hz=0, bc_MPS='infinite', conserve='best')
    M = XXZChain(model_params)
    product_state = ["up"] *
    psi = MPS.from_product_state(, product_state,
    dmrg_params = {
        'start_env': 10,
        'mixer': False,
        #  'mixer_params': {'amplitude': 1.e-3, 'decay': 5., 'disable_after': 50},
        'trunc_params': {
            'chi_max': 30,
            #Dimension of the system
            'svd_min': 1.e-10
        'max_E_err': 1.e-9,
        'max_S_err': 1.e-6,
        'update_env': 0,

    chi_list = np.arange(7, 31, 2)
    s_list = []
    xi_list = []
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)

    for chi in chi_list:

        t0 = time.time()
        )  # necessary if you for example have a fixed numer of sweeps, if you don't set this you option your simulation stops after initial number of sweeps!
        eng.trunc_params['chi_max'] = chi
        ##   DMRG Calculation    ##
        print("Start IDMRG CALCULATION")
        eng.options['mixer'] = None

        ##   Calculating bond entropy and correlation length  ##
        if a==len(chi_list):
        # the bond 0 is between MPS unit cells and hence sensible even for 2D lattices.

              time.time() - t0,
              flush=True)  # quite some speedup for small chi


    return s_list, xi_list, E_list

if __name__ == "__main__":
    import logging
    s_list, xi_list,E_list = example_DMRG_heisenberg_infinite_S_xi_scaling(Jz=1)
    length=[i for i in range(0,len(E_list))]

Re: Newcomer of tenpy having an issue with my code

Posted: 18 Jul 2022, 14:42
by Johannes
It's correct behaviour that the state doesn't change: You start from the fully polarized all-up state, which is an eigenstate of the Hamiltonian! Try to start from another initial state, e.g. the Neel state:

Code: Select all

product_state = ["up", "down"]
psi = MPS.from_product_state(, product_state,