Skip to content

Commit 48534cd

Browse files
Gertianlkdvos
andauthored
3 site tests (#180)
* 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]>
1 parent 1c061c9 commit 48534cd

File tree

1 file changed

+69
-50
lines changed

1 file changed

+69
-50
lines changed

test/algorithms.jl

Lines changed: 69 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ end
7272
tol = 1e-8
7373
g = 4.0
7474
D = 6
75-
H = force_planar(transverse_field_ising(; g))
7675

77-
@testset "VUMPS" begin
78-
ψ₀ = InfiniteMPS(ℙ^2, ℙ^D)
79-
v₀ = variance(ψ₀, H)
76+
H_ref = force_planar(transverse_field_ising(; g))
77+
ψ = InfiniteMPS(ℙ^2, ℙ^D)
78+
v₀ = variance(ψ, H_ref)
79+
80+
@testset "VUMPS" for unit_cell_size in [1, 3]
81+
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
82+
H = repeat(H_ref, unit_cell_size)
8083

8184
# test logging
82-
ψ, envs, δ = find_groundstate, H, VUMPS(; tol, verbosity=5, maxiter=2))
85+
ψ, envs, δ = find_groundstate(ψ, H, VUMPS(; tol, verbosity=5, maxiter=2))
8386

8487
ψ, envs, δ = find_groundstate(ψ, H, VUMPS(; tol, verbosity=1))
8588
v = variance(ψ, H, envs)
@@ -90,12 +93,12 @@ end
9093
@test v < 1e-2
9194
end
9295

93-
@testset "IDMRG1" begin
94-
ψ = InfiniteMPS(ℙ^2, ℙ^D)
95-
v₀ = variance(ψ₀, H)
96+
@testset "IDMRG1" for unit_cell_size in [1, 3]
97+
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
98+
H = repeat(H_ref, unit_cell_size)
9699

97100
# test logging
98-
ψ, envs, δ = find_groundstate, H, IDMRG1(; tol, verbosity=5, maxiter=2))
101+
ψ, envs, δ = find_groundstate(ψ, H, IDMRG1(; tol, verbosity=5, maxiter=2))
99102

100103
ψ, envs, δ = find_groundstate(ψ, H, IDMRG1(; tol, verbosity=1))
101104
v = variance(ψ, H, envs)
@@ -107,32 +110,32 @@ end
107110
end
108111

109112
@testset "IDMRG2" begin
110-
ψ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 2)
111-
H2 = repeat(H, 2)
112-
v₀ = variance(ψ₀, H2)
113+
ψ = repeat(InfiniteMPS(ℙ^2, ℙ^D), 2)
114+
H = repeat(H_ref, 2)
115+
113116
trscheme = truncbelow(1e-8)
114117

115118
# test logging
116-
ψ, envs, δ = find_groundstate₀, H2,
119+
ψ, envs, δ = find_groundstate, H,
117120
IDMRG2(; tol, verbosity=5, maxiter=2,
118121
trscheme))
119122

120-
ψ, envs, δ = find_groundstate(ψ, H2,
123+
ψ, envs, δ = find_groundstate(ψ, H,
121124
IDMRG2(; tol, verbosity=1, trscheme))
122-
v = variance(ψ, H2, envs)
125+
v = variance(ψ, H, envs)
123126

124127
# test using low variance
125128
@test sum(δ) 0 atol = 1e-3
126129
@test v < v₀
127130
@test v < 1e-2
128131
end
129132

130-
@testset "GradientGrassmann" begin
131-
ψ = InfiniteMPS(ℙ^2, ℙ^D)
132-
v₀ = variance(ψ₀, H)
133+
@testset "GradientGrassmann" for unit_cell_size in [1, 3]
134+
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
135+
H = repeat(H_ref, unit_cell_size)
133136

134137
# test logging
135-
ψ, envs, δ = find_groundstate, H,
138+
ψ, envs, δ = find_groundstate(ψ, H,
136139
GradientGrassmann(; tol, verbosity=5, maxiter=2))
137140

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

147-
@testset "Combination" begin
148-
ψ = InfiniteMPS(ℙ^2, ℙ^D)
149-
v₀ = variance(ψ₀, H)
150+
@testset "Combination" for unit_cell_size in [1, 3]
151+
ψ = unit_cell_size == 1 ? InfiniteMPS(ℙ^2, ℙ^D) : repeat(ψ, unit_cell_size)
152+
H = repeat(H_ref, unit_cell_size)
150153

151154
alg = VUMPS(; tol=100 * tol, verbosity=1, maxiter=10) &
152155
GradientGrassmann(; tol, verbosity=1, maxiter=50)
153-
ψ, envs, δ = find_groundstate, H, alg)
156+
ψ, envs, δ = find_groundstate(ψ, H, alg)
154157

155158
v = variance(ψ, H, envs)
156159

