Skip to content

Commit

Permalink
Replace QR leftorth with tsvd to fix gauge_fix AD
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrehmer committed Apr 3, 2024
1 parent 714c7f4 commit 15687b1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/algorithms/ctmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,23 @@ function gauge_fix(envprev::CTMRGEnv{C,T}, envfinal::CTMRGEnv{C,T}) where {C,T}
end

# Find right fixed points of mixed transfer matrices
rhoinit = TensorMap(
ρinit = TensorMap(
randn,
scalartype(T),
MPSKit._lastspace(Tsfinal[end])' MPSKit._lastspace(M[end])',
)

rhoprev = eigsolve(TransferMatrix(Tsprev, M), rhoinit, 1, :LM)[2][1]
rhofinal = eigsolve(TransferMatrix(Tsfinal, M), rhoinit, 1, :LM)[2][1]
# rhoprev = @showgrad rhoprev
ρprev = eigsolve(TransferMatrix(Tsprev, M), ρinit, 1, :LM)[2][1]
ρfinal = eigsolve(TransferMatrix(Tsfinal, M), ρinit, 1, :LM)[2][1]

# Decompose and multiply
Qprev, = leftorth(rhoprev, ((1,), (2,)))
Qfinal, = leftorth(rhofinal, ((1,), (2,)))
σ = @checkgrad Qprev * Qfinal'
# σ = Qprev * Qfinal'
# Qprev, = leftorth(ρprev, ((1,), (2,))) # QR decomposition leads to diverging gradients?
# Qfinal, = leftorth(ρfinal, ((1,), (2,)))
# σ = @checkgrad Qprev * Qfinal'
Up, _, Vp = tsvd(ρprev)
Uf, _, Vf = tsvd(ρfinal)
Qprev = Up * Vp
Qfinal = Uf * Vf
σ = Qprev * Qfinal'

return σ
end
Expand Down

0 comments on commit 15687b1

Please sign in to comment.