From fcd60568bd8b80778e8b9eb9d61db0e478902717 Mon Sep 17 00:00:00 2001 From: Paul Brehmer Date: Tue, 14 May 2024 15:37:33 +0200 Subject: [PATCH] Stabilize tests by fixing seeds, reduce verbosity, use more elegant Heisenberg Hamiltonian --- Project.toml | 4 ++-- examples/heisenberg.jl | 21 ++++++++------------- test/boundarymps/vumps.jl | 6 ++++-- test/ctmrg/gaugefix.jl | 27 +++++++++------------------ test/ctmrg/gradients.jl | 22 ++++++++++------------ test/heisenberg.jl | 2 ++ 6 files changed, 35 insertions(+), 47 deletions(-) diff --git a/Project.toml b/Project.toml index e26bda03..bceab2ca 100644 --- a/Project.toml +++ b/Project.toml @@ -10,10 +10,10 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MPSKit = "bb1c41ca-d63c-52ed-829e-0820dda26502" -MPSKitModels = "ca635005-6f8c-4cd1-b51d-8491250ef2ab" OptimKit = "77e91f04-9b3b-57a6-a776-40b61faaebe0" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec" VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8" @@ -34,8 +34,8 @@ Zygote = "0.6" julia = "1.6" [extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test", "SafeTestsets"] diff --git a/examples/heisenberg.jl b/examples/heisenberg.jl index 736db6fa..94be4317 100644 --- a/examples/heisenberg.jl +++ b/examples/heisenberg.jl @@ -1,5 +1,5 @@ using LinearAlgebra -using TensorKit, MPSKitModels, OptimKit +using TensorKit, OptimKit using PEPSKit, KrylovKit # Square lattice Heisenberg Hamiltonian @@ -7,18 +7,13 @@ using PEPSKit, KrylovKit # the ground state in a single-site unit cell. This can be seen from # sublattice rotating H from parameters (1, 1, 1) to (-1, 1, -1). function square_lattice_heisenberg(; Jx=-1, Jy=1, Jz=-1) - 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) + physical_space = ComplexSpace(2) + T = ComplexF64 + σx = TensorMap(T[0 1; 1 0], physical_space, physical_space) + σy = TensorMap(T[0 im; -im 0], physical_space, physical_space) + σz = TensorMap(T[1 0; 0 -1], physical_space, physical_space) + H = (Jx * σx ⊗ σx) + (Jy * σy ⊗ σy) + (Jz * σz ⊗ σz) + return NLocalOperator{NearestNeighbor}(H / 4) end # Parameters diff --git a/test/boundarymps/vumps.jl b/test/boundarymps/vumps.jl index 0b2380f1..0d0efb1c 100644 --- a/test/boundarymps/vumps.jl +++ b/test/boundarymps/vumps.jl @@ -1,19 +1,21 @@ using Test +using Random using PEPSKit using TensorKit using MPSKit using LinearAlgebra +Random.seed!(29384293742893) psi = InfinitePEPS(ComplexSpace(2), ComplexSpace(2)) T = PEPSKit.InfiniteTransferPEPS(psi, 1, 1) mps = PEPSKit.initializeMPS(T, [ComplexSpace(8)]) -mps, envs, ϵ = leading_boundary(mps, T, VUMPS()) +mps, envs, ϵ = leading_boundary(mps, T, VUMPS(; verbosity=2)) N = sum(expectation_value(mps, T)) ctm = leading_boundary( - psi, CTMRG(; verbosity=2, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(8)) + psi, CTMRG(; verbosity=1, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(8)) ) N2 = norm(psi, ctm) diff --git a/test/ctmrg/gaugefix.jl b/test/ctmrg/gaugefix.jl index 15a0af73..7c7eaf0a 100644 --- a/test/ctmrg/gaugefix.jl +++ b/test/ctmrg/gaugefix.jl @@ -1,4 +1,5 @@ using Test +using Random using PEPSKit using TensorKit @@ -17,6 +18,7 @@ end @testset "Trivial symmetry ($T) - ($unitcell)" for (T, unitcell) in Iterators.product(scalartypes, unitcells) + Random.seed!(12345678) physical_space = ComplexSpace(2) peps_space = ComplexSpace(2) ctm_space = ComplexSpace(16) @@ -25,17 +27,11 @@ end psi = _make_symmetric(psi) ctm = CTMRGEnv(psi; Venv=ctm_space) + verbosity = 1 alg = CTMRG(; - trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=100, verbosity=2 - ) - alg_fixed = CTMRG(; - trscheme=truncdim(dim(ctm_space)), - tol=1e-10, - miniter=4, - maxiter=100, - verbosity=2, - fixedspace=true, + trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=200, verbosity ) + alg_fixed = CTMRG(; trscheme=truncdim(dim(ctm_space)), verbosity, fixedspace=true) ctm = leading_boundary(psi, alg, ctm) ctm2, = ctmrg_iter(psi, ctm, alg_fixed) @@ -45,6 +41,7 @@ end @testset "Z2 symmetry ($T) - ($unitcell)" for (T, unitcell) in Iterators.product(scalartypes, unitcells) + Random.seed!(12345678) physical_space = Z2Space(0 => 1, 1 => 1) peps_space = Z2Space(0 => 2, 1 => 2) ctm_space = Z2Space(0 => 8, 1 => 8) @@ -53,17 +50,11 @@ end psi = _make_symmetric(psi) ctm = CTMRGEnv(psi; Venv=ctm_space) + verbosity = 1 alg = CTMRG(; - trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=100, verbosity=2 - ) - alg_fixed = CTMRG(; - trscheme=truncdim(dim(ctm_space)), - tol=1e-10, - miniter=4, - maxiter=100, - verbosity=2, - fixedspace=true, + trscheme=truncdim(dim(ctm_space)), tol=1e-10, miniter=4, maxiter=200, verbosity ) + alg_fixed = CTMRG(; trscheme=truncdim(dim(ctm_space)), verbosity, fixedspace=true) ctm = leading_boundary(psi, alg, ctm) ctm2, = ctmrg_iter(psi, ctm, alg_fixed) diff --git a/test/ctmrg/gradients.jl b/test/ctmrg/gradients.jl index 47c2127b..4ebe3d46 100644 --- a/test/ctmrg/gradients.jl +++ b/test/ctmrg/gradients.jl @@ -1,24 +1,21 @@ using Test +using Random using PEPSKit using TensorKit using PEPSKit using Zygote using OptimKit using KrylovKit + # Square lattice Heisenberg Hamiltonian -function square_lattice_heisenberg(; Jx=-1.0, Jy=1.0, Jz=-1.0) +function square_lattice_heisenberg(; Jx=-1, Jy=1, Jz=-1) + physical_space = ComplexSpace(2) T = ComplexF64 - Vphys = ℂ^2 - σx = TensorMap(T[0 1; 1 0], Vphys, Vphys) - σy = TensorMap(T[0 im; -im 0], Vphys, Vphys) - σz = TensorMap(T[1 0; 0 -1], 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) + σx = TensorMap(T[0 1; 1 0], physical_space, physical_space) + σy = TensorMap(T[0 im; -im 0], physical_space, physical_space) + σz = TensorMap(T[1 0; 0 -1], physical_space, physical_space) + H = (Jx * σx ⊗ σx) + (Jy * σy ⊗ σy) + (Jz * σz ⊗ σz) + return NLocalOperator{NearestNeighbor}(H / 4) end h = TensorMap(randn, Float64, ComplexSpace(2)^2, ComplexSpace(2)^2) @@ -38,6 +35,7 @@ gradmodes = [nothing, GeomSum(; tol), ManualIter(; tol), KrylovKit.GMRES(; tol)] @testset "$alg_rrule" for alg_rrule in gradmodes # random point, random direction + Random.seed!(42039482038) dir = InfinitePEPS(2, χbond) psi = InfinitePEPS(2, χbond) env = leading_boundary(psi, boundary_alg, CTMRGEnv(psi; Venv=ℂ^χenv)) diff --git a/test/heisenberg.jl b/test/heisenberg.jl index b8c68398..888ac39b 100644 --- a/test/heisenberg.jl +++ b/test/heisenberg.jl @@ -1,4 +1,5 @@ using Test +using Random using PEPSKit using TensorKit using KrylovKit @@ -34,6 +35,7 @@ opt_alg = PEPSOptimize(; ) # initialize states +Random.seed!(91283219347) psi_init = InfinitePEPS(2, χbond) env_init = leading_boundary(psi_init, ctm_alg, CTMRGEnv(psi_init; Venv=ComplexSpace(χenv)))