Cytnx icon indicating copy to clipboard operation
Cytnx copied to clipboard

Network contraction error for symmetric tensors: rowrank cannot exceed the rank of UniTensor-1, and should be >=1.

Open chiamin opened this issue 2 years ago • 0 comments

I got an error in a Network contraction that I don't understand. When I used cytnx.Contract to implement the same contraction, no error occurred, so I suspect it is a bug in Network. Following is an code example

# Network for computing right environment tensors
LR_env_net = cytnx.Network()
LR_env_net.FromString(["LR: _mid, _up, _dn",
                       "A: _dn, _i, dn",
                       "M: _mid, mid, _ip, _i",
                       "A_Conj: _up, _ip, up",
                       "TOUT: mid, up, dn"])

# Define bonds
ii = cytnx.Bond(cytnx.BD_IN, [[0],[1]], [3,1], [cytnx.Symmetry.Zn(2)])
li = cytnx.Bond(cytnx.BD_IN, [[0]], [1], [cytnx.Symmetry.Zn(2)])
iip = ii.redirect()
lip = li.redirect()

# Define tensors
LR = cytnx.UniTensor([lip,lip,li], labels=["mid","dn","up"])
A = cytnx.UniTensor([li,ii,lip], labels=["l","i","r"])
W = cytnx.UniTensor([li,ii,iip,lip], labels=["l","ip","i","r"])



# The equivalent contraction using cytnx.Contract
# This works well
A1 = LR.relabels(['mid','dn','up'],['_mid','_dn','_up'])
A2 = A.relabels(['l','i','r'],['_dn','_i','dn'])
A3 = W.relabels(['l','r','ip','i'],['_mid','mid','_ip','_i'])
A4 = A.Dagger().relabels(['l','i','r'],['_up','_ip','up'])
tmp = cytnx.Contract(A1,A2)
tmp = cytnx.Contract(tmp,A3)
tmp = cytnx.Contract(tmp,A4)
print(tmp.labels())
print(tmp.bonds())



# Contraction using Network
# Errer occurs
LR_env_net.PutUniTensor("LR", LR, ['mid','up','dn'])
LR_env_net.PutUniTensor("A", A, ['l','i','r'])
LR_env_net.PutUniTensor("M", W, ['l','r','ip','i'])
LR_env_net.PutUniTensor("A_Conj", A.Dagger(), ['l','i','r'])
LR2 = LR_env_net.Launch()

and here is the error message

Traceback (most recent call last):
  File "/home/chiamin/project/2023/cytnx/test/gg.py", line 45, in <module>
    LR2 = LR_env_net.Launch()
RuntimeError: 
# Cytnx error occur at virtual void cytnx::BlockUniTensor::permute_(const std::vector<long int>&, const cytnx_int64&)
# error: [ERROR][BlockUniTensor] rowrank cannot exceed the rank of UniTensor-1, and should be >=1.

# file : /home/chiamin/cytnx_dev/Cytnx/src/BlockUniTensor.cpp (650)

chiamin avatar Dec 02 '23 02:12 chiamin