0 votes
asked by (290 points)
edited by

Hi Miles,
Given a MPS ,I want to apply a two site gate(i,i+1) to it.Can you please tell me how to construct this two site gate say
$$
\sigma^x \otimes \sigma^x
$$
acting on sites i,i+1.Thanks in advance.

commented by (640 points)
may be
auto operator = 4.0*sites.op("Sx",i)*sites.op("Sx",i+1);
commented by (290 points)
Hi abraDabra
      I have already tried that.It's giving me the following error.
"terminate called after throwing an instance of 'itensor::ITError'
  what():  doTask not defined for task Contract and storage types QDenseReal QMixed<Real>
Aborted (core dumped)
"
commented by (14.1k points)
Hello,

Could you please post a minimal (runnable) code for what you have tried? That would help us figure out what is going and where you are stuck.

Thanks!
Matt
commented by (290 points)
edited by
Hi Matt,
      Below is the code that I have used

    auto sites=SpinHalf(N);
    auto init = InitState(sites);
    for(auto n : range1(N))
    {
    init.set(n, "Up");    
    }
    auto psi = MPS(init);
    ITensor G = 1*sites.op("Sx",i)*sites.op("Sx",i+1);

One more thing I want to add is that If I remove the sites.op("Sx",i+1)  from the last line code seems to work.

1 Answer

+1 vote
answered by (14.1k points)

Hello,

Unfortunately in ITensor V2 this is admittedly a confusing situation. The following would be one way to do this:

auto N = 4;
auto sites = SpinHalf(N);
auto init = InitState(sites);
for(auto n : range1(N))
  {
  init.set(n, "Up");
  }
auto psi = MPS(init);
auto i = 2;
ITensor Sxi = sites.op("Sx",i);
ITensor Sxip = sites.op("Sx",i+1);
auto G = Sxi*Sxip;
PrintData(G);

The reason this works and what you tried did not is because by default, the SpinHalf SiteSet (and other SiteSets) create indices with QNs. That means operators like sites.op("Sx",i) must return an IQTensor. However, the "Sx" operator doesn't have a well defined QN. Through a little bit of a trick, we allow you to make this operator anyway, only so that it can get converted to an ITensor, for example using the line ITensor Sxi = sites.op("Sx",i). Once the operators are converted to ITensors, you can use them as you would any other ITensor, but before you convert them, the multiplication sites.op("Sx",i)*sites.op("Sx",i+1) is not defined (which is why you get an error message mentioning QMixed storage, which is the storage type those IQTensors are created with).

The situation is greatly improved in ITensor V3, where you can do the following:

auto N = 4;
auto sites = SpinHalf(N,{"ConserveQNs=",false});
auto init = InitState(sites);
for(auto n : range1(N))
  {
  init.set(n, "Up");    
  }
auto psi = MPS(init);
auto i = 2;
auto G = sites.op("Sx",i)*sites.op("Sx",i+1);
PrintData(G);

In ITensor V3, the IQTensor and ITensor classes have been merged, so all of the objects are ITensors. Putting {"ConserveQNs=",false} just makes the choice of whether or not the indices have QN information and whether or not the ITensors are block sparse. We would encourage you to try out ITensor V3 (http://www.itensor.org/docs.cgi?vers=cppv3&page=upgrade2to3 ) for this and a variety of other improvements.

Cheers,
Matt

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

...