def getsc(app): """Get the spin chain""" spins = get_spins() # return the spins sc = spinchain.Spin_Hamiltonian(spins) # return spin chain object # now initialize the Hamiltonian fj = get_exchange_function(app) # add exchange field fb = get_field_function(app) # get the function that adds b field ns = len(spins) h = 0 # initialize # add exchange for i in range(ns): # loop for j in range(ns): # loop cij = fj(i, j) # get matrix Si = [sc.Sx[i], sc.Sy[i], sc.Sz[i]] Sj = [sc.Sx[j], sc.Sy[j], sc.Sz[j]] for ii in range(3): for jj in range(3): if cij[ii, jj] != 0.0: h = h + cij[ii, jj] * Si[ii] * Sj[jj] # add zeeman for i in range(ns): # loop Si = [sc.Sx[i], sc.Sy[i], sc.Sz[i]] bi = fb(i) for ii in range(3): if bi[ii] != 0.0: h = h + bi[ii] * Si[ii] sc.set_hamiltonian(h) sc.maxm = int(app.get("maxm")) sc.kpmmaxm = int(app.get("maxm")) sc.nsweeps = int(app.get("nsweeps")) return sc
def get_energy(ind): """Given a certain ordering of the indexes, return the energy""" n = len(ind) spins = [2 for i in range(n)] # list with the different spins of your system sc = spinchain.Spin_Hamiltonian(spins) # create the spin chain object sc.maxm = 10 # bond dimension, controls the accuracy sc.nsweeps = 3 def fj(i,j): if abs(ind[i]-ind[j])==1: return 1.0 return 0.0 sc.set_exchange(fj) # add the exchange couplings return sc.gs_energy()
def getsc(iv): # create first neighbor exchange sc = spinchain.Spin_Hamiltonian(spins) # create the spin chain def fj(i, j): if abs(i - j) == 1: return 1.0 else: return 0.0 sc.set_exchange(fj) sc.itensor_version = iv sc.get_gs() return sc
def getsc(app): """Get the spin chain""" spins = get_spins() # return the spins sc = spinchain.Spin_Hamiltonian(spins) # return spin chain object # now initialize the Hamiltonian fj = get_exchange_function(app) # add exchange field fb = get_field_function(app) # get the function that adds b field sc.set_exchange(fj) # add the exchange sc.set_fields(fb) # set the magnetic field sc.maxm = int(app.get("maxm")) sc.kpmmaxm = int(app.get("maxm")) sc.nsweeps = int(app.get("nsweeps")) return sc
def get_gap(bx): """ Compute the gap of the 1D Ising model with DMRG """ print("Computing B_x = ", bx) sc = spinchain.Spin_Hamiltonian([2 for i in range(30)]) # create h = 0 for i in range(sc.ns - 1): h = h + sc.Sz[i] * sc.Sz[i + 1] for i in range(sc.ns): h = h + bx * sc.Sx[i] sc.set_hamiltonian(h) return abs(sc.vev(sc.Sz[0])) es = sc.get_excited(mode="DMRG", n=2) # compute the first two energies return es[1] - es[0] # return the gap
# Add the root path of the dmrgpy library import os import sys sys.path.append(os.getcwd() + '/../../src') import numpy as np # conventional numpy library from dmrgpy import spinchain # library dealing with DMRG for spin chains import matplotlib.pyplot as plt # library to plot the results #################################### ### Create the spin chain object ### #################################### n = 8 # total number of spins spins = [2 for i in range(n)] # list with the different spins of your system # the spins are labeled by 2s+1, so that 2 means s=1/2, 3 meand S=1 .... sc = spinchain.Spin_Hamiltonian(spins) # create the spin chain object ############################## ### Create the hamiltonian ### ############################## def fj(i, j): # function to define the exchange couplings if abs(i - j) == 1: return np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # first neighbors else: return 0.0 # otherwise sc.set_exchange(fj) # add the exchange couplings #sc.set_fields(lambda i: np.random.random(3)) # optionally you could add local magnetic fields # parameters controlling the DMRG algorithm, in principle default ones are fine #sc.maxm = 40 # maximum bond dimension
# Add the root path of the dmrgpy library import os import sys sys.path.append(os.getcwd() + '/../../src') import numpy as np from dmrgpy import spinchain ns = np.array(range(4, 30, 2)) es = [] n = 6 spins = [2 for i in range(n)] sc = spinchain.Spin_Hamiltonian(spins) # create the chain sc.clean() sc = spinchain.Spin_Hamiltonian(spins) # create the chain def fj(i, j): if 0.9 < abs(i - j) < 1.1: return 1.0 return 0.0 sc.set_exchange(fj) # set exchange couplings #sc.set_fields(lambda x: [0.2,0.2,0.2]) # set exchange couplings sc.maxm = 10 sc.get_gs() i = 0 j = 5 (x, y) = sc.evolution(nt=1000, dt=0.03, mode="ED", name="ZZ", i=i, j=j) (x1, y1) = sc.evolution(nt=1000, dt=0.03, mode="DMRG", name="ZZ", i=i, j=j) import matplotlib.pyplot as plt plt.subplot(1, 2, 1)
if i == j: return -2 * U # set to half filling return 0.0 def fu(i, j): if i == j: return U return 0.0 fc.set_hoppings(ft) # add the term to the Hamiltonian fc.set_hubbard(fu) # add the term to the Hamiltonian pairs = [(0, i) for i in range(n)] ch = fc.get_correlator(pairs=pairs, name="YY", mode="DMRG").real print(fc.get_density_spinful()) # now create the Heisenberg chain sc = spinchain.Spin_Hamiltonian([2 for i in range(n)]) sc.set_exchange(lambda i, j: 1.0 * (abs(i - j) == 1)) cs = sc.get_correlator(pairs=pairs, name="XX", mode="DMRG").real import matplotlib.pyplot as plt inds = range(len(ch)) plt.scatter(inds, ch, c="red", label="Hubbard") plt.plot(inds, cs, c="blue", label="Heisenberg") #plt.plot(inds,mz2,c="green",label="Exact") plt.legend() plt.xlabel("Site") plt.ylabel("Correlator") plt.show()