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

0 votes

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

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.

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.

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.

...