Skip to content

Commit 8725a8e

Browse files
committed
Precomputed derivatives II
1 parent 96059a9 commit 8725a8e

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

src/algorithms/derivatives/mpo_derivatives.jl

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ function prepare_operator!!(
130130
@plansor backend = backend allocator = allocator begin
131131
GL_O[-1 -2 -3; -4 -5] := H.leftenv[-1 1; -4] * H.operators[1][1 -2; -5 -3]
132132
end
133-
return PrecomputedDerivative(TensorMap(GL_O), TensorMap(H.rightenv), backend, allocator), x
133+
leftenv = TensorMap(GL_O)
134+
rightenv = TensorMap(H.rightenv)
135+
BraidingStyle(sectortype(rightenv)) === NoBraiding() ||
136+
(rightenv = braid(rightenv, ((2, 1), (3,)), (1, 2, 3)))
137+
138+
return PrecomputedDerivative(leftenv, rightenv, backend, allocator), x
134139
end
135140

136141
function prepare_operator!!(
@@ -142,17 +147,59 @@ function prepare_operator!!(
142147
GL_O[-1 -2 -3; -4 -5] := H.leftenv[-1 1; -4] * H.operators[1][1 -2; -5 -3]
143148
O_GR[-1 -2 -3; -4 -5] := H.operators[2][-3 -5; -2 1] * H.rightenv[-1 1; -4]
144149
end
145-
return PrecomputedDerivative(TensorMap(GL_O), TensorMap(O_GR), backend, allocator), x
150+
leftenv = TensorMap(GL_O)
151+
rightenv = TensorMap(O_GR)
152+
BraidingStyle(sectortype(rightenv)) === NoBraiding() ||
153+
(rightenv = braid(rightenv, ((3, 1, 2), (4, 5)), (1, 2, 3, 4, 5)))
154+
return PrecomputedDerivative(leftenv, rightenv, backend, allocator), x
146155
end
147156

148157
function (H::PrecomputedDerivative)(x::MPSTensor)
149-
return @plansor backend = H.backend allocator = H.allocator begin
150-
y[-1 -2; -3] ≔ H.leftenv[-1 -2 4; 1 2] * x[1 2; 3] * H.rightenv[3 4; -3]
158+
bstyle = BraidingStyle(sectortype(x))
159+
return _precontracted_ac_derivative(bstyle, x, H.leftenv, H.rightenv, H.backend, H.allocator)
160+
end
161+
162+
function _precontracted_ac_derivative(::NoBraiding, x, leftenv, rightenv, backend, allocator)
163+
return @planar backend = backend allocator = allocator begin
164+
y[-1 -2; -3] ≔ leftenv[-1 -2 4; 1 2] * x[1 2; 3] * rightenv[3 4; -3]
165+
end
166+
end
167+
function _precontracted_ac_derivative(::Bosonic, x, leftenv, rightenv, backend, allocator)
168+
return @tensor backend = backend allocator = allocator begin
169+
y[-1 -2; -3] ≔ leftenv[-1 -2 4; 1 2] * x[1 2; 3] * rightenv[4 3; -3]
170+
end
171+
end
172+
function _precontracted_ac_derivative(::BraidingStyle, x, leftenv, rightenv, backend, allocator)
173+
@planar backend = backend allocator = allocator begin
174+
tmp[-1 -2 -3; -4] := leftenv[-1 -2 -3; 1 2] * x[1 2; -4]
175+
end
176+
tmp2 = braid(tmp, ((1, 2), (3, 4)), (1, 2, 4, 3))
177+
return @planar backend = backend allocator = allocator begin
178+
y[-1 -2; -3] ≔ tmp2[-1 -2; 1 2] * rightenv[1 2; -3]
151179
end
152180
end
153181

154182
function (H::PrecomputedAC2Derivative)(x::MPOTensor)
155-
return @plansor backend = H.backend allocator = H.allocator begin
156-
y[-1 -2; -3 -4] ≔ H.leftenv[-1 -2 5; 1 2] * x[1 2; 3 4] * H.rightenv[3 4 5; -3 -4]
183+
bstyle = BraidingStyle(sectortype(x))
184+
return _precontracted_ac2_derivative(bstyle, x, H.leftenv, H.rightenv, H.backend, H.allocator)
185+
end
186+
187+
function _precontracted_ac2_derivative(::NoBraiding, x, leftenv, rightenv, backend, allocator)
188+
return @planar backend = backend allocator = allocator begin
189+
y[-1 -2; -3 -4] ≔ leftenv[-1 -2 5; 1 2] * x[1 2; 3 4] * rightenv[3 4 5; -3 -4]
190+
end
191+
end
192+
function _precontracted_ac2_derivative(::Bosonic, x, leftenv, rightenv, backend, allocator)
193+
return @tensor backend = backend allocator = allocator begin
194+
y[-1 -2; -3 -4] ≔ leftenv[-1 -2 5; 1 2] * x[1 2; 3 4] * rightenv[5 3 4; -3 -4]
195+
end
196+
end
197+
function _precontracted_ac2_derivative(::BraidingStyle, x, leftenv, rightenv, backend, allocator)
198+
@planar backend = backend allocator = allocator begin
199+
tmp[-1 -2 -3; -4 -5] := leftenv[-1 -2 -3; 1 2] * x[1 2; -4 -5]
200+
end
201+
tmp2 = braid(tmp, ((1, 2), (3, 4, 5)), (1, 2, 5, 3, 4))
202+
return @planar backend = backend allocator = allocator begin
203+
y[-1 -2; -3 -4] := tmp2[-1 -2; 1 2 3] * rightenv[1 2 3; -3 -4]
157204
end
158205
end

0 commit comments

Comments
 (0)