Skip to content

Commit 6fc9e7a

Browse files
committed
remove redundanct contracted_C operator and dispatch to the contracted derivates for MPO{<:MPOTensor}
1 parent ade24de commit 6fc9e7a

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/algorithms/derivatives/mpo_derivatives.jl

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
Base.length(H::MPODerivativeOperator) = length(H.operators)
1818
Base.length(::MPOContractedDerivativeOperator{L, R, N}) where {L, R, N} = N
1919

20-
const MPO_C_Hamiltonian{L, R} = MPOContractedDerivativeOperator{L, Tuple{}, R}
20+
const MPO_C_Hamiltonian{L, R} = MPODerivativeOperator{L, Tuple{}, R}
2121
MPO_C_Hamiltonian(GL, GR) = MPODerivativeOperator(GL, (), GR)
2222

2323
const MPO_AC_Hamiltonian{L, O, R} = MPODerivativeOperator{L, Tuple{O}, R}
@@ -26,9 +26,6 @@ MPO_AC_Hamiltonian(GL, O, GR) = MPODerivativeOperator(GL, (O,), GR)
2626
const MPO_AC2_Hamiltonian{L, O₁, O₂, R} = MPODerivativeOperator{L, Tuple{O₁, O₂}, R}
2727
MPO_AC2_Hamiltonian(GL, O1, O2, GR) = MPODerivativeOperator(GL, (O1, O2), GR)
2828

29-
const MPO_Contracted_C_Hamiltonian{L, R} = MPOContractedDerivativeOperator{L, R, 0}
30-
MPO_Contracted_C_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L,R,0}(GL, GR)
31-
3229
const MPO_Contracted_AC_Hamiltonian{L, R} = MPOContractedDerivativeOperator{L, R, 1}
3330
MPO_Contracted_AC_Hamiltonian(GL::L, GR::R) where {L, R} = MPOContractedDerivativeOperator{L,R,1}(GL, GR)
3431

@@ -56,19 +53,16 @@ function AC2_hamiltonian(site::Int, below, operator, above, envs)
5653
leftenv(envs, site, below), O1, O2, rightenv(envs, site + 1, below)
5754
)
5855
end
59-
function C_hamiltonian(site::Int, below::_HAM_MPS_TYPES, operator::MPOHamiltonian{<:MPOTensor}, above::_HAM_MPS_TYPES, envs)
60-
return MPO_Contracted_C_Hamiltonian(leftenv(envs, site + 1, below), rightenv(envs, site, below))
61-
end
62-
function AC_hamiltonian(site::Int, below::_HAM_MPS_TYPES, operator::MPOHamiltonian{<:MPOTensor}, above::_HAM_MPS_TYPES, envs)
56+
function AC_hamiltonian(site::Int, below::_HAM_MPS_TYPES, operator::MPO{<:MPOTensor}, above::_HAM_MPS_TYPES, envs)
6357
O = operator[site]
6458
GL = leftenv(envs, site, below)
6559
return AC_hamiltonian(GL, O, rightenv(envs, site, below))
6660
end
6761
function AC_hamiltonian(GL::MPSTensor, O::MPOTensor, GR::MPSTensor)
6862
@plansor GLW[-1 -2 -3; -4 -5] ≔ GL[-1 1; -4] * O[1 -2; -5 -3]
69-
return MPO_Contracted_AC_Hamiltonian(GLW, O, GR)
63+
return MPO_Contracted_AC_Hamiltonian(GLW, GR)
7064
end
71-
function AC2_hamiltonian(site::Int, below::_HAM_MPS_TYPES, operator::MPOHamiltonian{<:MPOTensor}, above::_HAM_MPS_TYPES, envs)
65+
function AC2_hamiltonian(site::Int, below::_HAM_MPS_TYPES, operator::MPO{<:MPOTensor}, above::_HAM_MPS_TYPES, envs)
7266
O1 = operator[site]
7367
O2 = operator[site + 1]
7468
GL = leftenv(envs, site, below)
@@ -164,12 +158,8 @@ function (h::MPO_AC2_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPOTensor, <:MPSTen
164158
h.operators[2][7 -6; 4 5] * τ[5 -5; 2 3]
165159
return y isa AbstractBlockTensorMap ? only(y) : y
166160
end
167-
function (h::MPO_Contracted_C_Hamiltonian)(x::MPSBondTensor)
168-
@plansor y[-1; -2] ≔ h.leftenv[-1 3; 1] * x[1; 2] * h.rightenv[2 3; -2]
169-
return y isa AbstractBlockTensorMap ? only(y) : y
170-
end
171161
function (h::MPO_Contracted_AC_Hamiltonian)(
172-
x::GenericMPSTensor{<:Any, 3}
162+
x::AbstractTensorMap{<:Any, <:Any, 2, 1}
173163
)
174164
@plansor y[-1 -2; -3] ≔ h.leftenv[-1 -2 3; 1 2] * x[1 2; 4] * h.rightenv[4 3; -3]
175165
return y isa AbstractBlockTensorMap ? only(y) : y
@@ -179,5 +169,4 @@ function (h::MPO_Contracted_AC2_Hamiltonian)(
179169
)
180170
@plansor y[-1 -2; -3 -4] ≔ h.leftenv[-1 -2 5; 1 2] * x[1 2; 3 4] * h.rightenv[3 4 5; -3 -4]
181171
return y isa AbstractBlockTensorMap ? only(y) : y
182-
end
183-
## TODO: Which interface should we use for an inplace += version to be used in hamiltonian_derivatives.jl?
172+
end

0 commit comments

Comments
 (0)