Skip to content

Commit

Permalink
Improve CTMRG error computation (QuantumKitHub#65)
Browse files Browse the repository at this point in the history
* Add non-fixedspace error calculation

* Refactor error calculation
  • Loading branch information
lkdvos authored Aug 29, 2024
1 parent 76e25d9 commit ab0d215
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/algorithms/ctmrg/gaugefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,32 @@ function fix_global_phases(envprev::CTMRGEnv, envfix::CTMRGEnv)
return CTMRGEnv(cornersgfix, edgesgfix)
end

#=
In order to compute an error measure, we compare the singular values of the current iteration with the previous one.
However, when the virtual spaces change, this comparison is not directly possible.
Instead, we project both tensors into the smaller space and then compare the difference.
TODO: we might want to consider embedding the smaller tensor into the larger space and then compute the difference
=#
function _singular_value_distance((S₁, S₂))
V₁ = space(S₁, 1)
V₂ = space(S₂, 1)
if V₁ == V₂
return norm(S₁ - S₂)
else
V = infimum(V₁, V₂)
e1 = isometry(V₁, V)
e2 = isometry(V₂, V)
return norm(e1' * S₁ * e1 - e2' * S₂ * e2)
end
end

function calc_convergence(envs, CSold, TSold)
CSnew = map(x -> tsvd(x; alg=TensorKit.SVD())[2], envs.corners)
ΔCS = maximum(zip(CSold, CSnew)) do (c_old, c_new)
# only compute the difference on the smallest part of the spaces
smallest = infimum(MPSKit._firstspace(c_old), MPSKit._firstspace(c_new))
e_old = isometry(MPSKit._firstspace(c_old), smallest)
e_new = isometry(MPSKit._firstspace(c_new), smallest)
return norm(e_new' * c_new * e_new - e_old' * c_old * e_old)
end
ΔCS = maximum(_singular_value_distance, zip(CSold, CSnew))

TSnew = map(x -> tsvd(x; alg=TensorKit.SVD())[2], envs.edges)
ΔTS = maximum(zip(TSold, TSnew)) do (t_old, t_new)
MPSKit._firstspace(t_old) == MPSKit._firstspace(t_new) ||
return scalartype(t_old)(Inf)
return norm(t_new - t_old)
end
ΔTS = maximum(_singular_value_distance, zip(TSold, TSnew))

@debug "maxᵢ|Cⁿ⁺¹ - Cⁿ|ᵢ = $ΔCS maxᵢ|Tⁿ⁺¹ - Tⁿ|ᵢ = $ΔTS"

Expand Down

0 comments on commit ab0d215

Please sign in to comment.