Beispiel #1
0
def run_groundstate_xxz(L=30,
                        Jz=1.,
                        hz=0.,
                        conserve='best',
                        chi_max=50,
                        Jz_init=None):
    model_params = dict(L=L,
                        Jx=1.,
                        Jy=1.,
                        Jz=Jz,
                        hz=hz,
                        bc_MPS='finite',
                        conserve='best',
                        verbose=1)
    result = {}
    M = SpinChain(model_params)
    result['model'] = 'SpinChain'
    result['model_params'] = model_params

    result['sites'] = np.arange(L)
    result['bonds'] = np.arange(L - 1) + 0.5

    psi = MPS.from_product_state(M.lat.mps_sites(), (["up", "down"] * L)[:L])
    dmrg_params = {
        'trunc_params': {
            'chi_max': chi_max,
            'svd_min': 1.e-10,
            'trunc_cut': None
        },
        'mixer': True,
        'verbose': 1
    }
    if Jz_init:
        # run first time with small hx to break the symmetry
        model_params_Jz = model_params.copy()
        model_params_Jz['Jz'] = Jz_init
        M_Jz = SpinChain(model_params_Jz)
        dmrg_params['start_env'] = 10,
        run_DMRG(psi, M_Jz, dmrg_params)

    # run simulation
    t0 = time.time()

    info = run_DMRG(psi, M, dmrg_params)
    print("DMRG finished after", time.time() - t0, "s")

    # save results in output file
    result['chi'] = np.array(psi.chi)
    result['S'] = np.array(psi.entanglement_entropy())
    result['E'] = info['E']
    result['sweeps'] = info['sweep_statistics']['sweep']
    for key in ['E', 'S', 'max_trunc_err', 'max_E_trunc', 'max_chi']:
        result_key = 'sweep_' + key
        result[result_key] = np.array(info['sweep_statistics'][key])
    return result
Beispiel #2
0
def run(Jzs):
    L = 2
    model_params = dict(L=L,
                        Jx=1.,
                        Jy=1.,
                        Jz=1.,
                        bc_MPS='infinite',
                        conserve='Sz',
                        verbose=0)
    chi = 300
    dmrg_params = dict(trunc_params={
        'chi_max': chi,
        'svd_min': 1.e-10,
        'trunc_cut': None
    },
                       update_env=20,
                       start_env=20,
                       max_E_err=0.0001,
                       max_S_err=0.0001,
                       verbose=1,
                       mixer=True)

    M = SpinChain(model_params)
    psi = MPS.from_product_state(M.lat.mps_sites(), (["up", "down"] * L)[:L],
                                 M.lat.bc_MPS)

    np.set_printoptions(linewidth=120)
    corr_length = []
    for Jz in Jzs:
        print("-" * 80)
        print("Jz =", Jz)
        print("-" * 80)
        model_params['Jz'] = Jz
        M = SpinChain(model_params)
        run_DMRG(psi, M, dmrg_params)
        corr_length.append(psi.correlation_length(tol_ev0=1.e-3))
        print("corr. length", corr_length[-1])
        print("<Sz>", psi.expectation_value('Sz'))
    corr_length = np.array(corr_length)
    results = {
        'model_params': model_params,
        'dmrg_params': dmrg_params,
        'Jzs': Jzs,
        'corr_length': corr_length,
        'eval_transfermatrix': np.exp(-1. / corr_length)
    }
    return results
Beispiel #3
0
xxz_pars = dict(L=4, Jxx=1., Jz=1., hz=0.0, bc_MPS='finite')
M = XXZChain(xxz_pars)
ED = ExactDiag(M, [0])
ED.build_full_H_from_mpo()
# ED.build_full_H_from_bonds()  # whatever you prefer
print("start diagonalization")
ED.full_diagonalization()
psi_ED = ED.groundstate()
print("psi_ED =", psi_ED)

