Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Oct 3, 2023
1 parent 374b961 commit cba9424
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/algorithms/groundstate/vumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,45 @@ end
"

function find_groundstate::InfiniteMPS, H, alg::VUMPS, envs=environments(Ψ, H))
galerkin::Float64 = 1 + alg.tol_galerkin
iter = 1
ε::Float64 = 1 + alg.tol_galerkin

temp_ACs = similar.(Ψ.AC)

while true
eigalg = Arnoldi(; tol=galerkin / (4 * sqrt(iter)))
for iter in 1:(alg.maxiter)
Δt = @elapsed begin
eigalg = Arnoldi(; tol=ε / (4 * sqrt(iter)))

@static if Defaults.parallelize_sites
@sync begin
for loc in 1:length(Ψ)
Threads.@spawn begin
_vumps_localupdate!(temp_ACs[loc], loc, Ψ, H, envs, eigalg)
@static if Defaults.parallelize_sites
@sync begin
for loc in 1:length(Ψ)
Threads.@spawn begin
_vumps_localupdate!(temp_ACs[loc], loc, Ψ, H, envs, eigalg)
end
end
end
else
for loc in 1:length(Ψ)
_vumps_localupdate!(temp_ACs[loc], loc, Ψ, H, envs, eigalg)
end
end
else
for loc in 1:length(Ψ)
_vumps_localupdate!(temp_ACs[loc], loc, Ψ, H, envs, eigalg)
end
end

Ψ = InfiniteMPS(temp_ACs, Ψ.CR[end]; tol=alg.tol_gauge, maxiter=alg.orthmaxiter)
recalculate!(envs, Ψ)

Ψ, envs = alg.finalize(iter, Ψ, H, envs)::Tuple{typeof(Ψ),typeof(envs)}
Ψ = InfiniteMPS(temp_ACs, Ψ.CR[end]; tol=alg.tol_gauge, maxiter=alg.orthmaxiter)
recalculate!(envs, Ψ)

galerkin = calc_galerkin(Ψ, envs)
alg.verbose && @info "vumps @iteration $(iter) galerkin = $(galerkin)"
Ψ, envs = alg.finalize(iter, Ψ, H, envs)::Tuple{typeof(Ψ),typeof(envs)}

if galerkin <= alg.tol_galerkin || iter >= alg.maxiter
iter >= alg.maxiter && @warn "vumps didn't converge $(galerkin)"
return Ψ, envs, galerkin
ε = calc_galerkin(Ψ, envs)
end

iter += 1
alg.verbose &&
@info "VUMPS iteration:" iter ε λ = sum(expectation_value(Ψ, H, envs)) Δt

ε <= alg.tol_galerkin && break
iter == alg.maxiter &&
@warn "VUMPS maximum iterations" iter ε λ = sum(expectation_value(Ψ, H, envs)) Δt
end

return Ψ, envs, ε
end

function _vumps_localupdate!(AC′, loc, Ψ, H, envs, eigalg, factalg=QRpos())
Expand Down

0 comments on commit cba9424

Please sign in to comment.