Hi,
I am new to using ITensor (and Julia) and I noticed that the C++ version was outputting the vN entropy at the center bond as well as the energy, etc… after each sweep. On the other hand, the Julia version does not, and I’d like to do that. I’ve followed the advice I found in the documentation to define the vN entropy (see below)
using ITensors
function entropy_von_neumann(psi::MPS, b::Int)
s = siteinds(psi)
orthogonalize!(psi, b)
_,S = svd(psi[b], (linkind(psi, b-1), s[b]))
SvN = 0.0
for n in 1:dim(S, 1)
p = S[n,n]^2
SvN -= p * log(p)
end
return SvN
end
This works well after I finish the calculation, but I would like to output this after every sweep. From what I understood an observer is needed for that.
If I understood correctly a new ITensor.op
operator that calls the entropy_von_neumann
function needs to be defined and then be called under DMRGObserver
, followed by calling such observer in the dmg
arguments with outputlevel =1
.
Does anyone know how to do this?
function op!(Op::ITensor,::OpName"vN_entrop",::SiteType"MySiteType",s::Index)
Op[s'=>1,s=>3] = entropy_von_neumann(psi,b)
end
vN_observer = DMRGObserver(["vN_entrop"],sites,energy_tol=1E-7)
energy, psi = dmrg(H, psi0; nsweeps, maxdim, cutoff, noise, observer=vN_observer,outputlevel=1)
But I get the following error:
Overload of "op" or "op!" functions not found for operator name "vN_entrop" and Index tags: ("Electron,Site,n=9",)
And is also not very clear to me what should be the values going here Op[s'=>1,s=>3]
.
For context, I am trying to solve a small 3x3 OBC plain-vanilla Fermi Hubbard model in the square lattice.
Thanks!