print("start DMRG")
product_state = [0, 1] * (xxz_pars['L'] // 2)  # this selects a charge sector!
psi_DMRG = MPS.from_product_state(M.lat.mps_sites(), product_state)

res = run_DMRG(psi_DMRG, M, {'verbose': 0})
# first way to compare ED with DMRG: convert MPS to ED vector
psi_DMRG_full = ED.mps_to_full(psi_DMRG)
print("psi_DMRG_full =", psi_DMRG_full)
ov = abs(npc.inner(psi_ED, psi_DMRG_full, do_conj=True))
print("|<psi_ED|psi_DMRG>| =", ov)
assert (abs(ov - 1.) < 1.e-13)

# second way: convert ED vector to MPS
psi_ED_mps = ED.full_to_mps(psi_ED)
ov = psi_ED_mps.overlap(psi_DMRG)
print("|<psi_ED_mps|psi_DMRG>| =", abs(ov))
assert (abs(abs(ov) - 1.) < 1.e-13)
# -> advantange: expectation_value etc. of MPS are available!
print("<Sz> =", psi_ED_mps.expectation_value('Sz'))
Beispiel #4
0
def run(Jzs):
    L = 2
    bc = 'infinite'
    model_params = dict(L=L,
                        Jx=1.,
                        Jy=1.,
                        Jz=1.,
                        bc_MPS=bc,
                        conserve='Sz',
                        verbose=0)
    chi = 300
    dmrg_params = dict(trunc_params={
        'chi_max': chi,
        'svd_min': 1.e-10,
        'trunc_cut': None
    },
                       update_env=20,
                       start_env=20,
                       max_E_err=0.0001,
                       max_S_err=0.0001,
                       verbose=1,
                       mixer=True)  # TODO: mixer?

    M = SpinChain(model_params)
    psi = MPS.from_product_state(M.lat.mps_sites(), [1, 0] * (L // 2), bc)
    #  B = np.zeros([2, 2, 2])
    #  B[0, 0, 0] = B[1, 1, 1] = 1.
    #  psi = MPS.from_Bflat(M.lat.mps_sites(), [B]*L, bc=bc)

    np.set_printoptions(linewidth=120)
    corr_length = []
    for Jz in Jzs:
        print("-" * 80)
        print("Jz =", Jz)
        print("-" * 80)
        model_params['Jz'] = Jz
        M = SpinChain(model_params)
        #  #  psi = MPS.from_product_state(M.lat.mps_sites(), [1, 1]*(L//2), bc)
        #  B = np.zeros([2, 2, 2])
        #  B[0, 0, 0] = B[1, 1, 1] = 1.
        #  psi = MPS.from_Bflat(M.lat.mps_sites(), [B]*L, bc=bc)
        run_DMRG(psi, M, dmrg_params)
        if bc == 'infinite':
            #  T = TransferMatrix(psi, psi, charge_sector=None)
            #  E, V = T.eigenvectors(4, which='LM')
            #  chi = psi.chi[0]
            #  print V[0].to_ndarray().reshape([chi, chi])[:5, :5] * chi**0.5
            #  if len(V) > 1:
            #      print V[1].to_ndarray().reshape([chi, chi])[:5, :5] * chi**0.5
            #  print "chi:", psi.chi
            #  print "eigenvalues transfermatrix:", E
            #  print "norm_test:", psi.norm_test()
            corr_length.append(
                psi.correlation_length(charge_sector=0, tol_ev0=1.e-3))
            print("corr. length", corr_length[-1])
            print("corr. fct.",
                  psi.correlation_function('Sz', 'Sz', sites1=[0], sites2=6))
            print("<Sz>", psi.expectation_value('Sz'))
        else:
            print(psi.correlation_function('Sz', 'Sz'))
    corr_length = np.array(corr_length)
    results = {
        'model_params': model_params,
        'dmrg_params': dmrg_params,
        'Jzs': Jzs,
        'corr_length': corr_length,
        'eval_transfermatrix': np.exp(-1. / corr_length)
    }
    return results