Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Tensor A({3,4,5},Type.Double);
UniTensor tA = UniTensor(A); // convert directly.
UniTensor tB = UniTensor({Bond(3),Bond(4),Bond(5)},{}); // init from scratch.
// Relabel the tensor and then contract.
tA.relabels_({"common_1", "common_2", "out_a"});
tB.relabels_({"common_1", "common_2", "out_b"});
tA.relabel_({"common_1", "common_2", "out_a"});
tB.relabel_({"common_1", "common_2", "out_b"});
UniTensor out = cytnx::Contract(tA,tB);
tA.print_diagram();
tB.print_diagram();
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/linalg/Arnoldi_bm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace BMTest_Arnoldi {
const unsigned int& dtype = Type.Double, const int& device = Device.cpu);
UniTensor matvec(const UniTensor& l) override {
auto tmp = Contracts({A, l, B}, "", true);
tmp.relabels_(l.labels()).set_rowrank(l.rowrank());
tmp.relabel_(l.labels()).set_rowrank(l.rowrank());
return tmp;
}
};
Expand All @@ -22,15 +22,15 @@ namespace BMTest_Arnoldi {
std::vector<Bond> bonds = {Bond(D), Bond(d), Bond(D)};
A = UniTensor(bonds, {}, -1, in_dtype, in_device)
.set_name("A")
.relabels_({"al", "phys", "ar"})
.relabel_({"al", "phys", "ar"})
.set_rowrank(2);
B = UniTensor(bonds, {}, -1, in_dtype, in_device)
.set_name("B")
.relabels_({"bl", "phys", "br"})
.relabel_({"bl", "phys", "br"})
.set_rowrank(2);
T_init = UniTensor({Bond(D), Bond(D)}, {}, -1, in_dtype, in_device)
.set_name("l")
.relabels_({"al", "bl"})
.relabel_({"al", "bl"})
.set_rowrank(1);
if (Type.is_float(this->dtype())) {
double low = -1.0, high = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/linalg/Lanczos_bm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace BMTest_Lanczos {
* | | + | | "pi"
* |_|--"vol" "po" "vor"--|_|
*
* Then relabels ["vil", "pi", "vir"] -> ["vol", "po", "vor"]
* Then relabel ["vil", "pi", "vir"] -> ["vol", "po", "vor"]
*
* "vil":virtual in bond left
* "po":physical out bond
Expand Down
2 changes: 1 addition & 1 deletion developer_tools/dev_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# uT = cytnx.UniTensor.arange(2*3*4, name="tensor uT")
# uT.reshape_(2,3,4);
# uT.relabels_(["a","b","c"])
# uT.relabel_(["a","b","c"])

# T = cytnx.random.uniform([4,4], low=-1., high=1.)
# print(T)
Expand Down
84 changes: 42 additions & 42 deletions docs/code/CytnxGuide_PythonCodeExamples_2023_06_30.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@
"metadata": {},
"outputs": [],
"source": [
"uT=cytnx.UniTensor(cytnx.ones([2,3,4]), name=\"untagged tensor\").relabels_([\"a\",\"b\",\"c\"])\n",
"uT=cytnx.UniTensor(cytnx.ones([2,3,4]), name=\"untagged tensor\").relabel_([\"a\",\"b\",\"c\"])\n",
"\n",
"bond_d = cytnx.Bond(cytnx.BD_IN, [cytnx.Qs(1)>>1, cytnx.Qs(-1)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
Expand All @@ -1085,9 +1085,9 @@
"\n",
"bond_h = cytnx.Bond(2,cytnx.BD_IN)\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])\n",
"\n",
"Tdiag= cytnx.UniTensor([bond_g, bond_h], is_diag=True, name=\"diag tensor\").relabels_([\"g\",\"h\"])\n"
"Tdiag= cytnx.UniTensor([bond_g, bond_h], is_diag=True, name=\"diag tensor\").relabel_([\"g\",\"h\"])\n"
]
},
{
Expand Down Expand Up @@ -1238,7 +1238,7 @@
"uT.print_diagram()\n",
"\n",
"\n",
"uT.relabels_([\"a\",\"b\",\"c\"])\n",
"uT.relabel_([\"a\",\"b\",\"c\"])\n",
"\n",
"uT.print_diagram()"
]
Expand Down Expand Up @@ -1443,7 +1443,7 @@
"\n",
"bond_f = cytnx.Bond(cytnx.BD_OUT, [cytnx.Qs(2)>>1, cytnx.Qs(0)>>2, cytnx.Qs(-2)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])\n",
"\n",
"Tsymm.print_diagram()"
]
Expand Down Expand Up @@ -1495,7 +1495,7 @@
"\n",
" [cytnx.Qs(2)>>1, cytnx.Qs(0)>>2, cytnx.Qs(-2)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])"
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])"
]
},
{
Expand Down Expand Up @@ -1623,7 +1623,7 @@
"\n",
" [cytnx.Qs(2)>>1, cytnx.Qs(0)>>2, cytnx.Qs(-2)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])"
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])"
]
},
{
Expand Down Expand Up @@ -1685,7 +1685,7 @@
"\n",
" [cytnx.Qs(2)>>1, cytnx.Qs(0)>>2, cytnx.Qs(-2)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])\n",
"\n",
"Tsymm.print_diagram()\n",
"\n",
Expand Down Expand Up @@ -1892,11 +1892,11 @@
"source": [
"A = cytnx.UniTensor(cytnx.ones([2,8,8]));\n",
"\n",
"A.relabels_([\"phy\", \"left\", \"right\"])\n",
"A.relabel_([\"phy\", \"left\", \"right\"])\n",
"\n",
"B = cytnx.UniTensor(cytnx.ones([2,8,8]));\n",
"\n",
"B.relabels_([\"phy\", \"left\", \"right\"])\n",
"B.relabel_([\"phy\", \"left\", \"right\"])\n",
"\n"
]
},
Expand Down Expand Up @@ -1951,12 +1951,12 @@
"\n",
"A = cytnx.UniTensor(cytnx.ones([2,3,4]), rowrank = 1)\n",
"\n",
"A.relabels_([\"i\",\"j\",\"l\"])\n",
"A.relabel_([\"i\",\"j\",\"l\"])\n",
"\n",
"\n",
"B = cytnx.UniTensor(cytnx.ones([3,2,4,5]), rowrank = 2)\n",
"\n",
"B.relabels_([\"j\",\"k\",\"l\",\"m\"])\n",
"B.relabel_([\"j\",\"k\",\"l\",\"m\"])\n",
"\n",
"\n",
"C = cytnx.Contract(A, B)\n",
Expand All @@ -1978,16 +1978,16 @@
"source": [
"A = cytnx.UniTensor(cytnx.ones([2,3,4]), rowrank = 1)\n",
"\n",
"A.relabels_([\"i\",\"j\",\"l\"])\n",
"A.relabel_([\"i\",\"j\",\"l\"])\n",
"\n",
"Are = A.relabels([\"i\",\"j\",\"lA\"])\n",
"Are = A.relabel([\"i\",\"j\",\"lA\"])\n",
"\n",
"\n",
"B = cytnx.UniTensor(cytnx.ones([3,2,4,5]), rowrank = 2)\n",
"\n",
"B.relabels_([\"j\",\"k\",\"l\",\"m\"])\n",
"B.relabel_([\"j\",\"k\",\"l\",\"m\"])\n",
"\n",
"Bre = B.relabels([\"j\",\"k\",\"lB\",\"m\"])\n",
"Bre = B.relabel([\"j\",\"k\",\"lB\",\"m\"])\n",
"\n",
"\n",
"C = cytnx.Contract(Are, Bre)\n",
Expand Down Expand Up @@ -2018,11 +2018,11 @@
"\n",
"# Assign labels\n",
"\n",
"A1.relabels_([\"phy1\",\"v1\",\"v2\"])\n",
"A1.relabel_([\"phy1\",\"v1\",\"v2\"])\n",
"\n",
"M.relabels_([\"phy1\",\"phy2\",\"v3\",\"v4\"])\n",
"M.relabel_([\"phy1\",\"phy2\",\"v3\",\"v4\"])\n",
"\n",
"A2.relabels_([\"phy2\",\"v5\",\"v6\"])\n",
"A2.relabel_([\"phy2\",\"v5\",\"v6\"])\n",
"\n",
"\n",
"# Use Contracts\n",
Expand Down Expand Up @@ -2587,13 +2587,13 @@
"metadata": {},
"outputs": [],
"source": [
"A.relabels_([\"a\",\"0\",\"b\"])\n",
"A.relabel_([\"a\",\"0\",\"b\"])\n",
"\n",
"B.relabels_([\"c\",\"1\",\"d\"])\n",
"B.relabel_([\"c\",\"1\",\"d\"])\n",
"\n",
"la.relabels_([\"b\",\"c\"])\n",
"la.relabel_([\"b\",\"c\"])\n",
"\n",
"lb.relabels_([\"d\",\"e\"])\n",
"lb.relabel_([\"d\",\"e\"])\n",
"\n",
"\n",
"## contract all\n",
Expand All @@ -2616,7 +2616,7 @@
"\n",
"XH = cytnx.Contract(X,H)\n",
"\n",
"XH.relabels_([\"d\",\"e\",\"0\",\"1\"])\n",
"XH.relabel_([\"d\",\"e\",\"0\",\"1\"])\n",
"\n",
"XHX = cytnx.Contract(Xt,XH).item() ## rank-0\n",
"\n",
Expand Down Expand Up @@ -2665,7 +2665,7 @@
"lb_inv = 1./lb\n",
"\n",
"\n",
"lb_inv.relabels_([\"e\",\"d\"])\n",
"lb_inv.relabel_([\"e\",\"d\"])\n",
"\n",
"A = cytnx.Contract(lb_inv,A)\n",
"\n",
Expand All @@ -2689,13 +2689,13 @@
"for i in range(10000):\n",
"\n",
"\n",
" A.relabels_(['a','0','b'])\n",
" A.relabel_(['a','0','b'])\n",
"\n",
" B.relabels_(['c','1','d'])\n",
" B.relabel_(['c','1','d'])\n",
"\n",
" la.relabels_(['b','c'])\n",
" la.relabel_(['b','c'])\n",
"\n",
" lb.relabels_(['d','e'])\n",
" lb.relabel_(['d','e'])\n",
"\n",
"\n",
" ## contract all\n",
Expand Down Expand Up @@ -2732,7 +2732,7 @@
"\n",
" XH = cytnx.Contract(X,H)\n",
"\n",
" XH.relabels_(['d','e','0','1'])\n",
" XH.relabel_(['d','e','0','1'])\n",
"\n",
"\n",
" XHX = cytnx.Contract(Xt,XH).item() ## rank-0\n",
Expand Down Expand Up @@ -2799,7 +2799,7 @@
"\n",
" # lb_inv.print_diagram();\n",
"\n",
" lb_inv.relabels_(['e','d'])\n",
" lb_inv.relabel_(['e','d'])\n",
"\n",
"\n",
" A = cytnx.Contract(lb_inv,A)\n",
Expand Down Expand Up @@ -2903,7 +2903,7 @@
"\n",
" A[k] = cytnx.UniTensor(cytnx.random.normal([dim1, dim2, dim3],0.,1.),2)\n",
"\n",
" A[k].relabels_([2*k,2*k+1,2*k+2])\n",
" A[k].relabel_([2*k,2*k+1,2*k+2])\n",
"\n"
]
},
Expand Down Expand Up @@ -3011,7 +3011,7 @@
"\n",
" psi = cytnx.UniTensor(psi_T,2);\n",
"\n",
" psi.relabels_(lbl);\n",
" psi.relabel_(lbl);\n",
"\n",
" Ekeep.append(Entemp);\n",
"\n",
Expand All @@ -3029,7 +3029,7 @@
"\n",
" s = s/s.get_block_().Norm().item()\n",
"\n",
" s.relabels_(slabel)\n",
" s.relabel_(slabel)\n",
"\n",
"\n",
" A[p] = cytnx.Contract(A[p],s) ## absorb s into next neighbor\n",
Expand Down Expand Up @@ -3162,7 +3162,7 @@
"\n",
"s = s/s.get_block_().Norm().item()\n",
"\n",
"s.relabels_(slabel)\n",
"s.relabel_(slabel)\n",
"\n",
"\n",
"A[p] = cytnx.Contract(A[p],s) ## absorb s into next neighbor"
Expand Down Expand Up @@ -3247,7 +3247,7 @@
"\n",
" psi = cytnx.UniTensor(psi_T,2);\n",
"\n",
" psi.relabels_(lbl);\n",
" psi.relabel_(lbl);\n",
"\n",
" Ekeep.append(Entemp);\n",
"\n",
Expand All @@ -3266,7 +3266,7 @@
"\n",
" s = s/s.get_block_().Norm().item()\n",
"\n",
" s.relabels_(slabel)\n",
" s.relabel_(slabel)\n",
"\n",
"\n",
"\n",
Expand Down Expand Up @@ -3313,7 +3313,7 @@
"\n",
" psi_T.reshape_(dim_l,d,d,dim_r)## convert psi back to 4-leg form\n",
"\n",
" psi = cytnx.UniTensor(psi_T,2); psi.relabels_(lbl);\n",
" psi = cytnx.UniTensor(psi_T,2); psi.relabel_(lbl);\n",
"\n",
" Ekeep.append(Entemp);\n",
"\n",
Expand All @@ -3330,7 +3330,7 @@
"\n",
" s = s/s.get_block_().Norm().item()\n",
"\n",
" s.relabels_(slabel)\n",
" s.relabel_(slabel)\n",
"\n",
"\n",
" A[p+1] = cytnx.Contract(s,A[p+1]) ## absorb s into next neighbor.\n",
Expand Down Expand Up @@ -3664,12 +3664,12 @@
"\n",
"s0 = 1./s0\n",
"\n",
"s0.set_labels(['0','1'])\n",
"s0.relabel_(['0','1'])\n",
"\n",
"s2 = cytnx.Contract(cytnx.Contract(sL,s0),sR)\n",
"\n",
"\n",
"s2.set_labels(['-10','-11'])\n",
"s2.relabel_(['-10','-11'])\n",
"\n",
"A.set_label(2,'-10')\n",
"\n",
Expand Down Expand Up @@ -3812,7 +3812,7 @@
"\n",
" [cytnx.Qs(2)>>1, cytnx.Qs(0)>>2, cytnx.Qs(-2)>>1],[cytnx.Symmetry.U1()])\n",
"\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabels_([\"d\",\"e\",\"f\"])\n",
"Tsymm = cytnx.UniTensor([bond_d, bond_e, bond_f], name=\"symm. tensor\").relabel_([\"d\",\"e\",\"f\"])\n",
"\n",
"\n",
"for block in Tsymm.get_blocks_():\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/code/iTEBD/iTEBD.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
Elast = 0
for i in range(10000):

