diff --git a/test/ctmrg/fixediter.jl b/test/ctmrg/fixediter.jl new file mode 100644 index 00000000..3e8a634c --- /dev/null +++ b/test/ctmrg/fixediter.jl @@ -0,0 +1,75 @@ +using Test +using Random +using TensorKit +using PEPSKit +using PEPSKit: + FixedSVD, + ctmrg_iter, + gauge_fix, + fix_relative_phases, + fix_global_phases, + check_elementwise_convergence + +# initialize parameters +χbond = 2 +χenv = 16 +svd_algs = [SVDAdjoint(; fwd_alg=TensorKit.SVD()), SVDAdjoint(; fwd_alg=IterSVD())] +unitcells = [(1, 1), (3, 4)] + +# test for element-wise convergence after application of FixedIter step +@testset "$unitcell unit cell with $(typeof(svd_alg.fwd_alg))" for (unitcell, svd_alg) in + Iterators.product( + unitcells, svd_algs +) + ctm_alg = CTMRG(; tol=1e-12, verbosity=1, ctmrgscheme=:AllSides, svd_alg) + + # initialize states + Random.seed!(91283219347) + psi = InfinitePEPS(2, χbond; unitcell) + env_conv1 = leading_boundary(CTMRGEnv(psi; Venv=ComplexSpace(χenv)), psi, ctm_alg) + + # do extra iteration to get SVD + env_conv2, info = ctmrg_iter(psi, env_conv1, ctm_alg) + env_fix, signs = gauge_fix(env_conv1, env_conv2) + @test check_elementwise_convergence(env_conv1, env_fix) + + # fix gauge of SVD + U_fix, V_fix = fix_relative_phases(info.U, info.V, signs) + svd_alg_fix = SVDAdjoint(; fwd_alg=FixedSVD(U_fix, info.S, V_fix)) + ctm_alg_fix = CTMRG(; svd_alg=svd_alg_fix, trscheme=notrunc(), ctmrgscheme=:AllSides) + + # do iteration with FixedSVD + env_fixedsvd, = ctmrg_iter(psi, env_conv1, ctm_alg_fix) + env_fixedsvd = fix_global_phases(env_conv1, env_fixedsvd) + @test check_elementwise_convergence(env_conv1, env_fixedsvd) +end + +## +# ctm_alg = CTMRG(; +# tol=1e-12, +# miniter=4, +# maxiter=100, +# verbosity=1, +# ctmrgscheme=:AllSides, +# svd_alg=SVDAdjoint(; fwd_alg=IterSVD()), +# ) + +# # initialize states +# Random.seed!(91283219347) +# psi = InfinitePEPS(2, χbond) +# env_conv1 = leading_boundary(CTMRGEnv(psi; Venv=ComplexSpace(χenv)), psi, ctm_alg); + +# # do extra iteration to get SVD +# env_conv2, info = ctmrg_iter(psi, env_conv1, ctm_alg); +# env_fix, signs = gauge_fix(env_conv1, env_conv2); +# @test check_elementwise_convergence(env_conv1, env_fix) + +# # fix gauge of SVD +# U_fix, V_fix = fix_relative_phases(info.U, info.V, signs); +# svd_alg_fix = SVDAdjoint(; fwd_alg=FixedSVD(U_fix, info.S, V_fix)); +# ctm_alg_fix = CTMRG(; svd_alg=svd_alg_fix, trscheme=notrunc(), ctmrgscheme=:AllSides); + +# # do iteration with FixedSVD +# env_fixedsvd, = ctmrg_iter(psi, env_conv1, ctm_alg_fix); +# env_fixedsvd = fix_global_phases(env_conv1, env_fixedsvd); +# @test check_elementwise_convergence(env_conv1, env_fixedsvd) \ No newline at end of file diff --git a/test/ctmrg/fixedsvd.jl b/test/ctmrg/fixedsvd.jl deleted file mode 100644 index 9b0ec4d1..00000000 --- a/test/ctmrg/fixedsvd.jl +++ /dev/null @@ -1,60 +0,0 @@ -using Test -using Random -using TensorKit -using PEPSKit -using PEPSKit: - FixedSVD, - ctmrg_iter, - gauge_fix, - fix_relative_phases, - fix_global_phases, - check_elementwise_convergence - -# initialize parameters -χbond = 2 -χenv = 16 -ctm_alg = CTMRG(; tol=1e-12, miniter=4, maxiter=100, verbosity=1, ctmrgscheme=:AllSides) - -@testset "(1, 1) unit cell" begin - # initialize states - Random.seed!(91283219347) - psi = InfinitePEPS(2, χbond) - env_conv1 = leading_boundary(CTMRGEnv(psi; Venv=ComplexSpace(χenv)), psi, ctm_alg) - - # do extra iteration to get SVD - env_conv2, info = ctmrg_iter(psi, env_conv1, ctm_alg) - env_fix, signs = gauge_fix(env_conv1, env_conv2) - @test check_elementwise_convergence(env_conv1, env_fix) - - # fix gauge of SVD - U_fix, V_fix = fix_relative_phases(info.U, info.V, signs) - svd_alg_fix = SVDAdjoint(; fwd_alg=FixedSVD(U_fix, info.S, V_fix)) - ctm_alg_fix = CTMRG(; svd_alg=svd_alg_fix, trscheme=notrunc(), ctmrgscheme=:AllSides) - - # do iteration with FixedSVD - env_fixedsvd, = ctmrg_iter(psi, env_conv1, ctm_alg_fix) - env_fixedsvd = fix_global_phases(env_conv1, env_fixedsvd) - @test check_elementwise_convergence(env_conv1, env_fixedsvd) -end - -@testset "(3, 4) unit cell" begin - # initialize states - Random.seed!(91283219347) - psi = InfinitePEPS(2, χbond; unitcell=(3, 4)) - env_conv1 = leading_boundary(CTMRGEnv(psi; Venv=ComplexSpace(χenv)), psi, ctm_alg) - - # do extra iteration to get SVD - env_conv2, info = ctmrg_iter(psi, env_conv1, ctm_alg) - env_fix, signs = gauge_fix(env_conv1, env_conv2) - @test check_elementwise_convergence(env_conv1, env_fix) - - # fix gauge of SVD - U_fix, V_fix = fix_relative_phases(info.U, info.V, signs) - svd_alg_fix = SVDAdjoint(; fwd_alg=FixedSVD(U_fix, info.S, V_fix)) - ctm_alg_fix = CTMRG(; svd_alg=svd_alg_fix, trscheme=notrunc(), ctmrgscheme=:AllSides) - - # do iteration with FixedSVD - env_fixedsvd, = ctmrg_iter(psi, env_conv1, ctm_alg_fix) - env_fixedsvd = fix_global_phases(env_conv1, env_fixedsvd) - @test check_elementwise_convergence(env_conv1, env_fixedsvd) -end diff --git a/test/ctmrg/gradients.jl b/test/ctmrg/gradients.jl index 978d65e7..3e3a7070 100644 --- a/test/ctmrg/gradients.jl +++ b/test/ctmrg/gradients.jl @@ -17,9 +17,15 @@ models = [square_lattice_heisenberg(), square_lattice_pwave()] names = ["Heisenberg", "p-wave superconductor"] Random.seed!(42039482030) tol = 1e-8 -boundary_alg = CTMRG(; tol=tol, miniter=4, maxiter=100, verbosity=0) +boundary_alg = CTMRG(; tol=tol, miniter=4, maxiter=100, verbosity=0, ctmrgscheme=:AllSides) gradmodes = [ - nothing, GeomSum(; tol), ManualIter(; tol), KrylovKit.GMRES(; tol=tol, maxiter=10) + nothing, + GeomSum(; tol, iterscheme=:FixedIter), + GeomSum(; tol, iterscheme=:DiffGauge), + ManualIter(; tol, iterscheme=:FixedIter), + ManualIter(; tol, iterscheme=:DiffGauge), + LinSolve(; alg=KrylovKit.GMRES(; tol=tol, maxiter=10), iterscheme=:FixedIter), + LinSolve(; alg=KrylovKit.GMRES(; tol=tol, maxiter=10), iterscheme=:DiffGauge), ] steps = -0.01:0.005:0.01 diff --git a/test/runtests.jl b/test/runtests.jl index 99810728..143e188b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,7 +21,7 @@ end include("ctmrg/svd_wrapper.jl") end @time @safetestset "SVD wrapper" begin - include("ctmrg/fixedsvd.jl") + include("ctmrg/fixediter.jl") end @time @safetestset "SVD wrapper" begin include("ctmrg/unitcell.jl")