Skip to content

Commit

Permalink
3 site tests (#180)
Browse files Browse the repository at this point in the history
* Added some tests for a 3-site unit cell

* formatting...

* Added some more tests for vumpssvd. This will be helpfull when we paralelize it !

* formatted

* changed order of tests according to @lukas

* now also mentions current unit_cell_size

* Now tests re-use prior converged states

* fixed groundstate-alg part of tests

* formatting

* small formatting changes

* reenable test

---------

Co-authored-by: lkdvos <[email protected]>
Co-authored-by: Lukas Devos <[email protected]>
  • Loading branch information
3 people authored Oct 27, 2024
1 parent 1c061c9 commit 48534cd
Showing 1 changed file with 69 additions and 50 deletions.
119 changes: 69 additions & 50 deletions test/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ end
tol = 1e-8
g = 4.0
D = 6
H = force_planar(transverse_field_ising(; g))

@testset "VUMPS" begin
ψ₀ = InfiniteMPS(ℙ^2, ℙ^D)
v₀ = variance(ψ₀, H)
H_ref = force_planar(transverse_field_ising(; g))
ψ = InfiniteMPS(ℙ^2, ℙ^D)
v₀ = variance(ψ, H_ref)

@testset "VUMPS" for unit_cell_size in [1, 3]
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
H = repeat(H_ref, unit_cell_size)

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

ψ, envs, δ = find_groundstate(ψ, H, VUMPS(; tol, verbosity=1))
v = variance(ψ, H, envs)
Expand All @@ -90,12 +93,12 @@ end
@test v < 1e-2
end

@testset "IDMRG1" begin
ψ = InfiniteMPS(ℙ^2, ℙ^D)
v₀ = variance(ψ₀, H)
@testset "IDMRG1" for unit_cell_size in [1, 3]
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
H = repeat(H_ref, unit_cell_size)

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

ψ, envs, δ = find_groundstate(ψ, H, IDMRG1(; tol, verbosity=1))
v = variance(ψ, H, envs)
Expand All @@ -107,32 +110,32 @@ end
end

@testset "IDMRG2" begin
ψ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 2)
H2 = repeat(H, 2)
v₀ = variance(ψ₀, H2)
ψ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 2)
H = repeat(H_ref, 2)

trscheme = truncbelow(1e-8)

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

ψ, envs, δ = find_groundstate(ψ, H2,
ψ, envs, δ = find_groundstate(ψ, H,
IDMRG2(; tol, verbosity=1, trscheme))
v = variance(ψ, H2, envs)
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
ψ = InfiniteMPS(ℙ^2, ℙ^D)
v₀ = variance(ψ₀, H)
@testset "GradientGrassmann" for unit_cell_size in [1, 3]
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
H = repeat(H_ref, unit_cell_size)

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

ψ, envs, δ = find_groundstate(ψ, H, GradientGrassmann(; tol, verbosity=1))
Expand All @@ -144,13 +147,13 @@ end
@test v < 1e-2
end

@testset "Combination" begin
ψ = InfiniteMPS(ℙ^2, ℙ^D)
v₀ = variance(ψ₀, H)
@testset "Combination" for unit_cell_size in [1, 3]
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
H = repeat(H_ref, unit_cell_size)

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

v = variance(ψ, H, envs)

Expand Down Expand Up @@ -452,7 +455,7 @@ end
Rep[SU₂](0 => 2, 1 => 2,
2 => 1))]
@testset "mpo" begin
#random nn interaction
# random nn interaction
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
nn += nn'
H = MPOHamiltonian(nn)
Expand All @@ -467,33 +470,49 @@ end
end

@testset "infinite mps" begin
#random nn interaction
# random nn interaction
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
nn += nn'

state = InfiniteMPS([pspace, pspace], [Dspace, Dspace])

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

state_oe, _ = changebonds(state,
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))
# test rand_expand
for unit_cell_size in 2:3
H = repeat(MPOHamiltonian(nn), unit_cell_size)
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))

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))
state_re = changebonds(state,
RandExpand(;
trscheme=truncdim(dim(Dspace) * dim(Dspace))))
@test dot(state, state_re) 1 atol = 1e-8
end
# test optimal_expand
for unit_cell_size in 2:3
H = repeat(MPOHamiltonian(nn), unit_cell_size)
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))

state_oe, _ = changebonds(state,
H,
OptimalExpand(;
trscheme=truncdim(dim(Dspace) *
dim(Dspace))))
@test dot(state, state_oe) 1 atol = 1e-8
end
# test VUMPSSvdCut
for unit_cell_size in [1, 2, 3, 4]
H = repeat(MPOHamiltonian(nn), unit_cell_size)
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))

state_vs, _ = changebonds(state, H,
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
#random nn interaction
# random nn interaction
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
nn += nn'

Expand Down Expand Up @@ -576,15 +595,15 @@ end
for λ in [1.05, 2.0, 4.0]
H = hamiltonian(λ)
ψ = InfiniteMPS([ℂ^2], [ℂ^16])
ψ, envs, = find_groundstate(ψ, H, VUMPS(; maxiter=100, verbosity=0))
ψ, envs = find_groundstate(ψ, H, VUMPS(; maxiter=100, verbosity=0))

numerical_scusceptibility = fidelity_susceptibility(ψ, H, [H_X], envs; maxiter=10)
@test numerical_scusceptibility[1, 1] analytical_susceptibility(λ) atol = 1e-2

# test if the finite fid sus approximates the analytical one with increasing system size
fin_en = map([20, 15, 10]) do L
ψ = FiniteMPS(rand, ComplexF64, L, ℂ^2, ℂ^16)
ψ, envs, = find_groundstate(ψ, H, DMRG(; verbosity=0))
ψ, envs = find_groundstate(ψ, H, DMRG(; verbosity=0))
numerical_scusceptibility = fidelity_susceptibility(ψ, H, [H_X], envs;
maxiter=10)
return numerical_scusceptibility[1, 1] / L
Expand All @@ -593,7 +612,7 @@ end
end
end

#stub tests
# stub tests
@testset "correlation length / entropy" begin
ψ = InfiniteMPS([ℙ^2], [ℙ^10])
H = force_planar(transverse_field_ising())
Expand Down Expand Up @@ -697,20 +716,20 @@ end
@testset "periodic boundary conditions" begin
len = 10

#impose periodic boundary conditions on the hamiltonian (circle size 10)
# impose periodic boundary conditions on the hamiltonian (circle size 10)
H = transverse_field_ising()
H = periodic_boundary_conditions(H, len)

ψ = FiniteMPS(len, ℂ^2, ℂ^10)

gs, envs = find_groundstate(ψ, H, DMRG(; verbosity=0))

#translation mpo:
# translation mpo:
@tensor bulk[-1 -2; -3 -4] := isomorphism(ℂ^2, ℂ^2)[-2, -4] *
isomorphism(ℂ^2, ℂ^2)[-1, -3]
translation = periodic_boundary_conditions(DenseMPO(bulk), len)

#the groundstate should be translation invariant:
# the groundstate should be translation invariant:
ut = Tensor(ones, ℂ^1)
@tensor leftstart[-1 -2; -3] := l_LL(gs)[-1, -3] * conj(ut[-2])
T = TransferMatrix([gs.AC[1]; gs.AR[2:end]], translation[:], [gs.AC[1]; gs.AR[2:end]])
Expand Down

0 comments on commit 48534cd

Please sign in to comment.