Query: Regarding Energy gap calculation
Closed this issue · 2 comments
hcut commented
In the following your code for calculation of energy gap of 1D Transverse Ising model, Could you please tell/explain me the purpose of line No. 17: return abs(sc.vev(sc.Sz[0]))
? Result is different when I don't use this line.
# 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
# This example shows the quantum phase transition in the trnasverse Ising model
# generate a 1D Ising chain
def get_gap(bx):
"""
Compute the gap of the 1D Ising model with DMRG
"""
print("Computing B_x = ",bx)
sc = spinchain.Spin_Chain([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
bs = np.linspace(0.,1.,30) # list of fields
gs = [get_gap(b) for b in bs] # list of gaps
import matplotlib.pyplot as plt
plt.plot(bs,gs,marker="o")
plt.xlabel("Bx")
plt.ylabel("Gap")
plt.show()
Thanks and Regards
joselado commented
Dear quantum-magnet,
thanks for your message .The line "return abs(sc.vev(sc.Sz[0]))" would return the magnetization of the system, so that the function would compute the magnetization instead of the gap. That is the reason why the result is different. I added a comment in the example to clarify this point. If you want to compute the gap, you can just remove "return abs(sc.vev(sc.Sz[0]))"
Best regards,
Jose
hcut commented
Thanks, for your timely reply and clarification.