@@ -119,87 +119,112 @@ struct PrecomputedDerivative{
119119 allocator:: A
120120end
121121
122- const PrecomputedACDerivative{T, S} = PrecomputedDerivative{T, S, 3 , 2 , 2 , 1 }
123- const PrecomputedAC2Derivative{T, S} = PrecomputedDerivative{T, S, 3 , 2 , 3 , 2 }
122+ const PrecomputedACDerivative{T, S} = PrecomputedDerivative{T, S, 2 , 1 , 2 , 1 }
124123
125124function prepare_operator!! (
126125 H:: MPO_AC_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPSTensor} ,
127126 x:: MPSTensor ,
128127 backend:: AbstractBackend , allocator
129128 )
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 )))
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
137137
138- return PrecomputedDerivative (leftenv, rightenv, backend, allocator), x
138+ function unprepare_operator!! (y:: MPSBondTensor , :: PrecomputedACDerivative , x:: MPSTensor )
139+ F_left = fuser (scalartype (x), codomain (x)... )
140+ return F_left' * y
139141end
140142
141143function prepare_operator!! (
142144 H:: MPO_AC2_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPOTensor, <:MPSTensor} ,
143145 x:: MPOTensor ,
144146 backend:: AbstractBackend , allocator
145147 )
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
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
155162end
156163
157- function (H:: PrecomputedDerivative )(x:: MPSTensor )
164+ function (H:: PrecomputedDerivative )(x:: MPSBondTensor )
158165 bstyle = BraidingStyle (sectortype (x))
159166 return _precontracted_ac_derivative (bstyle, x, H. leftenv, H. rightenv, H. backend, H. allocator)
160167end
161168
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
167169function _precontracted_ac_derivative (:: Bosonic , x, leftenv, rightenv, backend, allocator)
168170 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 ]
171+ y[- 1 ; - 2 ] ≔ leftenv[- 1 3 ; 1 ] * x[1 ; 2 ] * rightenv[3 2 ; - 2 ]
170172 end
171173end
172174function _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+ 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 ]
175177 end
176- tmp2 = braid (tmp, ((1 , 2 ), (3 , 4 )), (1 , 2 , 4 , 3 ))
178+ end
179+ function _precontracted_ac_derivative (:: NoBraiding , x, leftenv, rightenv, backend, allocator)
177180 return @planar backend = backend allocator = allocator begin
178- y[- 1 - 2 ; - 3 ] ≔ tmp2 [- 1 - 2 ; 1 2 ] * rightenv[1 2 ; - 3 ]
181+ y[- 1 ; - 2 ] ≔ leftenv [- 1 3 ; 1 ] * x[ 1 ; 2 ] * rightenv[2 3 ; - 2 ]
179182 end
180183end
181184
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)
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)
187+ @planar backend = backend allocator = allocator begin
188+ GL_O[- 1 - 2 - 3 ; - 4 - 5 ] := leftenv[- 1 1 ; - 4 ] * operator[1 - 2 ; - 5 - 3 ]
189+ end
190+ 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 ]
192+ end
185193end
186194
187- function _precontracted_ac2_derivative (:: NoBraiding , x, leftenv, rightenv, backend, allocator)
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)
188203 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 ]
204+ rightenv [- 1 - 2 ; - 3 ] := τ [- 1 - 2 ; 1 2 ] * TensorMap (rightenv) [1 2 ; - 3 ]
190205 end
191206end
192- function _precontracted_ac2_derivative (:: Bosonic , x, leftenv, rightenv, backend, allocator)
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
211+ 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 ]
213+ end
214+ end
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
193219 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 ]
220+ rightenv[ - 2 - 1 ; - 3 ] := F [- 1 ; 3 4 ] * TensorMap (O_GR)[ 3 4 - 2 ; 1 2 ] * F ' [ 1 2 ; - 3 ]
195221 end
196222end
197- function _precontracted_ac2_derivative (:: BraidingStyle , x, leftenv, rightenv , backend, allocator)
223+ function _right_precontract_derivative (:: BraidingStyle , rightenv, operator, F , backend, allocator)
198224 @planar backend = backend allocator = allocator begin
199- tmp [- 1 - 2 - 3 ; - 4 - 5 ] := leftenv[ - 1 - 2 - 3 ; 1 2 ] * x[ 1 2 ; - 4 - 5 ]
225+ O_GR [- 1 - 2 - 3 ; - 4 - 5 ] := operator[ - 3 - 5 ; - 2 1 ] * rightenv[ - 1 1 ; - 4 ]
200226 end
201- tmp2 = braid (tmp, ((1 , 2 ), (3 , 4 , 5 )), (1 , 2 , 5 , 3 , 4 ))
202227 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 ]
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 ]
204229 end
205230end
0 commit comments