+1 vote
asked by (190 points)

Is there a way I can keep them in a particular order?

1 Answer

0 votes
answered by (70.1k points)

It's a good question but I've intentionally tried to make ITensor usable without anything depending on this order on the user level. There is one, maybe two, places on the developer level of the code where I rely on the indices being in a certain order but so far the contract in the design is that the library can internally permute the order of the indices however it wants as long as the tensor data is permuted in the same way.

Can you say more about why you need to keep the indices in a certain order? Maybe there is a different solution to your problem?

Miles

commented by (190 points)
My situation is to simulate quantum circuits. When constructing the gate tensor, I need to get the index the wavefunction corresponding to the qubit which the gate is acting on. The wavefunction initially has its indecies in a particular order (the same as qubits indecies), however, after several gates, the indecies of the wavefunction are no longer in the same order as qubits.
commented by (70.1k points)
Ok I see then how that could mix up the order of the indices. So an "ITensor way" of dealing with this is to make use of the index type feature. It sounds like the wavefunction you're working with is an MPS, correct? And that after you apply the gates you restore MPS form by doing an SVD, correct? In that case each MPS tensor would always have a single, unique physical index and the convention I use, and is used throughout ITensor, is to make these physical indices have the `Site` type. Then if you are wanting to retrieve the physical index of a certain MPS tensor, say the one at site n, you can do:
    auto si = findtype(psi.A(n),Site);
to get the index of type `Site` on the nth MPS tensor.

Let me know if this doesn't solve your problem though.
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

...