joselado / dmrgpy

DMRGPy is a Python library to compute quasi-one-dimensional spin chains and fermionic systems using matrix product states with DMRG as implemented in ITensor. Most of the computations can be performed both with DMRG and exact diagonalization for small systems, which allows one to benchmark the results.
GNU General Public License v3.0
83 stars 20 forks source link

Query: Regarding Energy gap calculation #18

Closed hcut closed 1 year ago

hcut commented 1 year ago

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 1 year ago

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 1 year ago

Thanks, for your timely reply and clarification.