Cytnx-dev / Cytnx

Project Cytnx, A Cross-section of Python & C++,Tensor network library
Apache License 2.0
33 stars 13 forks source link

Tensor decomposition: ED #426

Open pcchen opened 4 months ago

pcchen commented 4 months ago

There are several related issues about various tensor decompositions. I will create several issues, but I will write some general guidelines here.

Proposed guideline: If we provide a tensor decomposition T -> A B C, where T, A, B, C are UniTensors, then we should design the bonds and labels of A, B, C, such that one can directly compare T and cyntax.Contract([A,B,C]) without any relabelling or combing bonds.

Specific issues related to ED

Consider first the non-symmetric UniTensor.

As a result,

How to get eigenvectors

How to check is is a square matrix (I propose we have some more strict rule here)

Following two code examples will run in current release, but I think maybe we should not allow this, because the in and out space are permuated somehow.

import cytnx
bond1 = cytnx.Bond(cytnx.BD_IN, [cytnx.Qs(1)>>2, cytnx.Qs(-1)>>2],[cytnx.Symmetry.U1()])
bond3 = cytnx.Bond(cytnx.BD_OUT, [cytnx.Qs(-1)>>2, cytnx.Qs(1)>>2], [cytnx.Symmetry.U1()])
uTsym = cytnx.UniTensor([bond1, bond3]).relabels(["a","b"]).set_name("uTsym")
uTsym.print_diagram()
cytnx.random.uniform_(uTsym, low=-1., high=1.)
print(uTsym)
eigvals, V = cytnx.linalg.Eigh(uTsym)
print(eigvals)
print(V)
import cytnx
bond1 = cytnx.Bond(cytnx.BD_IN, [cytnx.Qs(1)>>1, cytnx.Qs(-1)>>1],[cytnx.Symmetry.U1()])
bond2 = cytnx.Bond(cytnx.BD_IN, [cytnx.Qs(-1)>>1, cytnx.Qs(1)>>1],[cytnx.Symmetry.U1()])
bond3 = cytnx.Bond(cytnx.BD_OUT, [cytnx.Qs(-1)>>1, cytnx.Qs(1)>>1], [cytnx.Symmetry.U1()])
bond4 = cytnx.Bond(cytnx.BD_OUT, [cytnx.Qs(1)>>1, cytnx.Qs(-1)>>1], [cytnx.Symmetry.U1()])
uTsym = cytnx.UniTensor([bond1, bond2, bond3, bond4]).relabels(["a","b","c","d"]).set_name("uTsym")
uTsym.print_diagram()
cytnx.random.uniform_(uTsym, low=-1., high=1.)
print(uTsym)
eigvals, V = cytnx.linalg.Eigh(uTsym)
V.print_diagram()
print(eigvals)
# print(V)

For symmetric UniTensor, the output are sorted by block structure. It is hence difficult to see globally which is the i-th eivenvalue. (and also difficult to get eigenvector)

pcchen commented 4 months ago

Also, I think Lanczos will return higher-rank UniTensor. And when you define the LinOp, I think you basically need to match the in and out vector space.