Hi,
I am new to ITensor, so please forgive me if my question is naive. I want to get the results of string correlation function like <psi | N_i N_i+1 N_i+2 … N_L|psi>. From searching the categories, I finded it that I can achieve my goal as far as using the OpSum interface:
os = OpSum()
os *= "N",i,"N",2,"N",3,...,"N",L
But, at the end, I encountered some errors. I could not find the problems from the tensors. Here are my codes:
using ITensors
L=10;cutoff=1E-8;δτ=0.1;beta_max=2.0;
function ITensors.op(::OpName"expτnn", ::SiteType"Boson", adag::Index,amis::Index; τ)
h =
1 / 2 * op("a†", adag) * op("A", amis) +
1 / 2 * op("A", amis) * op("a†", adag) +
op("N", adag) * op("N",amis)
return exp(τ * h)
end
s = siteinds("Boson", L; conserve_number=false);
gates = ops([("expτnn", (e, e + 1), (τ=-δτ / 2,)) for e in 1:(L - 1)], s);
append!(gates, reverse(gates));
rho = MPO(s, "Id") ./ √2;
terms = OpSum();
U=4;V=4;
for j in 1:(L - 1)
terms += "a†", j, "A", j + 1
terms += "A", j, "a†", j + 1
terms += U / 2, "N", j, "N", j
terms += V, "N", j, "N", j + 1
end
H = MPO(terms, s)
for w in 0:δτ:beta_max
energy = inner(rho, H)
@printf("β = %.2f energy = %.8f\n", w, energy)
rho = apply(gates, rho; cutoff)
rho = rho / tr(rho)
end
τ_range = δτ:δτ:(beta_max / 2)
psi = randomMPS(s);
for τ in τ_range
psi = apply(gates, psi; cutoff)
normalize!(psi)
end
n_2=op("N",s[2]);
n_3=op("N",s[3]);
n_4=op("N",s[4]);
n_5=op("N",s[5]);
orthogonalize!(psi,2)
c=psi[2];
c *= n_2;
ir2=commonindex(psi[2],psi[3],"Link");
c *=dag(prime(prime(psi[2],"Site"),ir2));
c *=psi[3];
c *=n_3;
c *=dag(prime(prime(psi[3],"Site"),"Link"));
c *=psi[4];
c *=n_4;
c *=dag(prime(prime(psi[4],"Site"),"Link"));
c *=psi[5];
c *=n_5;
il5=commonindex(psi[5],psi[4],"Link");
c *=dag(prime(prime(psi[5],"Site"),il5));
scalar(c)
The error tolds me that “In scalar(T) or T, ITensor T is not a scalar.” Please tell me the reasons and give me a hand.
Thanks a lot!