Hello everybody, I’m a newbie to the ITensor library and in general to coding in Julia and I’ve been tasked for an exam to develop a code able to analyze basic properties (ground state energy, entanglement entropy etc.) of quantum many-body systems using ITensor so here I am desperately asking for help.
Looking through the documentation given to us by the devs of this wonderful library I found some code that was supposed to return ground state energy of a given model which i replaced with the infamous hamiltonian of 1d ising’s model.
I looked online and found a bunch of examples and I’ve been finding contrasting outcomes since.
In a 1d ising model considering h as our external magnetic field (transverse, so on the x axis) we’re supposed to have a critical point in h = 1 and in general with our field “shut off” as a function of the spin coupling J (the first term in our hamiltonian in front of the sum) the energy of our gs should look like a straight line with negative angular coefficient (feel free to underline any mistakes in my understanding of the model cause i’m still trying to figure it out theoretically).
What I’m getting from 3 different codes is a totally different behaviour.
What happens once i plot all the values returned by the code is that i get with my field shut off an upside down “module function” (like a triangle with no base) and once i turn my field on it turns out to be a parabola pointing downwards, i tried changing signs in my ampos but nothing changes, what am i doing wrong??
Here’s the code for the kind-hearted person that wants to dig deeper into this “Ising mistery”:
begin
# In this example we show how to pass a DMRGObserver to
# the dmrg function which allows tracking energy convergence and
# convergence of local operators.
using ITensors
"""
Get MPO of transverse field Ising model Hamiltonian with field strength h
"""
function tfimMPO(sites, h::Float64)
# Input operator terms which define a Hamiltonian
N = length(sites)
os = OpSum()
for j in 1:(N - 1)
os += 1, "Z", j, "Z", j + 1
end
for j in 1:N
os += h, "X", j
end
# Convert these terms to an MPO tensor network
return MPO(os, sites)
end
let
N = 100
sites = siteinds("S=1/2", N)
psi0 = randomMPS(sites; linkdims=10)
# define parameters for DMRG sweeps
nsweeps = 15
maxdim = [10, 20, 100, 100, 200]
cutoff = [1E-10]
#=
create observer which will measure Sᶻ at each
site during the dmrg sweeps and track energies after each sweep.
in addition it will stop the computation if energy converges within
1E-7 tolerance
=#
let
Sz_observer = DMRGObserver(["Sz"], sites; energy_tol=1E-7)
# we will now run DMRG calculation for different values
# of the transverse field and check how local observables
# converge to their ground state values
println("Running DMRG for TFIM with h=0.0")
println("================================")
H = tfimMPO(sites, 0.1)
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff, observer=Sz_observer)
end
end
end
and here’s my attempt of writing a code:
begin
using ITensors
function main()
# Definire i parametri del modello di Ising
L = 10 # Numero di siti nella catena
J = 1.0 # Accoppiamento di spin
h = 0.5 # Campo magnetico esterno
# Creare gli indici di sito per una catena di spin-1/2
sites = siteinds("S=1/2", L)
# Costruire l'Hamiltoniano utilizzando AutoMPO
ampo = AutoMPO()
for j=1:L-1
ampo += J, "Sz", j, "Sz", j+1
ampo += h, "Sx", j
end
ampo += h, "Sx", L
H = MPO(ampo, sites)
# Inizializzare lo stato MPS casuale
psi0 = randomMPS(sites)
# Impostare i parametri per l'algoritmo DMRG
sweeps = Sweeps(5) # Numero di iterazioni DMRG
maxdim!(sweeps, 100, 200, 400, 800, 1000)
cutoff!(sweeps, 1E-10)
# Eseguire l'algoritmo DMRG per trovare l'energia dello stato fondamentale
energy, psi = dmrg(H, psi0, sweeps)
println("Energia dello stato fondamentale: ", energy)
end
main()
end
PS I’m sorry for my English, it’s been a lot since I last had to use it properly and it’s a bit “rusty”, add to it the fact that specifical math/physics terms are different in my native language and here you have this “melting pot” of weird terms tryin to make sense out of what I was tryin to say.
Thanks for the attention, hopefully someone wiser and more experienced than me can help me uncover the mistery! <3 <3 <3