Skip to content

Commit 98b1fd0

Browse files
Refactor projector steps for 2D and 3D HOTRG (#107)
* Refactor `_step_hotrg(3d)_x(y)` * Fix test
1 parent 69f7c49 commit 98b1fd0

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/schemes/hotrg.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Hence both are written explicitly.
4040
=#
4141

4242
function _get_hotrg_xproj(
43-
A1::TensorMap{E, S, 2, 2}, A2::TensorMap{E, S, 2, 2},
43+
A1::AbstractTensorMap{E, S, 2, 2}, A2::AbstractTensorMap{E, S, 2, 2},
4444
trunc::TensorKit.TruncationScheme
4545
) where {E, S}
4646
#= join in y-direction, keep x-indices open (A1 below A2)
@@ -72,7 +72,7 @@ function _get_hotrg_xproj(
7272
end
7373

7474
function _get_hotrg_yproj(
75-
A1::TensorMap{E, S, 2, 2}, A2::TensorMap{E, S, 2, 2},
75+
A1::AbstractTensorMap{E, S, 2, 2}, A2::AbstractTensorMap{E, S, 2, 2},
7676
trunc::TensorKit.TruncationScheme
7777
) where {E, S}
7878
#= join in x-direction, keep y-indices open (A1 on the left of A2)
@@ -104,50 +104,50 @@ function _get_hotrg_yproj(
104104
end
105105

106106
function _step_hotrg_y(
107-
A1::TensorMap{E, S, 2, 2}, A2::TensorMap{E, S, 2, 2},
108-
trunc::TensorKit.TruncationScheme
107+
A1::AbstractTensorMap{E, S, 2, 2}, A2::AbstractTensorMap{E, S, 2, 2},
108+
Ux::AbstractTensorMap{E, S, 2, 1}
109109
) where {E, S}
110110
#= compression along the y-direction
111111
-3
112112
|
113113
┌---1---A2---3--┐
114114
| | |
115-
-1--U† 5 U-- -4
115+
-1--Ux† 5 Ux-- -4
116116
| | |
117117
└---2---A1---4--┘
118118
|
119119
-2
120120
=#
121-
U, = _get_hotrg_xproj(A1, A2, trunc)
122121
@tensor T[-1 -2; -3 -4] :=
123-
conj(U[1 2; -1]) * U[3 4; -4] * A2[1 5; -3 3] * A1[2 -2; 5 4]
122+
conj(Ux[1 2; -1]) * Ux[3 4; -4] * A2[1 5; -3 3] * A1[2 -2; 5 4]
124123
return T
125124
end
126125

127126
function _step_hotrg_x(
128-
A1::TensorMap{E, S, 2, 2}, A2::TensorMap{E, S, 2, 2},
129-
trunc::TensorKit.TruncationScheme
127+
A1::AbstractTensorMap{E, S, 2, 2}, A2::AbstractTensorMap{E, S, 2, 2},
128+
Uy::AbstractTensorMap{E, S, 2, 1}
130129
) where {E, S}
131130
#= compression along the x-direction
132131
-3
133132
|
134-
┌3--U--4┐
133+
┌3--Uy-4┐
135134
| |
136135
-1--A1--5---A2-- -4
137136
| |
138-
└1--U†-2┘
137+
└1-Uy†-2┘
139138
|
140139
-2
141140
=#
142-
U, = _get_hotrg_yproj(A1, A2, trunc)
143141
@tensor T[-1 -2; -3 -4] :=
144-
A1[-1 1; 3 5] * A2[5 2; 4 -4] * conj(U[1 2; -2]) * U[3 4; -3]
142+
A1[-1 1; 3 5] * A2[5 2; 4 -4] * conj(Uy[1 2; -2]) * Uy[3 4; -3]
145143
return T
146144
end
147145

148146
function step!(scheme::HOTRG, trunc::TensorKit.TruncationScheme)
149-
scheme.T = _step_hotrg_y(scheme.T, scheme.T, trunc)
150-
scheme.T = _step_hotrg_x(scheme.T, scheme.T, trunc)
147+
Ux, = _get_hotrg_xproj(scheme.T, scheme.T, trunc)
148+
scheme.T = _step_hotrg_y(scheme.T, scheme.T, Ux)
149+
Uy, = _get_hotrg_yproj(scheme.T, scheme.T, trunc)
150+
scheme.T = _step_hotrg_x(scheme.T, scheme.T, Uy)
151151
return scheme
152152
end
153153

src/schemes/hotrg3d.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mutable struct HOTRG_3D <: TNRScheme
3434
end
3535

3636
function _get_hotrg3d_xproj(
37-
A1::TensorMap{E, S, 2, 4}, A2::TensorMap{E, S, 2, 4},
37+
A1::AbstractTensorMap{E, S, 2, 4}, A2::AbstractTensorMap{E, S, 2, 4},
3838
trunc::TensorKit.TruncationScheme
3939
) where {E, S}
4040
# join in z-direction, keep x-indices open (A1 below A2)
@@ -60,24 +60,30 @@ function _get_hotrg3d_xproj(
6060
return U, s, ε
6161
end
6262

63-
function _step_hotrg3d(
64-
A1::TensorMap{E, S, 2, 4}, A2::TensorMap{E, S, 2, 4},
63+
function _get_hotrg3d_yproj(
64+
A1::AbstractTensorMap{E, S, 2, 4}, A2::AbstractTensorMap{E, S, 2, 4},
6565
trunc::TensorKit.TruncationScheme
6666
) where {E, S}
67-
Ux, = _get_hotrg3d_xproj(A1, A2, trunc)
68-
# switch x/y directions
6967
perm = ((1, 2), (4, 3, 6, 5))
70-
Uy, = _get_hotrg3d_xproj(permute(A1, perm), permute(A2, perm), trunc)
71-
# apply the truncation
68+
return _get_hotrg3d_xproj(permute(A1, perm), permute(A2, perm), trunc)
69+
end
70+
71+
function _step_hotrg3d(
72+
A1::AbstractTensorMap{E, S, 2, 4}, A2::AbstractTensorMap{E, S, 2, 4},
73+
Ux::AbstractTensorMap{E, S, 2, 1}, Uy::AbstractTensorMap{E, S, 2, 1},
74+
) where {E, S}
7275
@tensoropt T[-1 -2; -3 -4 -5 -6] :=
7376
conj(Ux[x1 x2; -6]) * Ux[x1′ x2′; -4] *
7477
conj(Uy[y1 y2; -5]) * Uy[y1′ y2′; -3] *
7578
A1[-1 z; y1′ x1′ y1 x1] * A2[z -2; y2′ x2′ y2 x2]
7679
return T
7780
end
7881

82+
# HOTRG step to compress along z direction
7983
function _step!(scheme::HOTRG_3D, trunc::TensorKit.TruncationScheme)
80-
scheme.T = _step_hotrg3d(scheme.T, scheme.T, trunc)
84+
Ux, = _get_hotrg3d_xproj(scheme.T, scheme.T, trunc)
85+
Uy, = _get_hotrg3d_yproj(scheme.T, scheme.T, trunc)
86+
scheme.T = _step_hotrg3d(scheme.T, scheme.T, Ux, Uy)
8187
return scheme
8288
end
8389

0 commit comments

Comments
 (0)