Thank you so much Miles! Could you explain how to "grab the index 'u' connecting U to S," as you said earlier? I think this is actually the issue I am running into right now. Basically, in the factorization step, the link connecting site j to site j+1 gets a different id value from what it was before. In the default 2-site DMRG, the program seems to successfully recognize this. However, when I tried to generalize it, the program fails to recognize the new link index as the link connecting sites j and j+1.
As an example, when I run DMRG on a 10-site chain with ncenter=5, this is what happens when I print the state after the first step of the first sweep:
ITensors.MPS
[1] IndexSet{2} (dim=2|id=341|"S=1/2,Site,n=1") (dim=2|id=243|"Link,l=1")
[2] IndexSet{2} (dim=2|id=823|"S=1/2,Site,n=2") (dim=2|id=547|"Link,l=2")
[3] IndexSet{2} (dim=2|id=998|"S=1/2,Site,n=3") (dim=2|id=965|"Link,l=3")
[4] IndexSet{2} (dim=2|id=329|"S=1/2,Site,n=4") (dim=2|id=841|"Link,l=4")
[5] IndexSet{6} (dim=2|id=841|"Link,l=4") (dim=2|id=965|"Link,l=3") (dim=2|id=547|"Link,l=2") (dim=2|id=243|"Link,l=1") (dim=1|id=86|"Link,l=5") (dim=2|id=424|"S=1/2,Site,n=5")
[6] IndexSet{3} (dim=1|id=86|"Link,l=5") (dim=2|id=733|"S=1/2,Site,n=6") (dim=1|id=351|"Link,l=6")
[7] IndexSet{3} (dim=1|id=351|"Link,l=6") (dim=2|id=483|"S=1/2,Site,n=7")
(dim=1|id=776|"Link,l=7")
[8] IndexSet{3} (dim=1|id=776|"Link,l=7") (dim=2|id=436|"S=1/2,Site,n=8") (dim=1|id=409|"Link,l=8")
[9] IndexSet{3} (dim=1|id=409|"Link,l=8") (dim=2|id=231|"S=1/2,Site,n=9") (dim=1|id=818|"Link,l=9")
[10] IndexSet{2} (dim=1|id=818|"Link,l=9") (dim=2|id=317|"S=1/2,Site,n=10")
Notice how the link indices don't get recognized as part, so when you do the step
factorize(phi_new[1],inds(M[b+j]); which_decomp = which_decomp,
tags = tags(linkind(M,b+j)),
kwargs...)
(this is part of a for loop where j starts at 0 and ends at ncenter-2), the code doesn't separate the index that it should. I can post my attempted code in a bit more detail if that would help.