@@ -134,52 +134,84 @@ function MPSKit.contract_mpo_expval(
134134 return environment_overlap (GL´, GR)
135135end
136136
137+ # PEPS Derivative contractions
138+ # ----------------------------
139+ # This is appropriating the MPSKit MPO derivative structures, which might not be the best
140+ # idea in the long run.
141+
142+ const PEPS_C_Hamiltonian{S,N} = MPSKit. MPO_C_Hamiltonian{
143+ <: GenericMPSTensor{S,N} ,<: GenericMPSTensor{S,N}
144+ } # this one is technically type-piracy
145+ PEPS_C_Hamiltonian (GL, GR) = MPSKit. MPODerivativeOperator (GL, (), GR)
146+
147+ const PEPS_AC_Hamiltonian{S,N} = MPSKit. MPO_AC_Hamiltonian{
148+ <: GenericMPSTensor{S,N} ,<: PEPSSandwich ,<: GenericMPSTensor{S,N}
149+ }
150+ PEPS_AC_Hamiltonian (GL, O, GR) = MPSKit. MPODerivativeOperator (GL, (O,), GR)
151+
152+ const PEPS_AC2_Hamiltonian{S,N} = MPSKit. MPO_AC2_Hamiltonian{
153+ <: GenericMPSTensor{S,N} ,<: PEPSSandwich ,<: PEPSSandwich ,<: GenericMPSTensor{S,N}
154+ }
155+ PEPS_AC2_Hamiltonian (GL, O1, O2, GR) = MPSKit. MPODerivativeOperator (GL, (O1, O2), GR)
156+
157+ # Constructors
137158#
138- # Derivative contractions
139- #
140-
141- function MPSKit. ∂C (
142- C:: MPSBondTensor{S} , GL:: GenericMPSTensor{S,N} , GR:: GenericMPSTensor{S,N}
143- ) where {S,N}
159+ function MPSKit. C_hamiltonian (site:: Int , below, :: InfiniteTransferMatrix , above, envs)
160+ GL = leftenv (envs, site + 1 , below)
144161 GL = twistdual (GL, 1 )
162+ GR = rightenv (envs, site, below)
145163 GR = twistdual (GR, numind (GR))
146- return _∂C (C, GL, GR)
164+ return PEPS_C_Hamiltonian ( GL, GR)
147165end
148- @generated function _∂C (
149- C:: MPSBondTensor{S} , GL:: GenericMPSTensor{S,N} , GR:: GenericMPSTensor{S,N}
150- ) where {S,N}
151- C´_e = tensorexpr (:C´ , - 1 , - 2 )
152- C_e = tensorexpr (:C , 1 , 2 )
153- GL_e = tensorexpr (:GL , (- 1 , (3 : (N + 1 )). .. ), 1 )
154- GR_e = tensorexpr (:GR , 2 : (N + 1 ), - 2 )
155- return macroexpand (@__MODULE__ , :(return @tensor $ C´_e := $ GL_e * $ C_e * $ GR_e))
166+
167+ function MPSKit. AC_hamiltonian (
168+ site:: Int , below, operator:: InfiniteTransferPEPS , above, envs
169+ )
170+ GL = leftenv (envs, site, below)
171+ GL = twistdual (GL, 1 )
172+ GR = rightenv (envs, site, below)
173+ GR = twistdual (GR, numind (GR))
174+ return PEPS_AC_Hamiltonian (GL, operator[site], GR)
156175end
157176
158- function MPSKit. ∂AC (
159- AC:: GenericMPSTensor{S,N} ,
160- O:: Union{PEPSSandwich,PEPOSandwich} ,
161- GL:: GenericMPSTensor{S,N} ,
162- GR:: GenericMPSTensor{S,N} ,
163- ) where {S,N}
177+ function MPSKit. AC2_hamiltonian (
178+ site:: Int , below, operator:: InfiniteTransferPEPS , above, envs
179+ )
180+ GL = leftenv (envs, site, below)
164181 GL = twistdual (GL, 1 )
182+ GR = rightenv (envs, site + 1 , below)
165183 GR = twistdual (GR, numind (GR))
166- return _∂AC (AC, O, GL , GR)
184+ return PEPS_AC2_Hamiltonian (GL, operator[site], operator[site + 1 ] , GR)
167185end
168186
169- # # PEPS
187+ # Actions
188+ #
189+ @generated function (h:: PEPS_C_Hamiltonian{S,N} )(C:: MPSBondTensor{S} ) where {S,N}
190+ C´_e = tensorexpr (:C´ , - 1 , - 2 )
191+ C_e = tensorexpr (:C , 1 , 2 )
192+ GL_e = tensorexpr (:(h. leftenv), (- 1 , (3 : (N + 1 )). .. ), 1 )
193+ GR_e = tensorexpr (:(h. rightenv), (2 : (N + 1 ). .. ,), - 2 )
194+ return macroexpand (@__MODULE__ , :(return @tensor $ C´_e := $ GL_e * $ C_e * $ GR_e))
195+ end
170196
171- function _∂AC (
172- AC:: GenericMPSTensor{S,3} ,
173- O:: PEPSSandwich ,
174- GL:: GenericMPSTensor{S,3} ,
175- GR:: GenericMPSTensor{S,3} ,
176- ) where {S}
197+ function (h:: PEPS_AC_Hamiltonian{S,N} )(AC:: GenericMPSTensor{S,N} ) where {S,N}
177198 return @autoopt @tensor AC′[χ_SW D_S_above D_S_below; χ_SE] :=
178- GL [χ_SW D_W_above D_W_below; χ_NW] *
199+ h . leftenv [χ_SW D_W_above D_W_below; χ_NW] *
179200 AC[χ_NW D_N_above D_N_below; χ_NE] *
180- GR[χ_NE D_E_above D_E_below; χ_SE] *
181- ket (O)[d; D_N_above D_E_above D_S_above D_W_above] *
182- conj (bra (O)[d; D_N_below D_E_below D_S_below D_W_below])
201+ h. rightenv[χ_NE D_E_above D_E_below; χ_SE] *
202+ ket (h. operators[1 ])[d; D_N_above D_E_above D_S_above D_W_above] *
203+ conj (bra (h. operators[1 ])[d; D_N_below D_E_below D_S_below D_W_below])
204+ end
205+
206+ function (h:: PEPS_AC2_Hamiltonian{S,3} )(AC2:: AbstractTensorMap{<:Any,S,3,3} ) where {S}
207+ return @autoopt @tensor AC2′[χ_SW D_S_above1 D_S_below1; χ_SE D_S_below2 D_S_above2] :=
208+ h. leftenv[χ_SW D_W_above1 D_W_below1; χ_NW] *
209+ AC2[χ_NW D_N_above1 D_N_below1; χ_NE D_N_below2 D_N_above2] *
210+ h. rightenv[χ_NE D_E_above2 D_E_below2; χ_SE] *
211+ ket (h. operators[1 ])[d1; D_N_above1 D_E_above1 D_S_above1 D_W_above1] *
212+ conj (bra (h. operators[1 ])[d1; D_N_below1 D_E_below1 D_S_below1 D_W_below1]) *
213+ ket (h. operators[2 ])[d2; D_N_above2 D_E_above2 D_S_above2 D_E_above1] *
214+ conj (bra (h. operators[2 ])[d2; D_N_below2 D_E_below2 D_S_below2 D_E_below1])
183215end
184216
185217# PEPS derivative
@@ -198,22 +230,32 @@ function ∂peps(
198230 conj (ĀC[χ_SW D_S_above D_S_below; χ_SE])
199231end
200232
201- # # PEPO
233+ # PEPO Derivative contractions
234+ # ----------------------------
235+ const PEPO_AC_Hamiltonian{S,N,H} = MPSKit. MPO_AC_Hamiltonian{
236+ <: GenericMPSTensor{S,N} ,<: PEPOSandwich{H} ,<: GenericMPSTensor{S,N}
237+ }
238+ PEPO_AC_Hamiltonian (GL, O, GR) = MPSKit. MPODerivativeOperator (GL, (O,), GR)
239+
240+ function MPSKit. AC_hamiltonian (
241+ site:: Int , below, operator:: InfiniteTransferPEPO , above, envs
242+ )
243+ GL = leftenv (envs, site, below)
244+ GL = twistdual (GL, 1 )
245+ GR = rightenv (envs, site, below)
246+ GR = twistdual (GR, numind (GR))
247+ return PEPO_AC_Hamiltonian (GL, operator[site], GR)
248+ end
202249
203- @generated function _∂AC (
204- AC:: GenericMPSTensor{S,N} ,
205- O:: PEPOSandwich{H} ,
206- GL:: GenericMPSTensor{S,N} ,
207- GR:: GenericMPSTensor{S,N} ,
208- ) where {S,N,H}
250+ @generated function (h:: PEPO_AC_Hamiltonian{S,N,H} )(AC:: GenericMPSTensor{S,N} ) where {S,N,H}
209251 # sanity check
210- @assert H == N - 3
252+ @assert H == N - 3 " Incompatible number of legs and layers "
211253
212254 AC´_e = _pepo_edge_expr (:AC´ , :SW , :SE , :S , H)
213255 AC_e = _pepo_edge_expr (:AC , :NW , :NE , :N , H)
214- GL_e = _pepo_edge_expr (:GL , :SW , :NW , :W , H)
215- GR_e = _pepo_edge_expr (:GR , :NE , :SE , :E , H)
216- ket_e, bra_e, pepo_es = _pepo_sandwich_expr (:O , H)
256+ GL_e = _pepo_edge_expr (:(h . leftenv) , :SW , :NW , :W , H)
257+ GR_e = _pepo_edge_expr (:(h . rightenv) , :NE , :SE , :E , H)
258+ ket_e, bra_e, pepo_es = _pepo_sandwich_expr (:(h . operators[ 1 ]) , H)
217259
218260 rhs = Expr (:call , :* , AC_e, GL_e, GR_e, ket_e, Expr (:call , :conj , bra_e), pepo_es... )
219261
0 commit comments