@@ -452,7 +455,7 @@ end
452455
Rep[SU₂](0 => 2, 1 => 2,
453456
2 => 1))]
454457
@testset "mpo" begin
455-
#random nn interaction
458+
# random nn interaction
456459
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
457460
nn += nn'
458461
H = MPOHamiltonian(nn)
@@ -467,33 +470,49 @@ end
467470
end
468471

469472
@testset "infinite mps" begin
470-
#random nn interaction
473+
# random nn interaction
471474
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
472475
nn += nn'
473476

474-
state = InfiniteMPS([pspace, pspace], [Dspace, Dspace])
475-
476-
state_re = changebonds(state,
477-
RandExpand(; trscheme=truncdim(dim(Dspace) * dim(Dspace))))
478-
@test dot(state, state_re) 1 atol = 1e-8
479-
480-
state_oe, _ = changebonds(state,
481-
repeat(MPOHamiltonian(nn), 2),
482-
OptimalExpand(;
483-
trscheme=truncdim(dim(Dspace) *
484-
dim(Dspace))))
485-
@test dot(state, state_oe) 1 atol = 1e-8
486-
487-
state_vs, _ = changebonds(state, repeat(MPOHamiltonian(nn), 2),
488-
VUMPSSvdCut(; trscheme=notrunc()))
489-
@test dim(left_virtualspace(state, 1)) < dim(left_virtualspace(state_vs, 1))
477+
# test rand_expand
478+
for unit_cell_size in 2:3
479+
H = repeat(MPOHamiltonian(nn), unit_cell_size)
480+
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))
490481

491-
state_vs_tr = changebonds(state_vs, SvdCut(; trscheme=truncdim(dim(Dspace))))
492-
@test dim(right_virtualspace(state_vs_tr, 1)) < dim(right_virtualspace(state_vs, 1))
482+
state_re = changebonds(state,
483+
RandExpand(;
484+
trscheme=truncdim(dim(Dspace) * dim(Dspace))))
485+
@test dot(state, state_re) 1 atol = 1e-8
486+
end
487+
# test optimal_expand
488+
for unit_cell_size in 2:3
489+
H = repeat(MPOHamiltonian(nn), unit_cell_size)
490+
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))
491+
492+
state_oe, _ = changebonds(state,
493+
H,
494+
OptimalExpand(;
495+
trscheme=truncdim(dim(Dspace) *
496+
dim(Dspace))))
497+
@test dot(state, state_oe) 1 atol = 1e-8
498+
end
499+
# test VUMPSSvdCut
500+
for unit_cell_size in [1, 2, 3, 4]
501+
H = repeat(MPOHamiltonian(nn), unit_cell_size)
502+
state = InfiniteMPS(fill(pspace, unit_cell_size), fill(Dspace, unit_cell_size))
503+
504+
state_vs, _ = changebonds(state, H,
505+
VUMPSSvdCut(; trscheme=notrunc()))
506+
@test dim(left_virtualspace(state, 1)) < dim(left_virtualspace(state_vs, 1))
507+
508+
state_vs_tr = changebonds(state_vs, SvdCut(; trscheme=truncdim(dim(Dspace))))
509+
@test dim(right_virtualspace(state_vs_tr, 1)) <
510+
dim(right_virtualspace(state_vs, 1))
511+
end
493512
end
494513

495514
@testset "finite mps" begin
496-
#random nn interaction
515+
# random nn interaction
497516
nn = TensorMap(rand, ComplexF64, pspace * pspace, pspace * pspace)
498517
nn += nn'
499518

@@ -576,15 +595,15 @@ end
576595
for λ in [1.05, 2.0, 4.0]
577596
H = hamiltonian(λ)
578597
ψ = InfiniteMPS([ℂ^2], [ℂ^16])
579-
ψ, envs, = find_groundstate(ψ, H, VUMPS(; maxiter=100, verbosity=0))
598+
ψ, envs = find_groundstate(ψ, H, VUMPS(; maxiter=100, verbosity=0))
580599

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

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

596-
#stub tests
615+
# stub tests
597616
@testset "correlation length / entropy" begin
598617
ψ = InfiniteMPS([ℙ^2], [ℙ^10])
599618
H = force_planar(transverse_field_ising())
@@ -697,20 +716,20 @@ end
697716
@testset "periodic boundary conditions" begin
698717
len = 10
699718

700-
#impose periodic boundary conditions on the hamiltonian (circle size 10)
719+
# impose periodic boundary conditions on the hamiltonian (circle size 10)
701720
H = transverse_field_ising()
702721
H = periodic_boundary_conditions(H, len)
703722

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

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

708-
#translation mpo:
727+
# translation mpo:
709728
@tensor bulk[-1 -2; -3 -4] := isomorphism(ℂ^2, ℂ^2)[-2, -4] *
710729
isomorphism(ℂ^2, ℂ^2)[-1, -3]
711730
translation = periodic_boundary_conditions(DenseMPO(bulk), len)
712731

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

0 commit comments

Comments
 (0)