Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 site tests #180

Merged
merged 12 commits into from
Oct 27, 2024
123 changes: 111 additions & 12 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,98 @@ end
end
end

@testset "InfiniteMPS 3-site groundstates" verbose = true begin
tol = 1e-8
g = 4.0
D = 6
H = repeat(force_planar(transverse_field_ising(; g)), 3)

@testset "VUMPS" begin
ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 3)
v₀ = variance(ψ₀, H)

# test logging
ψ, envs, δ = find_groundstate(ψ₀, H, VUMPS(; tol, verbosity=5, maxiter=2))

ψ, envs, δ = find_groundstate(ψ, H, VUMPS(; tol, verbosity=1))
v = variance(ψ, H, envs)

# test using low variance
@test sum(δ) ≈ 0 atol = 1e-3
@test v < v₀
@test v < 1e-2
end

@testset "IDMRG1" begin
ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 3)
v₀ = variance(ψ₀, H)

# test logging
ψ, envs, δ = find_groundstate(ψ₀, H, IDMRG1(; tol, verbosity=5, maxiter=2))

ψ, envs, δ = find_groundstate(ψ, H, IDMRG1(; tol, verbosity=1))
v = variance(ψ, H, envs)

# test using low variance
@test sum(δ) ≈ 0 atol = 1e-3
@test v < v₀
@test v < 1e-2
end

@testset "IDMRG2" begin
ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 3)
v₀ = variance(ψ₀, H)
trscheme = truncbelow(1e-8)

# test logging
ψ, envs, δ = find_groundstate(ψ₀, H,
IDMRG2(; tol, verbosity=5, maxiter=2,
trscheme))

ψ, envs, δ = find_groundstate(ψ, H,
IDMRG2(; tol, verbosity=1, trscheme))
v = variance(ψ, H, envs)

# test using low variance
@test sum(δ) ≈ 0 atol = 1e-3
@test v < v₀
@test v < 1e-2
end

@testset "GradientGrassmann" begin
ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 3)
v₀ = variance(ψ₀, H)

# test logging
ψ, envs, δ = find_groundstate(ψ₀, H,
GradientGrassmann(; tol, verbosity=5, maxiter=2))

ψ, envs, δ = find_groundstate(ψ, H, GradientGrassmann(; tol, verbosity=1))
v = variance(ψ, H, envs)

# test using low variance
@test sum(δ) ≈ 0 atol = 1e-3
@test v < v₀
@test v < 1e-2
end

@testset "Combination" begin
ψ₀ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 3)
v₀ = variance(ψ₀, H)

alg = VUMPS(; tol=100 * tol, verbosity=1, maxiter=10) &
GradientGrassmann(; tol, verbosity=1, maxiter=50)
ψ, envs, δ = find_groundstate(ψ₀, H, alg)

v = variance(ψ, H, envs)

# test using low variance
@test sum(δ) ≈ 0 atol = 1e-3
@test v < v₀
@test v < 1e-2
end
end

@testset "LazySum FiniteMPS groundstate" verbose = true begin
tol = 1e-8
D = 15
Expand Down Expand Up @@ -471,25 +563,32 @@ end
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
nn += nn'

state = InfiniteMPS([pspace, pspace], [Dspace, Dspace])
state1 = InfiniteMPS(pspace, Dspace)
state2 = InfiniteMPS([pspace, pspace], [Dspace, Dspace])
state3 = InfiniteMPS([pspace, pspace, pspace], [Dspace, Dspace, Dspace])

state_re = changebonds(state,
state_re = changebonds(state2,
RandExpand(; trscheme=truncdim(dim(Dspace) * dim(Dspace))))
@test dot(state, state_re) ≈ 1 atol = 1e-8
@test dot(state2, state_re) ≈ 1 atol = 1e-8

state_oe, _ = changebonds(state,
state_oe, _ = changebonds(state2,
repeat(MPOHamiltonian(nn), 2),
OptimalExpand(;
trscheme=truncdim(dim(Dspace) *
dim(Dspace))))
@test dot(state, state_oe) ≈ 1 atol = 1e-8

state_vs, _ = changebonds(state, repeat(MPOHamiltonian(nn), 2),
VUMPSSvdCut(; trscheme=notrunc()))
@test dim(left_virtualspace(state, 1)) < dim(left_virtualspace(state_vs, 1))

state_vs_tr = changebonds(state_vs, SvdCut(; trscheme=truncdim(dim(Dspace))))
@test dim(right_virtualspace(state_vs_tr, 1)) < dim(right_virtualspace(state_vs, 1))
@test dot(state2, state_oe) ≈ 1 atol = 1e-8

#test vumpssvd with different unit cells
for state in [state1, state2, state3]
@show length(state)
state_vs, _ = changebonds(state, repeat(MPOHamiltonian(nn), length(state)),
VUMPSSvdCut(; trscheme=notrunc()))
@test dim(left_virtualspace(state, 1)) < dim(left_virtualspace(state_vs, 1))

state_vs_tr = changebonds(state_vs, SvdCut(; trscheme=truncdim(dim(Dspace))))
@test dim(right_virtualspace(state_vs_tr, 1)) <
dim(right_virtualspace(state_vs, 1))
end
end

@testset "finite mps" begin
Expand Down
Loading