Skip to content

Commit 6f720f6

Browse files
committed
Precomputed derivatives I
1 parent ed2bda8 commit 6f720f6

File tree

3 files changed

+51
-337
lines changed

3 files changed

+51
-337
lines changed

src/MPSKit.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ include("environments/lazylincocache.jl")
140140
include("algorithms/fixedpoint.jl")
141141
include("algorithms/derivatives/derivatives.jl")
142142
include("algorithms/derivatives/mpo_derivatives.jl")
143-
include("algorithms/derivatives/hamiltonian_derivatives.jl")
144143
include("algorithms/derivatives/projection_derivatives.jl")
145144
include("algorithms/expval.jl")
146145
include("algorithms/toolbox.jl")

src/algorithms/derivatives/hamiltonian_derivatives.jl

Lines changed: 0 additions & 336 deletions
This file was deleted.

src/algorithms/derivatives/mpo_derivatives.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,54 @@ function (h::MPO_AC2_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPOTensor, <:MPSTen
105105
h.operators[2][7 -6; 4 5] * τ[5 -5; 2 3]
106106
return y isa AbstractBlockTensorMap ? only(y) : y
107107
end
108+
109+
# prepared operators
110+
# ------------------
111+
struct PrecomputedDerivative{
112+
T <: Number, S <: ElementarySpace, N₁, N₂, N₃, N₄,
113+
T1 <: AbstractTensorMap{T, S, N₁, N₂}, T2 <: AbstractTensorMap{T, S, N₃, N₄},
114+
B <: AbstractBackend, A,
115+
} <: DerivativeOperator
116+
leftenv::T1
117+
rightenv::T2
118+
backend::B
119+
allocator::A
120+
end
121+
122+
const PrecomputedACDerivative{T, S} = PrecomputedDerivative{T, S, 3, 2, 2, 1}
123+
const PrecomputedAC2Derivative{T, S} = PrecomputedDerivative{T, S, 3, 2, 3, 2}
124+
125+
function prepare_operator!!(
126+
H::MPO_AC_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPSTensor},
127+
x::MPSTensor,
128+
backend::AbstractBackend, allocator
129+
)
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+
return PrecomputedDerivative(TensorMap(GL_O), TensorMap(H.rightenv), backend, allocator), x
134+
end
135+
136+
function prepare_operator!!(
137+
H::MPO_AC2_Hamiltonian{<:MPSTensor, <:MPOTensor, <:MPOTensor, <:MPSTensor},
138+
x::MPOTensor,
139+
backend::AbstractBackend, allocator
140+
)
141+
@plansor backend = backend allocator = allocator begin
142+
GL_O[-1 -2 -3; -4 -5] := H.leftenv[-1 1; -4] * H.operators[1][1 -2; -5 -3]
143+
O_GR[-1 -2 -3; -4 -5] := H.operators[2][-3 -5; -2 1] * H.rightenv[-1 1; -4]
144+
end
145+
return PrecomputedDerivative(TensorMap(GL_O), TensorMap(O_GR), backend, allocator), x
146+
end
147+
148+
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]
151+
end
152+
end
153+
154+
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]
157+
end
158+
end

0 commit comments

Comments
 (0)