From 4e50b83e80460dbd23a8e329b2686cc5fd5d351f Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 12 Jun 2024 14:36:55 +0200 Subject: [PATCH 1/9] Change lazysum tests to improve stability --- test/algorithms.jl | 54 ++++++++++++++++++++++++---------------------- test/setup.jl | 32 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index 9643538b..92499abb 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -157,17 +157,18 @@ end @testset "LazySum FiniteMPS groundstate" verbose = true begin tol = 1e-8 - D = 20 + D = 15 + atol = 1e-2 - local_operators = [TensorMap(randn, ComplexF64, ℙ^2 ⊗ ℙ^2 ← ℙ^2 ⊗ ℙ^2) for i in 1:3] - local_operators .+= adjoint.(local_operators) + # test using XXZ model, Δ > 1 is gapped + local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) H = sum(H_lazy) @testset "DMRG" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℙ^2, ℙ^D) + ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, @@ -175,14 +176,14 @@ end # compare states alg = DMRG(; tol, verbosity=1) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "DMRG2" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℙ^2, ℙ^D) + ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) # test logging passes trscheme = truncdim(12) @@ -191,14 +192,14 @@ end # compare states alg = DMRG2(; tol, verbosity=1, trscheme) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℙ^2, ℙ^D) + ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, @@ -206,58 +207,59 @@ end # compare states alg = GradientGrassmann(; tol, verbosity=1) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end end @testset "LazySum InfiniteMPS groundstate" verbose = true begin tol = 1e-8 - D = 6 + D = 15 + atol = 1e-2 - local_operators = [TensorMap(randn, ComplexF64, ℙ^2 ⊗ ℙ^2 ← ℙ^2 ⊗ ℙ^2) for i in 1:3] - local_operators .+= adjoint.(local_operators) + # test using XXZ model, Δ > 1 is gapped + local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) H = sum(H_lazy) @testset "VUMPS" begin - ψ₀ = InfiniteMPS(ℙ^2, ℙ^D) + ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, VUMPS(; tol, verbosity=5, maxiter=2)) # compare states alg = VUMPS(; tol, verbosity=1) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG1" begin - ψ₀ = InfiniteMPS(ℙ^2, ℙ^D) + ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, IDMRG1(; tol, verbosity=5, maxiter=2)) # compare states alg = IDMRG1(; tol, verbosity=1) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG2" begin - ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 2) + ψ₀ = repeat(InfiniteMPS(ℂ^3, ℂ^D), 2) H_lazy′ = repeat(H_lazy, 2) H′ = repeat(H, 2) - trscheme = truncdim(12) + trscheme = truncdim(D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy′, IDMRG2(; tol, verbosity=5, maxiter=2, trscheme)) @@ -267,11 +269,11 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy′, alg) ψ, = find_groundstate(ψ₀, H′, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin - ψ₀ = InfiniteMPS(ℙ^2, ℙ^D) + ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, @@ -282,7 +284,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end end diff --git a/test/setup.jl b/test/setup.jl index 52412e80..548f66db 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -9,6 +9,7 @@ using TensorKit: PlanarTrivial, ℙ using LinearAlgebra: Diagonal # exports +export S_xx, S_yy, S_zz export force_planar export transverse_field_ising, heisenberg_XXX, bilinear_biquadratic_model export classical_ising, finite_classical_ising, sixvertex @@ -35,6 +36,37 @@ force_planar(mpo::DenseMPO) = DenseMPO(force_planar.(mpo.opp)) # Toy models # ---------------------------- +function S_xx(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1) where {T<:Number} + X = if spin == 1 // 2 + TensorMap(T[0 1; 1 0], ℂ^2 ← ℂ^2) + elseif spin == 1 + TensorMap(T[0 1 0; 1 0 1; 0 1 0], ℂ^3 ← ℂ^3) / sqrt(2) + else + throw(ArgumentError("spin $spin not supported")) + end + return X ⊗ X +end +function S_yy(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1) where {T<:Number} + Y = if spin == 1 / 2 + TensorMap(T[0 -im; im 0], ℂ^2 ← ℂ^2) + elseif spin == 1 + TensorMap(T[0 -im 0; im 0 -im; 0 im 0], ℂ^3 ← ℂ^3) / sqrt(2) + else + throw(ArgumentError("spin $spin not supported")) + end + return Y ⊗ Y +end +function S_zz(::Type{Trivial}=Trivial, ::Type{T}=ComplexF64; spin=1) where {T<:Number} + Z = if spin == 1 // 2 + TensorMap(T[1 0; 0 -1], ℂ^2 ← ℂ^2) + elseif spin == 1 + TensorMap(T[1 0 0; 0 0 0; 0 0 -1], ℂ^3 ← ℂ^3) + else + throw(ArgumentError("spin $spin not supported")) + end + return Z ⊗ Z +end + function transverse_field_ising(; g=1.0) X = TensorMap(ComplexF64[0 1; 1 0], ℂ^2 ← ℂ^2) Z = TensorMap(ComplexF64[1 0; 0 -1], ℂ^2 ← ℂ^2) From 851ba5f67b0a3381a89033517173d23b8a996f09 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 12 Jun 2024 14:38:41 +0200 Subject: [PATCH 2/9] Improve Grassmann stability --- src/algorithms/grassmann.jl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/algorithms/grassmann.jl b/src/algorithms/grassmann.jl index 05853164..f801faff 100644 --- a/src/algorithms/grassmann.jl +++ b/src/algorithms/grassmann.jl @@ -22,6 +22,9 @@ function TensorKit.rmul!(a::Grassmann.GrassmannTangent, b::AbstractTensorMap) Base.setfield!(a, :V, nothing) return a end +function Base.:/(a::Grassmann.GrassmannTangent, b::AbstractTensorMap) + return Grassmann.GrassmannTangent(a.W, a.Z / b) +end # preconditioned gradient struct PrecGrad{A,B} @@ -33,7 +36,8 @@ end function PrecGrad(v::Grassmann.GrassmannTangent) return PrecGrad(v, v, isometry(storagetype(v.Z), domain(v.Z), domain(v.Z))) end -PrecGrad(v::Grassmann.GrassmannTangent, rho) = PrecGrad(rmul!(copy(v), inv(rho)), v, rho) +PrecGrad(v::Grassmann.GrassmannTangent, rho) = PrecGrad(v / rho, v, rho) + Grassmann.base(g::PrecGrad) = Grassmann.base(g.Pg) function inner(g1::PrecGrad, g2::PrecGrad, rho=one(g1.rho)) @@ -72,8 +76,9 @@ function ManifoldPoint(state::Union{InfiniteMPS,FiniteMPS}, envs) g = Grassmann.project.(al_d, state.AL) Rhoreg = Vector{eltype(state.CR)}(undef, length(state)) + δmin = sqrt(eps(real(scalartype(state)))) for i in 1:length(state) - Rhoreg[i] = regularize(state.CR[i], norm(g[i]) / 10) + Rhoreg[i] = regularize(state.CR[i], max(norm(g[i]) / 10, δmin)) end return ManifoldPoint(state, envs, g, Rhoreg) @@ -85,16 +90,16 @@ function ManifoldPoint(state::MPSMultiline, envs) g = [Grassmann.project(d, a) for (d, a) in zip(ac_d, state.AL)] f = expectation_value(state, envs) - fi = imag.(f) - fr = real.(f) - - sum(fi) > MPSKit.Defaults.tol && @warn "mpo is not hermitian $fi" + sum(imag(f)) > MPSKit.Defaults.tol && @warn "MPO might not be Hermitian $f" - g = -2 * g ./ abs.(fr) + # actual costfunction is F = -log(sum(f)^2) => ∂F = -2 * g / |sum(f)| + # TODO: check if elementwise thing is correct? + g .*= (-2 ./ abs.(real(f))) Rhoreg = similar(state.CR) + δmin = sqrt(eps(real(scalartype(state)))) for (i, cg) in enumerate(g) - Rhoreg[i] = regularize(state.CR[i], norm(cg) / 10) + Rhoreg[i] = regularize(state.CR[i], max(norm(cg) / 10, δmin)) end return ManifoldPoint(state, envs, g, Rhoreg) @@ -112,9 +117,10 @@ function fg(x::ManifoldPoint{T}) where {T<:Union{InfiniteMPS,FiniteMPS}} g_prec[i] = PrecGrad(rmul!(copy(x.g[i]), x.state.CR[i]'), x.Rhoreg[i]) end - f = real(sum(expectation_value(x.state, x.envs))) + f = sum(expectation_value(x.state, x.envs)) + isapprox(imag(f), 0; atol=eps(abs(f))^(3 / 4)) || @warn "MPO might not be Hermitian: $f" - return f, g_prec + return real(f), g_prec end function fg(x::ManifoldPoint{<:MPSMultiline}) # the gradient I want to return is the preconditioned gradient! @@ -122,11 +128,10 @@ function fg(x::ManifoldPoint{<:MPSMultiline}) return PrecGrad(rmul!(copy(cg), x.state.CR[i]'), x.Rhoreg[i]) end - f = expectation_value(x.state, x.envs) - fi = imag.(f) - fr = real.(f) + f = sum(expectation_value(x.state, x.envs)) + isapprox(imag(f), 0; atol=eps(abs(f))^(3 / 4)) || @warn "MPO might not be Hermitian: $f" - return -log(sum(fr)^2), g_prec[:] + return -log(sum(real(f))^2), g_prec[:] end """ From 91c4f03de3f01be8862cd7c4bfaf9a89bb8b8a6b Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 12 Jun 2024 15:44:34 +0200 Subject: [PATCH 3/9] print more information --- test/algorithms.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index 92499abb..b7f58973 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -233,7 +233,7 @@ end ψ, envs, δ = find_groundstate(ψ₀, H_lazy, VUMPS(; tol, verbosity=5, maxiter=2)) # compare states - alg = VUMPS(; tol, verbosity=1) + alg = VUMPS(; tol, verbosity=2) ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) @@ -247,7 +247,7 @@ end ψ, envs, δ = find_groundstate(ψ₀, H_lazy, IDMRG1(; tol, verbosity=5, maxiter=2)) # compare states - alg = IDMRG1(; tol, verbosity=1) + alg = IDMRG1(; tol, verbosity=2) ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) @@ -265,7 +265,7 @@ end IDMRG2(; tol, verbosity=5, maxiter=2, trscheme)) # compare states - alg = IDMRG2(; tol, verbosity=1, trscheme) + alg = IDMRG2(; tol, verbosity=2, trscheme) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy′, alg) ψ, = find_groundstate(ψ₀, H′, alg) @@ -280,7 +280,7 @@ end GradientGrassmann(; tol, verbosity=5, maxiter=2)) # compare states - alg = GradientGrassmann(; tol, verbosity=1) + alg = GradientGrassmann(; tol, verbosity=2) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) From 71940fa2e30d6d47f804e51ea92960a5fa632945 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 12 Jun 2024 16:34:42 +0200 Subject: [PATCH 4/9] RNG overlord bless me --- test/algorithms.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index b7f58973..81d1c824 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -220,7 +220,7 @@ end atol = 1e-2 # test using XXZ model, Δ > 1 is gapped - local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] + local_operators = [-S_xx(), -S_yy(), -(1.234) * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) @@ -280,7 +280,7 @@ end GradientGrassmann(; tol, verbosity=5, maxiter=2)) # compare states - alg = GradientGrassmann(; tol, verbosity=2) + alg = GradientGrassmann(; tol, verbosity=1) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) From 87acfee4e7efccb933b2f723bfff97658aa74ea8 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 12 Jun 2024 16:57:08 +0200 Subject: [PATCH 5/9] simpler tests --- test/algorithms.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index 81d1c824..223a86c0 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -158,7 +158,7 @@ end @testset "LazySum FiniteMPS groundstate" verbose = true begin tol = 1e-8 D = 15 - atol = 1e-2 + atol = 1e-6 # test using XXZ model, Δ > 1 is gapped local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] @@ -179,7 +179,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end @testset "DMRG2" begin @@ -195,7 +195,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end @testset "GradientGrassmann" begin @@ -210,14 +210,14 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end end @testset "LazySum InfiniteMPS groundstate" verbose = true begin tol = 1e-8 D = 15 - atol = 1e-2 + atol = 1e-6 # test using XXZ model, Δ > 1 is gapped local_operators = [-S_xx(), -S_yy(), -(1.234) * S_zz()] @@ -237,7 +237,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end @testset "IDMRG1" begin @@ -251,7 +251,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end @testset "IDMRG2" begin @@ -269,7 +269,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy′, alg) ψ, = find_groundstate(ψ₀, H′, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H′)) ≈ sum(expectation_value(ψ_lazy, H_lazy′)) atol = atol end @testset "GradientGrassmann" begin @@ -284,7 +284,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol end end From 5299d9b749f5b0a0aaba556952b1bea0d8d3ab85 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Thu, 13 Jun 2024 09:14:08 +0200 Subject: [PATCH 6/9] Actually use antiferromagnetic heisenberg... --- test/algorithms.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index 223a86c0..cf36c024 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -220,7 +220,7 @@ end atol = 1e-6 # test using XXZ model, Δ > 1 is gapped - local_operators = [-S_xx(), -S_yy(), -(1.234) * S_zz()] + local_operators = [S_xx(), S_yy(), (1.234) * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) From 20106bdbcf1761f666a393e9280b4f9ffa4a2b72 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Thu, 13 Jun 2024 09:14:34 +0200 Subject: [PATCH 7/9] Revert "simpler tests" This reverts commit 87acfee4e7efccb933b2f723bfff97658aa74ea8. --- test/algorithms.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index cf36c024..d3d3adfa 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -158,7 +158,7 @@ end @testset "LazySum FiniteMPS groundstate" verbose = true begin tol = 1e-8 D = 15 - atol = 1e-6 + atol = 1e-2 # test using XXZ model, Δ > 1 is gapped local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] @@ -179,7 +179,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "DMRG2" begin @@ -195,7 +195,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin @@ -210,14 +210,14 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end end @testset "LazySum InfiniteMPS groundstate" verbose = true begin tol = 1e-8 D = 15 - atol = 1e-6 + atol = 1e-2 # test using XXZ model, Δ > 1 is gapped local_operators = [S_xx(), S_yy(), (1.234) * S_zz()] @@ -237,7 +237,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG1" begin @@ -251,7 +251,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG2" begin @@ -269,7 +269,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy′, alg) ψ, = find_groundstate(ψ₀, H′, alg) - @test sum(expectation_value(ψ, H′)) ≈ sum(expectation_value(ψ_lazy, H_lazy′)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin @@ -284,7 +284,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) - @test sum(expectation_value(ψ, H)) ≈ sum(expectation_value(ψ_lazy, H_lazy)) atol = atol + @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol end end From 07161c1e00169c93c0f0f65958a87a5db76f3e58 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Thu, 13 Jun 2024 09:42:58 +0200 Subject: [PATCH 8/9] Update defaults --- src/utility/defaults.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utility/defaults.jl b/src/utility/defaults.jl index 83dbde00..8aaaf5c8 100644 --- a/src/utility/defaults.jl +++ b/src/utility/defaults.jl @@ -16,16 +16,16 @@ const VERBOSE_ITER = 3 const VERBOSE_ALL = 4 const eltype = ComplexF64 -const maxiter = 100 -const tolgauge = 1e-14 -const tol = 1e-12 +const maxiter = 200 +const tolgauge = 1e-13 +const tol = 1e-10 const verbosity = VERBOSE_ITER const dynamic_tols = true const tol_min = 1e-14 -const tol_max = 1e-5 -const eigs_tolfactor = 1e-5 -const gauge_tolfactor = 1e-8 -const envs_tolfactor = 1e-5 +const tol_max = 1e-4 +const eigs_tolfactor = 1e-3 +const gauge_tolfactor = 1e-6 +const envs_tolfactor = 1e-4 _finalize(iter, state, opp, envs) = (state, envs) From 0cdaf568ad3355616d7a7dd7222aa3b52c0a999f Mon Sep 17 00:00:00 2001 From: lkdvos Date: Fri, 14 Jun 2024 20:02:42 +0200 Subject: [PATCH 9/9] more stabilization attempts --- test/algorithms.jl | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index d3d3adfa..85037cbc 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -161,30 +161,28 @@ end atol = 1e-2 # test using XXZ model, Δ > 1 is gapped - local_operators = [-S_xx(), -S_yy(), -(1 + abs(rand())) * S_zz()] + local_operators = [S_xx(), S_yy(), 0.7 * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) H = sum(H_lazy) - @testset "DMRG" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) + ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) + ψ₀, = find_groundstate(ψ₀, H; tol, verbosity=1) + @testset "DMRG" begin # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, DMRG(; tol, verbosity=5, maxiter=1)) # compare states alg = DMRG(; tol, verbosity=1) - ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end @testset "DMRG2" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) - # test logging passes trscheme = truncdim(12) ψ, envs, δ = find_groundstate(ψ₀, H_lazy, @@ -195,12 +193,10 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin - ψ₀ = FiniteMPS(randn, ComplexF64, 10, ℂ^3, ℂ^D) - # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, GradientGrassmann(; tol, verbosity=5, maxiter=2)) @@ -210,7 +206,7 @@ end ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end end @@ -220,61 +216,55 @@ end atol = 1e-2 # test using XXZ model, Δ > 1 is gapped - local_operators = [S_xx(), S_yy(), (1.234) * S_zz()] + local_operators = [S_xx(), S_yy(), (0.7) * S_zz()] mpo_hamiltonians = MPOHamiltonian.(local_operators) H_lazy = LazySum(mpo_hamiltonians) H = sum(H_lazy) - @testset "VUMPS" begin - ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) + ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) + ψ₀, = find_groundstate(ψ₀, H; tol, verbosity=1) + @testset "VUMPS" begin # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, VUMPS(; tol, verbosity=5, maxiter=2)) # compare states alg = VUMPS(; tol, verbosity=2) - ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG1" begin - ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) - # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, IDMRG1(; tol, verbosity=5, maxiter=2)) # compare states alg = IDMRG1(; tol, verbosity=2) - ψ, = find_groundstate(ψ₀, H, alg) ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end @testset "IDMRG2" begin - ψ₀ = repeat(InfiniteMPS(ℂ^3, ℂ^D), 2) + ψ₀′ = repeat(ψ₀, 2) H_lazy′ = repeat(H_lazy, 2) H′ = repeat(H, 2) trscheme = truncdim(D) # test logging passes - ψ, envs, δ = find_groundstate(ψ₀, H_lazy′, + ψ, envs, δ = find_groundstate(ψ₀′, H_lazy′, IDMRG2(; tol, verbosity=5, maxiter=2, trscheme)) # compare states alg = IDMRG2(; tol, verbosity=2, trscheme) - ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy′, alg) - ψ, = find_groundstate(ψ₀, H′, alg) + ψ_lazy, envs, δ = find_groundstate(ψ₀′, H_lazy′, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀′, ψ_lazy)) ≈ 1 atol = atol end @testset "GradientGrassmann" begin - ψ₀ = InfiniteMPS(ℂ^3, ℂ^D) - # test logging passes ψ, envs, δ = find_groundstate(ψ₀, H_lazy, GradientGrassmann(; tol, verbosity=5, maxiter=2)) @@ -284,7 +274,7 @@ end ψ_lazy, envs, δ = find_groundstate(ψ₀, H_lazy, alg) ψ, = find_groundstate(ψ₀, H, alg) - @test abs(dot(ψ, ψ_lazy)) ≈ 1 atol = atol + @test abs(dot(ψ₀, ψ_lazy)) ≈ 1 atol = atol end end