From f6f10ea19e6512602272fbab9ef14fc900f2239d Mon Sep 17 00:00:00 2001 From: lkdvos Date: Tue, 14 May 2024 10:37:33 +0200 Subject: [PATCH] Remove tests from examples --- examples/test_gauge_fixing.jl | 64 ----------------------------------- examples/test_gradients.jl | 53 ----------------------------- examples/test_vumps.jl | 8 ----- 3 files changed, 125 deletions(-) delete mode 100644 examples/test_gauge_fixing.jl delete mode 100644 examples/test_gradients.jl delete mode 100644 examples/test_vumps.jl diff --git a/examples/test_gauge_fixing.jl b/examples/test_gauge_fixing.jl deleted file mode 100644 index 6594cf23..00000000 --- a/examples/test_gauge_fixing.jl +++ /dev/null @@ -1,64 +0,0 @@ -using LinearAlgebra -using TensorKit, MPSKitModels, OptimKit -using PEPSKit - -function test_gauge_fixing( - f, T, P::S, V::S, E::S; χenv::Int=20, unitcell::NTuple{2,Int}=(1, 1) -) where {S<:ElementarySpace} - ψ = InfinitePEPS(f, T, P, V; unitcell) - env = CTMRGEnv(ψ; Venv=E) - - ctmalg = CTMRG(; - trscheme=truncdim(χenv), tol=1e-10, miniter=4, maxiter=100, verbosity=2 - ) - ctmalg_fixed = CTMRG(; - trscheme=truncdim(χenv), - tol=1e-10, - miniter=4, - maxiter=100, - verbosity=2, - fixedspace=true, - ) - - env = leading_boundary(ψ, ctmalg, env) - - println("Testing gauge fixing for $(sectortype(P)) symmetry and $unitcell unit cell.") - - println("\nBefore gauge-fixing:") - env′, = PEPSKit.ctmrg_iter(ψ, env, ctmalg_fixed) - @show PEPSKit.check_elementwise_convergence(env, env′) - - println("\nAfter gauge-fixing:") - envfix = PEPSKit.gauge_fix(env, env′) - @show PEPSKit.check_elementwise_convergence(env, envfix) - return println() -end - -# Trivial - -P = ℂ^2 # physical space -V = ℂ^2 # PEPS virtual space -χenv = 20 # environment truncation dimension -E = ℂ^χenv # environment virtual space - -test_gauge_fixing(randn, ComplexF64, P, V, E; χenv, unitcell=(1, 1)) -test_gauge_fixing(randn, ComplexF64, P, V, E; χenv, unitcell=(2, 2)) -test_gauge_fixing(randn, ComplexF64, P, V, E; χenv, unitcell=(3, 4)) # check gauge-fixing for unit cells > (2, 2) - -# Convergence of real CTMRG seems to be more sensitive to initial guess -test_gauge_fixing(randn, Float64, P, V, E; χenv, unitcell=(1, 1)) -test_gauge_fixing(randn, Float64, P, V, E; χenv, unitcell=(2, 2)) -test_gauge_fixing(randn, Float64, P, V, E; χenv, unitcell=(3, 4)) - -# Z2 - -P = Z2Space(0 => 1, 1 => 1) # physical space -V = Z2Space(0 => 2, 1 => 2) # PEPS virtual space -χenv = 20 # environment truncation dimension -E = Z2Space(0 => χenv / 2, 1 => χenv / 2) # environment virtual space - -test_gauge_fixing(randn, ComplexF64, P, V, E; χenv, unitcell=(1, 1)) -test_gauge_fixing(randn, ComplexF64, P, V, E; χenv, unitcell=(2, 2)) - -test_gauge_fixing(randn, Float64, P, V, E; χenv, unitcell=(1, 1)) -test_gauge_fixing(randn, Float64, P, V, E; χenv, unitcell=(2, 2)) diff --git a/examples/test_gradients.jl b/examples/test_gradients.jl deleted file mode 100644 index fde23330..00000000 --- a/examples/test_gradients.jl +++ /dev/null @@ -1,53 +0,0 @@ -using LinearAlgebra -using TensorKit, MPSKitModels, OptimKit -using PEPSKit, KrylovKit - -using Zygote - -# Square lattice Heisenberg Hamiltonian -function square_lattice_heisenberg(; Jx=-1.0, Jy=1.0, Jz=-1.0) - Sx, Sy, Sz, _ = spinmatrices(1//2) - Vphys = ℂ^2 - σx = TensorMap(Sx, Vphys, Vphys) - σy = TensorMap(Sy, Vphys, Vphys) - σz = TensorMap(Sz, Vphys, Vphys) - - @tensor H[-1 -3; -2 -4] := - Jx * σx[-1, -2] * σx[-3, -4] + - Jy * σy[-1, -2] * σy[-3, -4] + - Jz * σz[-1, -2] * σz[-3, -4] - - return NLocalOperator{NearestNeighbor}(H) -end - -# Initialize PEPS and environment -H = square_lattice_heisenberg() -χbond = 2 -χenv = 16 -boundary_alg = CTMRG(; - trscheme=truncdim(χenv), tol=1e-12, miniter=4, maxiter=100, verbosity=2 -) -ψ = InfinitePEPS(2, χbond) -env = leading_boundary(ψ, boundary_alg, CTMRGEnv(ψ; Venv=ℂ^χenv)) - -# Compute CTM gradient in four different ways (set reuse_env=false to not mutate environment) -function compute_grad(gradient_alg) - @info "FP gradient using $(gradient_alg):" - @time g = gradient(ψ) do peps - env′ = PEPSKit.hook_pullback( - leading_boundary, peps, boundary_alg, env; alg_rrule=gradient_alg - ) - return costfun(ψ, env′, H) - end - return only(g) -end - -gradtol = 1e-6 -g_naive = compute_grad(nothing) -g_geomsum = compute_grad(GeomSum(; tol=gradtol)) -g_maniter = compute_grad(ManualIter(; tol=gradtol)) -g_linsolve = compute_grad(KrylovKit.GMRES(; tol=gradtol)) - -@show norm(g_geomsum - g_naive) / norm(g_naive) -@show norm(g_maniter - g_naive) / norm(g_naive) -@show norm(g_linsolve - g_naive) / norm(g_naive) diff --git a/examples/test_vumps.jl b/examples/test_vumps.jl deleted file mode 100644 index b3492c2c..00000000 --- a/examples/test_vumps.jl +++ /dev/null @@ -1,8 +0,0 @@ -using Revise, PEPSKit, TensorKit, Zygote, MPSKit - -p = InfinitePEPS(fill(ℂ^2, 1, 1), fill(ℂ^2, 1, 1)); - -trans = PEPSKit.InfiniteTransferPEPS(p, 1, 1); -mps = PEPSKit.initializeMPS(trans, [ℂ^5]); - -leading_boundary(mps, trans, VUMPS())