From d34dc24171a74311e24a3ff68401514af9332035 Mon Sep 17 00:00:00 2001 From: Gertian Date: Tue, 15 Oct 2024 22:11:39 +0300 Subject: [PATCH 1/3] made VUMPSSVD parallel as well ! --- src/algorithms/changebonds/vumpssvd.jl | 59 ++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/src/algorithms/changebonds/vumpssvd.jl b/src/algorithms/changebonds/vumpssvd.jl index e0f9c5fcf..fa901bb6a 100644 --- a/src/algorithms/changebonds/vumpssvd.jl +++ b/src/algorithms/changebonds/vumpssvd.jl @@ -41,7 +41,6 @@ function changebonds_1(state::InfiniteMPS, H, alg::VUMPSSvdCut, end function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H)) - meps = 0.0 for loc in 1:length(state) @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3] @@ -58,7 +57,6 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment #svd ac2, get new AL1 and S,V ---> AC (AL1, S, V, eps) = tsvd(nAC2; trunc=alg.trscheme, alg=TensorKit.SVD()) @plansor AC[-1 -2; -3] := S[-1; 1] * V[1; -3 -2] - meps = max(eps, meps) #find AL2 from AC and C as in vumps paper QAC, _ = leftorth(AC; alg=QRpos()) @@ -77,10 +75,65 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment return state, envs end +function changebonds_parallel_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H)) + #prepare the loops we'll have to run over, this is different depending on wether the length of the state is odd or even ! + subsets = nothing + start_locs = nothing + if iseven(length(state)) + subsets = ["even", "odd"] + start_locs = Dict("even" => 1:2:length(state) , "odd" => 2:2:length(state) ) + start_locs + subsets = ["even", "odd", "last"] + start_locs = Dict("even" => 1:2:length(state)-1, "odd" => 2:2:length(state)-1, "last" => length(state)) + end + + for subset in subsets + new_ALs = similar(state.AL) + @sync for loc in start_locs[subset] + Threads.@spawn begin + @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3] + + h_ac2 = ∂∂AC2(loc, state, H, envs) + (vals, vecs, _) = eigsolve(h_ac2, AC2, 1, :SR; tol=alg.tol_eigenval, + ishermitian=false) + nAC2 = vecs[1] + + h_c = ∂∂C(loc + 1, state, H, envs) + (vals, vecs, _) = eigsolve(h_c, state.CR[loc + 1], 1, :SR; tol=alg.tol_eigenval, + ishermitian=false) + nC2 = vecs[1] + + #svd ac2, get new AL1 and S,V ---> AC + (AL1, S, V, eps) = tsvd(nAC2; trunc=alg.trscheme, alg=TensorKit.SVD()) + @plansor AC[-1 -2; -3] := S[-1; 1] * V[1; -3 -2] + + #find AL2 from AC and C as in vumps paper + QAC, _ = leftorth(AC; alg=QRpos()) + QC, _ = leftorth(nC2; alg=QRpos()) + dom_map = isometry(domain(QC), domain(QAC)) + + @plansor AL2[-1 -2; -3] := QAC[-1 -2; 1] * conj(dom_map[2; 1]) * conj(QC[-3; 2]) + + #make a new state using the updated A's + new_ALs[loc] = AL1 + new_ALs[loc + 1] = AL2 + end + end + state = InfiniteMPS(new_ALs; tol=alg.tol_gauge) + end + return state, envs +end + function changebonds(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H)) if (length(state) == 1) return changebonds_1(state, H, alg, envs) else - return changebonds_n(state, H, alg, envs) + @static if Defaults.parallelize_sites + return changebonds_parallel_n(state, H, alg, envs) + else + return changebonds_n(state, H, alg, envs) + end end end + + From 8ffa04f28b7a0fecf400ba5a69bc956de159891d Mon Sep 17 00:00:00 2001 From: Gertian Date: Tue, 15 Oct 2024 23:45:04 +0300 Subject: [PATCH 2/3] fixed typo --- src/algorithms/changebonds/vumpssvd.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/algorithms/changebonds/vumpssvd.jl b/src/algorithms/changebonds/vumpssvd.jl index fa901bb6a..178dae68e 100644 --- a/src/algorithms/changebonds/vumpssvd.jl +++ b/src/algorithms/changebonds/vumpssvd.jl @@ -41,6 +41,7 @@ function changebonds_1(state::InfiniteMPS, H, alg::VUMPSSvdCut, end function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H)) + meps = 0.0 for loc in 1:length(state) @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3] @@ -57,6 +58,7 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment #svd ac2, get new AL1 and S,V ---> AC (AL1, S, V, eps) = tsvd(nAC2; trunc=alg.trscheme, alg=TensorKit.SVD()) @plansor AC[-1 -2; -3] := S[-1; 1] * V[1; -3 -2] + meps = max(eps, meps) #find AL2 from AC and C as in vumps paper QAC, _ = leftorth(AC; alg=QRpos()) @@ -82,13 +84,13 @@ function changebonds_parallel_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=en if iseven(length(state)) subsets = ["even", "odd"] start_locs = Dict("even" => 1:2:length(state) , "odd" => 2:2:length(state) ) - start_locs + else subsets = ["even", "odd", "last"] start_locs = Dict("even" => 1:2:length(state)-1, "odd" => 2:2:length(state)-1, "last" => length(state)) end for subset in subsets - new_ALs = similar(state.AL) + new_ALs = copy(state.AL) @sync for loc in start_locs[subset] Threads.@spawn begin @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3] @@ -135,5 +137,3 @@ function changebonds(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments( end end end - - From b9e7acdefe0f01e6bf33a4c3f0e86ae2e5d24c76 Mon Sep 17 00:00:00 2001 From: Gertian Date: Tue, 15 Oct 2024 23:53:48 +0300 Subject: [PATCH 3/3] formatted lol... --- src/algorithms/changebonds/vumpssvd.jl | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/algorithms/changebonds/vumpssvd.jl b/src/algorithms/changebonds/vumpssvd.jl index 178dae68e..2582d201d 100644 --- a/src/algorithms/changebonds/vumpssvd.jl +++ b/src/algorithms/changebonds/vumpssvd.jl @@ -77,32 +77,36 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment return state, envs end -function changebonds_parallel_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environments(state, H)) +function changebonds_parallel_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, + envs=environments(state, H)) #prepare the loops we'll have to run over, this is different depending on wether the length of the state is odd or even ! subsets = nothing start_locs = nothing if iseven(length(state)) subsets = ["even", "odd"] - start_locs = Dict("even" => 1:2:length(state) , "odd" => 2:2:length(state) ) + start_locs = Dict("even" => 1:2:length(state), "odd" => 2:2:length(state)) else subsets = ["even", "odd", "last"] - start_locs = Dict("even" => 1:2:length(state)-1, "odd" => 2:2:length(state)-1, "last" => length(state)) + start_locs = Dict("even" => 1:2:(length(state) - 1), + "odd" => 2:2:(length(state) - 1), "last" => length(state)) end for subset in subsets new_ALs = copy(state.AL) @sync for loc in start_locs[subset] Threads.@spawn begin - @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3] + @plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * + state.AR[loc + 1][1 -4; -3] h_ac2 = ∂∂AC2(loc, state, H, envs) (vals, vecs, _) = eigsolve(h_ac2, AC2, 1, :SR; tol=alg.tol_eigenval, - ishermitian=false) + ishermitian=false) nAC2 = vecs[1] h_c = ∂∂C(loc + 1, state, H, envs) - (vals, vecs, _) = eigsolve(h_c, state.CR[loc + 1], 1, :SR; tol=alg.tol_eigenval, - ishermitian=false) + (vals, vecs, _) = eigsolve(h_c, state.CR[loc + 1], 1, :SR; + tol=alg.tol_eigenval, + ishermitian=false) nC2 = vecs[1] #svd ac2, get new AL1 and S,V ---> AC @@ -114,7 +118,8 @@ function changebonds_parallel_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=en QC, _ = leftorth(nC2; alg=QRpos()) dom_map = isometry(domain(QC), domain(QAC)) - @plansor AL2[-1 -2; -3] := QAC[-1 -2; 1] * conj(dom_map[2; 1]) * conj(QC[-3; 2]) + @plansor AL2[-1 -2; -3] := QAC[-1 -2; 1] * conj(dom_map[2; 1]) * + conj(QC[-3; 2]) #make a new state using the updated A's new_ALs[loc] = AL1