0 votes
asked by (280 points)

Hi all,
I am trying to find expectation value of spin operator S_z in Heisenberg spin chain. Up until now, I have been using C++ ITensor format to get expectation value from MPS as described in following documentation: http://itensor.org/docs.cgivers=cppv3&page=formulas/correlator_mps

http://itensor.org/docs.cgi?vers=cppv3&page=formulas/measure_mps

I am not sure how do I define operators ( Ex: S_z acting at site j) acting at arbitrary sites and then take the expectation value in ITensor Julia version.
There is well defined way of defining operators in C++ ITensor like "auto Szjop = op(sites,"Sz",j) and gauging psi to measure at position j:
psi.position(j)
auto ket = psi(j);
auto bra = dag(prime(ket,"Site"))

I am having trouble in defining similar procedure in ITensor Julia version. I would like to know if it is possible to do same in ITensor Julia.
Thank you.

commented by (70.1k points)
Thanks, this is a great question. I’ll write a code formula soon about this and post a link to it in an answer below. The short version of the answer is that can do “Szjop = op(sites,”Sz”,j)” in Julia too (just remove the auto keyword); instead of “psi.position(j)” you do “orthogonalize!(psi,j)”; and finally instead of accessing an MPS tensor with “psi(j)” you do “psi[j]”.

Miles
commented by (280 points)
Hi Miles,
Thanks you so much. It worked. I used it following way:
psi=psi0;
    orthogonalize!(psi,j)
    psidag_j = dag(prime(psi[j], "Site"))
    SPIN+ = scalar(psidag_j * op(sites, "S+", j) * psi[j])
    SPIN- = scalar(psidag_j * op(sites, "S-", j) * psi[j])
    SPINz= scalar(psidag_j * op(sites, "Sz", j) * psi[j])
     Also, is there any command  to get complex output rather than scalar ( e.g.  to get expectation value of S_y or S_x) like "InnerC or eltC" defined in ITensor C++?
commented by (70.1k points)
Glad you figured it out! Also see the version I just posted below for a slightly different approach. (The main difference is that I retrieve the site index from the MPS instead of using the sites array.)

To answer your question about complex output, in the Julia version you can just use `scalar` and `inner` just as for real-valued ITensors and MPS. The reason is that in Julia you can have different return types of functions, whereas in C++ every function has to have a single return type. It’s one of many things we like better about Julia.

1 Answer

0 votes
answered by (70.1k points)

Hi Ajit,
Thanks for the question. I just began working on a "Code Formula" about this which you can find at this link:

http://itensor.org/docs.cgi?vers=julia&page=formulas/measure_mps

The formula already gives a working example for the case of measuring the "Sz" operator on each site of an MPS. I'll expand it over time to show some other examples and more context. Then later I'll add another formula about measuring correlation functions. (Though if you understand the above example and how to measure correlation functions in the C++ version of ITensor, the translation of the code for that case is very similar.)

Best regards,
Miles

Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...