Explicitly construct the reduced density matrix

Dear ITensor team,

For my specific requirements, I need to explicitly construct the reduced density matrix. The basic procedure I have followed is to first shift the canonical center of the MPS to a particular site, and then perform an SVD to obtain matrices U, S, and V. My goal is to compute U*S*U^\dag. To achieve this, I attempted to replace the left index of U^\dag (dagged the right link Index of U) with the left index of V.

   # the right index of U
    indA = commonind(U, S; tags = "Link")
    # the left index of V
    indB = commonind(V, S; tags = "Link")

    #the left link of Aux MPS  tensor is replected by the left index of V
    replaceind!(Udag, dag(indA), indB)

However, some problems arise as following

 LoadError: Attempting to replace the Indices

((dim=2|id=730|"Link,u") <Out>
 1: QN("Sz",2) => 1
 2: QN("Sz",0) => 1,)

with

((dim=2|id=228|"Link,v") <In>
 1: QN("Sz",-2) => 1
 2: QN("Sz",0) => 1,)

in the Index collection

((dim=2|id=412|"Aux,S=1/2,Site,n=12") <In>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1, (dim=2|id=624|"Link,l=13") <In>
 1: QN("Sz",1) => 1
 2: QN("Sz",-1) => 1, (dim=2|id=730|"Link,u") <Out>
 1: QN("Sz",2) => 1
 2: QN("Sz",0) => 1).

However, the Index

(dim=2|id=730|"Link,u") <Out>
 1: QN("Sz",2) => 1
 2: QN("Sz",0) => 1

has a different space from the Index

(dim=2|id=228|"Link,v") <Out>
 1: QN("Sz",-2) => 1
 2: QN("Sz",0) => 1.

They must have the same spaces to be replaced.

In the presence of QN, how can I correctly construct the reduce density matrix explicitly.

Best regards.

ZHOU Zongsheng.

I am not 100% sure about your requirement, but since the reduce density matrix is S^2 instead of S, a possible way is to calculate USV^\dagger * (USV^\dagger)^\dagger or US * (US)^\dagger and in these ways your contract the (right) left index of V to the (right) left index of V and do not need to replace the index.

If you really want S itself, another way (though not so straightforward) is to define an \tilde{S} by replacing matrix element of S by an identity matrix and then contract it to S (remember to use prime level so that only the link "Link,v" is contracted) to obtain a tensor with two legs are all links "Link,u" .

(Maybe there is better way to directly replace the Index but I am not familiar with it so I just offer some possible solutions. )

Thanks for your help. I am sorry for my unclear description of my problem. In fact, I want to construct \sqrt{\rho}. Your suggestion about redefining a new S seems promising. I will try it.

Thanks again for your help.

Best wishes!

ZHOU Zongsheng