Newcomer of tenpy having an issue with my code

How do I use this algorithm? What does that parameter do?
Post Reply
yhang
Posts: 3
Joined: 15 Jul 2022, 18:58

Newcomer of tenpy having an issue with my code

Post 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:

Python: 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"] * M.lat.N_sites
    psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc=M.lat.bc_MPS)
    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 = []
    E_list=[]
    eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
    a=0

    for chi in chi_list:

        t0 = time.time()
        eng.reset_stats(
        )  # 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")
        result=eng.run()
        eng.options['mixer'] = None
        psi.canonical_form()

        ##   Calculating bond entropy and correlation length  ##
        a+=1
        if a==len(chi_list):
            print("cnm")
            s_list=psi.entanglement_entropy()
        # the bond 0 is between MPS unit cells and hence sensible even for 2D lattices.
        #xi_list.append(psi.correlation_length())
        #print(result)
        E_list.append(result[0])

        print(chi,
              time.time() - t0,
              #np.mean(psi.expectation_value(M.H_bond)),
              #s_list[-1],
              #xi_list[-1],
              flush=True)
        tenpy.tools.optimization.optimize(3)  # quite some speedup for small chi

        print("SETTING NEW BOND DIMENSION")

    return s_list, xi_list, E_list

if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.INFO)
    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))]
    plt.plot(length,E_list)
    plt.show()
Attachments
Screen Shot 2022-07-15 at 10.23.13.png
Screen Shot 2022-07-15 at 10.23.13.png (190.35 KiB) Viewed 13274 times
User avatar
Johannes
Site Admin
Posts: 456
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Newcomer of tenpy having an issue with my code

Post 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:

Python: Select all

product_state = ["up", "down"]
psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc=M.lat.bc_MPS)
Post Reply