@@ -119,112 +119,87 @@ struct PrecomputedDerivative{
119119 allocator:: A
120120end
121121
122- const PrecomputedACDerivative{T, S} = PrecomputedDerivative{T, S, 2 , 1 , 2 , 1 }
122+ const PrecomputedACDerivative{T, S} = PrecomputedDerivative{T, S, 3 , 2 , 2 , 1 }
123+ const PrecomputedAC2Derivative{T, S} = PrecomputedDerivative{T, S, 3 , 2 , 3 , 2 }
123124
124125function prepare_operator!! (
125126 H:: MPO_AC_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPSTensor} ,
126127 x:: MPSTensor ,
127128 backend:: AbstractBackend , allocator
128129 )
129- F_left = fuser (scalartype (x), codomain (x)... )
130- x′ = F_left * x
131-
132- leftenv = left_precontract_derivative (H. leftenv, H. operators[1 ], F_left, backend, allocator)
133- rightenv = right_precontract_derivative (H. rightenv, backend, allocator)
134-
135- return PrecomputedDerivative (leftenv, rightenv, backend, allocator), x′
136- end
130+ @plansor backend = backend allocator = allocator begin
131+ GL_O[- 1 - 2 - 3 ; - 4 - 5 ] := H. leftenv[- 1 1 ; - 4 ] * H. operators[1 ][1 - 2 ; - 5 - 3 ]
132+ end
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 )))
137137
138- function unprepare_operator!! (y:: MPSBondTensor , :: PrecomputedACDerivative , x:: MPSTensor )
139- F_left = fuser (scalartype (x), codomain (x)... )
140- return F_left' * y
138+ return PrecomputedDerivative (leftenv, rightenv, backend, allocator), x
141139end
142140
143141function prepare_operator!! (
144142 H:: MPO_AC2_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPOTensor, <:MPSTensor} ,
145143 x:: MPOTensor ,
146144 backend:: AbstractBackend , allocator
147145 )
148- F_left = fuser (scalartype (x), codomain (x)... )
149- F_right = fuser (scalartype (x), domain (x)... )
150- x′ = F_left * x * F_right'
151-
152- leftenv = left_precontract_derivative (H. leftenv, H. operators[1 ], F_left, backend, allocator)
153- rightenv = right_precontract_derivative (H. rightenv, H. operators[2 ], F_right, backend, allocator)
154-
155- return PrecomputedDerivative (leftenv, rightenv, backend, allocator), x′
156- end
157-
158- function unprepare_operator!! (y:: MPSBondTensor , :: PrecomputedDerivative , x:: MPOTensor )
159- F_left = fuser (scalartype (x), codomain (x)... )
160- F_right = fuser (scalartype (x), domain (x)... )
161- return F_left' * y * F_right
146+ @plansor backend = backend allocator = allocator begin
147+ GL_O[- 1 - 2 - 3 ; - 4 - 5 ] := H. leftenv[- 1 1 ; - 4 ] * H. operators[1 ][1 - 2 ; - 5 - 3 ]
148+ O_GR[- 1 - 2 - 3 ; - 4 - 5 ] := H. operators[2 ][- 3 - 5 ; - 2 1 ] * H. rightenv[- 1 1 ; - 4 ]
149+ end
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
162155end
163156
164- function (H:: PrecomputedDerivative )(x:: MPSBondTensor )
157+ function (H:: PrecomputedDerivative )(x:: MPSTensor )
165158 bstyle = BraidingStyle (sectortype (x))
166159 return _precontracted_ac_derivative (bstyle, x, H. leftenv, H. rightenv, H. backend, H. allocator)
167160end
168161
169- function _precontracted_ac_derivative (:: Bosonic , x, leftenv, rightenv, backend, allocator)
170- return @tensor backend = backend allocator = allocator begin
171- y[- 1 ; - 2 ] ≔ leftenv[- 1 3 ; 1 ] * x[1 ; 2 ] * rightenv[3 2 ; - 2 ]
172- end
173- end
174- function _precontracted_ac_derivative (:: BraidingStyle , x, leftenv, rightenv, backend, allocator)
162+ function _precontracted_ac_derivative (:: NoBraiding , x, leftenv, rightenv, backend, allocator)
175163 return @planar backend = backend allocator = allocator begin
176- y[- 1 ; - 2 ] := leftenv[- 1 2 ; 1 ] * x[1 ; 3 ] * τ ' [ 3 2 ; 4 5 ] * rightenv[4 5 ; - 2 ]
164+ y[- 1 - 2 ; - 3 ] ≔ leftenv[- 1 - 2 4 ; 1 2 ] * x[1 2 ; 3 ] * rightenv[3 4 ; - 3 ]
177165 end
178166end
179- function _precontracted_ac_derivative (:: NoBraiding , x, leftenv, rightenv, backend, allocator)
180- return @planar backend = backend allocator = allocator begin
181- y[- 1 ; - 2 ] ≔ leftenv[- 1 3 ; 1 ] * x[1 ; 2 ] * rightenv[2 3 ; - 2 ]
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 ]
182170 end
183171end
184-
185- left_precontract_derivative (arg, args... ) = _left_precontract_derivative (BraidingStyle (sectortype (arg)), arg, args... )
186- function _left_precontract_derivative (:: BraidingStyle , leftenv, operator, F, backend, allocator)
172+ function _precontracted_ac_derivative (:: BraidingStyle , x, leftenv, rightenv, backend, allocator)
187173 @planar backend = backend allocator = allocator begin
188- GL_O [- 1 - 2 - 3 ; - 4 - 5 ] := leftenv[- 1 1 ; - 4 ] * operator [1 - 2 ; - 5 - 3 ]
174+ tmp [- 1 - 2 - 3 ; - 4 ] := leftenv[- 1 - 2 - 3 ; 1 2 ] * x [1 2 ; - 4 ]
189175 end
176+ tmp2 = braid (tmp, ((1 , 2 ), (3 , 4 )), (1 , 2 , 4 , 3 ))
190177 return @planar backend = backend allocator = allocator begin
191- leftenv [- 1 - 2 ; - 3 ] := F [- 1 ; 3 4 ] * TensorMap (GL_O)[ 3 4 - 2 ; 1 2 ] * F ' [1 2 ; - 3 ]
178+ y [- 1 - 2 ; - 3 ] ≔ tmp2 [- 1 - 2 ; 1 2 ] * rightenv [1 2 ; - 3 ]
192179 end
193180end
194181
195- right_precontract_derivative (arg, args... ) = _right_precontract_derivative (BraidingStyle (sectortype (arg)), arg, args... )
196- _right_precontract_derivative (:: NoBraiding , rightenv, backend, allocator) = TensorMap (rightenv)
197- function _right_precontract_derivative (:: Bosonic , rightenv, backend, allocator)
198- return @tensor backend = backend allocator = allocator begin
199- rightenv[- 2 - 1 ; - 3 ] := TensorMap (rightenv)[- 1 - 2 ; - 3 ]
200- end
201- end
202- function _right_precontract_derivative (:: BraidingStyle , rightenv, backend, allocator)
203- return @planar backend = backend allocator = allocator begin
204- rightenv[- 1 - 2 ; - 3 ] := τ[- 1 - 2 ; 1 2 ] * TensorMap (rightenv)[1 2 ; - 3 ]
205- end
182+ function (H:: PrecomputedAC2Derivative )(x:: MPOTensor )
183+ bstyle = BraidingStyle (sectortype (x))
184+ return _precontracted_ac2_derivative (bstyle, x, H. leftenv, H. rightenv, H. backend, H. allocator)
206185end
207- function _right_precontract_derivative (:: NoBraiding , rightenv, operator, F, backend, allocator)
208- @planar backend = backend allocator = allocator begin
209- O_GR[- 1 - 2 - 3 ; - 4 - 5 ] := operator[- 3 - 5 ; - 2 1 ] * rightenv[- 1 1 ; - 4 ]
210- end
186+
187+ function _precontracted_ac2_derivative (:: NoBraiding , x, leftenv, rightenv, backend, allocator)
211188 return @planar backend = backend allocator = allocator begin
212- rightenv [- 1 - 2 ; - 3 ] := F [- 1 ; 3 4 ] * TensorMap (O_GR)[ 3 4 - 2 ; 1 2 ] * F ' [ 1 2 ; - 3 ]
189+ y [- 1 - 2 ; - 3 - 4 ] ≔ leftenv [- 1 - 2 5 ; 1 2 ] * x[ 1 2 ; 3 4 ] * rightenv[ 3 4 5 ; - 3 - 4 ]
213190 end
214191end
215- function _right_precontract_derivative (:: Bosonic , rightenv, operator, F, backend, allocator)
216- @tensor backend = backend allocator = allocator begin
217- O_GR[- 1 - 2 - 3 ; - 4 - 5 ] := operator[- 3 - 5 ; - 2 1 ] * rightenv[- 1 1 ; - 4 ]
218- end
192+ function _precontracted_ac2_derivative (:: Bosonic , x, leftenv, rightenv, backend, allocator)
219193 return @tensor backend = backend allocator = allocator begin
220- rightenv[ - 2 - 1 ; - 3 ] := F [- 1 ; 3 4 ] * TensorMap (O_GR)[ 3 4 - 2 ; 1 2 ] * F ' [ 1 2 ; - 3 ]
194+ y[ - 1 - 2 ; - 3 - 4 ] ≔ leftenv [- 1 - 2 5 ; 1 2 ] * x[ 1 2 ; 3 4 ] * rightenv[ 5 3 4 ; - 3 - 4 ]
221195 end
222196end
223- function _right_precontract_derivative (:: BraidingStyle , rightenv, operator, F , backend, allocator)
197+ function _precontracted_ac2_derivative (:: BraidingStyle , x, leftenv, rightenv , backend, allocator)
224198 @planar backend = backend allocator = allocator begin
225- O_GR [- 1 - 2 - 3 ; - 4 - 5 ] := operator[ - 3 - 5 ; - 2 1 ] * rightenv[ - 1 1 ; - 4 ]
199+ tmp [- 1 - 2 - 3 ; - 4 - 5 ] := leftenv[ - 1 - 2 - 3 ; 1 2 ] * x[ 1 2 ; - 4 - 5 ]
226200 end
201+ tmp2 = braid (tmp, ((1 , 2 ), (3 , 4 , 5 )), (1 , 2 , 5 , 3 , 4 ))
227202 return @planar backend = backend allocator = allocator begin
228- rightenv [- 1 - 2 ; - 3 ] := τ [- 1 - 2 ; 5 6 ] * F[ 5 ; 3 4 ] * TensorMap (O_GR)[ 3 4 6 ; 1 2 ] * F ' [ 1 2 ; - 3 ]
203+ y [- 1 - 2 ; - 3 - 4 ] := tmp2 [- 1 - 2 ; 1 2 3 ] * rightenv[ 1 2 3 ; - 3 - 4 ]
229204 end
230205end
0 commit comments