Problem with contracting a network of tensors.

Hi I am trying to contract a network of 4 tensors as shown in the figure attached

This is the code I am using for this -

using ITensors
let
  D = Index(9,"D")
  w = Index(2,"w")
  d = Index(2,"d")

  C = randomITensor(D,w,D)
  A = randomITensor(D,d,D)
  X = randomITensor(w,d,w,d)
  B = randomITensor(D,d,D)
  C1 = C * B
  C2 = C1 * X
  C3 = C2 * A
end

But it is giving an error saying wrong permutation of indices…what am I doing wrong?
This is the error code -
" ArgumentError: Invalid permutation of length 4: (4, 3, 3, 4)"

Thanks for the question; it’s a good question. The main issue with your code, and something which is not too obvious from the ITensor documentation unfortunately, is that in ITensor you aren’t allowed to use the exact same Index twice on a single ITensor. (E.g. your C ITensor has the Index D twice.) This behavior is intentional, and is necessary for our automatic contraction and addition operations to work properly.

The recommended practice in a case like yours is to use prime levels to distinguish indices.

So you could define C as

C = randomITensor(D,w,D')

and correspondingly prime the Index of A that you want to contract with the primed index of C, etc.

(When you think about the code you wrote above, notice that the computer has no way of knowing which of the two “D” indices of C should be contracted with the “D” indices of A. So the prime levels disambiguate that.)

Thanks for the swift reply…by the way is there any place where I can find the documentation of all the built in functions of ITensor say for creating operators etc. all of it in one place?

Great. Not sure what you’re asking, though, about “creating operators, etc.” because that could cover many things, and there are many objects that act like operators (certain ITensors, MPO tensor networks, operators created from names like “Sz” or “Sy”).

Overall our documentation is organized into categories like operations on individual ITensors, versus systems for making single-site operators out of local indices, to working with MPS and MPO tensor networks.

Here is the link to the documentation: https://itensor.github.io/ITensors.jl/stable/

Did you have a specific question about creating operators (and giving some more context about what you mean by “operator”)?

Thanks