Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/algorithms/toolbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@ function infinite_temperature(ham::MPOHamiltonian)
]
end

"calculates the galerkin error"
"""
calc_galerkin(state, envs)

Calculate the galerkin error.
"""
function calc_galerkin(state::Union{InfiniteMPS,FiniteMPS,WindowMPS}, loc, envs)::Float64
out = ∂∂AC(loc, state, envs.opp, envs) * state.AC[loc]
out -= state.AL[loc] * state.AL[loc]' * out
AC´ = ∂∂AC(loc, state, envs.opp, envs) * state.AC[loc]
normalize!(AC´)
out = add!(AC´, state.AL[loc] * state.AL[loc]' * AC´, -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One less allocation could have been obtained by writing
out = mul!(AC´, state.AL[loc], state.AL[loc]' * AC´, -1, +1)

return norm(out)
end
calc_galerkin(state::Union{InfiniteMPS,FiniteMPS,WindowMPS}, envs)::Float64 =
maximum([calc_galerkin(state, loc, envs) for loc in 1:length(state)])
function calc_galerkin(state::MPSMultiline, envs::PerMPOInfEnv)::Float64
above = isnothing(envs.above) ? state : envs.above

return maximum(
[
norm(
leftnull(state.AC[row + 1, col])' *
(∂∂AC(row, col, state, envs.opp, envs) * above.AC[row, col]),
) for (row, col) in product(1:size(state, 1), 1:size(state, 2))
][:],
)
εs = zeros(Float64, size(state, 1), size(state, 2))
for (row, col) in product(1:size(state, 1), 1:size(state, 2))
AC´ = ∂∂AC(row, col, state, envs.opp, envs) * above.AC[row, col]
normalize!(AC´)
out = add!(AC´, state.AL[row + 1, col] * state.AL[row + 1, col]' * AC´, -1)
εs[row, col] = norm(out)
end

return maximum(εs[:])
end

"
Expand Down