Hi!
I wish to create a Hamiltonian which consist of sum of product of 12 local operators which are eventually added to the full Hamiltonian. I was able to create MPO of 12 local spin operators using
flux = AutoMPO()
for j in 1:((N/2)-3)
fl =Prod{Op}()
fl *= Op(“Sx”, i)
‘’’
‘’‘’
‘’’ #12 local operators
M= MPO(fl, sites)
global flux = sum(flux,M) #error
end
ham_fl = ham+flux
but I get error when I add this MPO M to another MPO.
I read the answer in the following link:
one way to solve my problem is to send set of M’s to dmrg functional. But I am not sure how to make array of M.
The other way is to add M to the hamiltonian. For which I am getting mismatch error.
Can you guide me how to create the Hamiltonian properly?
#usual spin interaction
ham = OpSum()
for j in 1:(N-1)
if isodd(j )
println("Sz", "\t", j, "\t", j+1)
ham .+= K, "Sz", j, "Sz", j+1
end
end
H = MPO(ham, sites)
#6-site interaction
F=0.0
flux = AutoMPO()
for j in 1:((N/2)-3)
i:: Int = 1 +(j-1)*2
fl = Prod{Op}()
fl *= Op("Sx",i+0)
fl *= Op("Sy",i+1)
fl *= Op("Sz",i+2)
fl *= Op("Sz",i+3)
fl *= Op("Sy",i+4)
fl *= Op("Sx",i+5)
M = MPO(fl, sites)
global flux = sum( flux, M)
#global flux .+= F, fl #Something I tried which caused error as well.
end
#Final Hamiltonian what I need
#ham_fl = ham + flux
Error:
LoadError: MethodError: objects of type Sum{Scaled{ComplexF64, Prod{Op}}} are not callable
Could you please write the code in a way that I could run it? For example there is a missing “end” statement and some other issues with it. I’m a little confused about some of the things you are trying with the code.
Mainly, my best guess of the issue here is that you are trying to add an AutoMPO to an MPO. But this is not defined. You will need to convert the AutoMPO to an MPO first. I see you have done this actually (H) but then you did not use H in the code at the end.
using ITensors
using DelimitedFiles
using Printf
using Random
include(get(ARGS, 1, "input.jl"))
sweeps = Sweeps(nsweep, sweeps_args)
sites = siteinds("S=1/2", N, conserve_qns=false)
ham = OpSum()
K = 1
# Kitaev exchange
for j in 1:(N-2)
if iseven(j)
ham .+= K, "Sx", j, "Sx", j+1
end
if isodd(j)
ham .+= K, "Sy", j, "Sy", j+3
end
end
for j in 1:(N-1)
if isodd(j )
ham .+= K, "Sz", j, "Sz", j+1
end
end
H = MPO(ham, sites)
#flux-interaction
F=0.0
flux = AutoMPO()
for j in 1:((N/2)-3)
i:: Int = 1 +(j-1)*2
fl = Prod{Op}()
fl *= Op("Sx",i+0)
fl *= Op("Sy",i+1)
fl *= Op("Sz",i+2)
fl *= Op("Sz",i+3)
fl *= Op("Sy",i+4)
fl *= Op("Sx",i+5)
M = MPO(fl, sites) #This is where I am creating a 6 site operator
global flux = sum( flux, M) # Adding one 6 site operator to flux
end
ham_fl = H + flux #adding flux operator for the whole lattice to hamiltonian
psi0 = randomMPS(sites, 10)
energy, psi = dmrg(ham_fl, psi0, sweeps)
@printf("Final energy = %.12f\n", energy)
ERROR: LoadError: MethodError: objects of type Sum{Scaled{ComplexF64, Prod{Op}}} are not callable
Thanks for posting the more complete code. I agree the error message could be clearer here, but if you look at the stack trace coming from the error message, it will point you to a particular line. That line is the following:
global flux = sum( flux, M)
There you are trying to add an MPO (M) to the object flux which is of type AutoMPO (note that these days we are calling AutoMPO OpSum but both names are allowed). I think the issue here is that one cannot add these two types in ITensor. An AutoMPO is just an object for storing a sum of operator names that will later be converted to an MPO. So if you want to sum the result of an AutoMPO with an MPO, you will need to convert the AutoMPO to an MPO first.
The good news is that for what you’re trying to do, you can just use AutoMPO entirely, like this:
os = OpSum() # equivalent to AutoMPO
for j in 1:((N/2)-3)
i = 1 +(j-1)*2
os += "Sx",i,"Sy",i+1,"Sz",i+2,"Sz",i+3,"Sy",i+4,"Sx",i+5
end
flux = MPO(os, sites)
Please let me know if that looks like it is doing what you want.