A.set_labels([-1,0,-2])
B.set_labels([-3,1,-4])
la.set_labels([-2,-3])
lb.set_labels([-4,-5])
A.relabel_([-1,0,-2])
B.relabel_([-3,1,-4])
la.relabel_([-2,-3])
lb.relabel_([-4,-5])

## contract all
X = cyx.Contract(cyx.Contract(A,la),cyx.Contract(B,lb))
Expand All @@ -103,7 +103,7 @@
# Note that X,Xt contract will result a rank-0 tensor, which can use item() toget element
XNorm = cyx.Contract(X,Xt).item()
XH = cyx.Contract(X,H)
XH.set_labels([-4,-5,0,1])
XH.relabel_([-4,-5,0,1])
XHX = cyx.Contract(Xt,XH).item() ## rank-0
E = XHX/XNorm

Expand Down Expand Up @@ -141,8 +141,8 @@
# --lb-A'-la-B'-lb--
#
# again, but A' and B' are updated
A.set_labels([-1,0,-2]); A.set_rowrank(1);
B.set_labels([-3,1,-4]); B.set_rowrank(1);
A.relabel_([-1,0,-2]); A.set_rowrank(1);
B.relabel_([-3,1,-4]); B.set_rowrank(1);

#A.print_diagram()
#B.print_diagram()
Expand Down
Loading
Loading