From 45456f008b9cd4348ea97ecc1c6a742814e31ced Mon Sep 17 00:00:00 2001 From: Paul Brehmer Date: Tue, 10 Dec 2024 15:13:12 +0100 Subject: [PATCH] Update gaugefix test again --- test/ctmrg/gaugefix.jl | 86 +++++++++++++----------------------------- 1 file changed, 27 insertions(+), 59 deletions(-) diff --git a/test/ctmrg/gaugefix.jl b/test/ctmrg/gaugefix.jl index 7c2aae1e..048d875d 100644 --- a/test/ctmrg/gaugefix.jl +++ b/test/ctmrg/gaugefix.jl @@ -5,78 +5,46 @@ using TensorKit using PEPSKit: ctmrg_iteration, gauge_fix, calc_elementwise_convergence +spacetypes = [ComplexSpace, Z2Space] scalartypes = [Float64, ComplexF64] unitcells = [(1, 1), (2, 2), (3, 2)] -maxiter = 400 ctmrg_algs = [SequentialCTMRG, SimultaneousCTMRG] projector_algs = [HalfInfiniteProjector, FullInfiniteProjector] -χ = 8 +χ = 6 atol = 1e-4 -function _make_symmetric!(psi) - if ==(size(psi)...) - return symmetrize!(psi, RotateReflect()) - else - return symmetrize!(symmetrize!(psi, ReflectDepth()), ReflectWidth()) - end +function _pre_converge_env( + ::Type{T}, physical_space, peps_space, ctm_space, unitcell; seed=12345 +) where {T} + Random.seed!(seed) # Seed RNG to make random environment consistent + psi = InfinitePEPS(rand, T, physical_space, peps_space; unitcell) + env₀ = CTMRGEnv(psi, ctm_space) + env_conv = leading_boundary(env₀, psi, SequentialCTMRG()) + return env_conv, psi end -# If I can't make the rng seed behave, I'll just randomly define a peps somehow -function _semi_random_peps!(psi::InfinitePEPS) - i = 0 - A′ = map(psi.A) do a - for (_, b) in blocks(a) - l = length(b) - b .= reshape(collect((1:l) .+ i), size(b)) - i += l - end - return a +# pre-converge CTMRG environments with given spacetype, scalartype and unit cell +preconv = Dict() +for (S, T, unitcell) in Iterators.product(spacetypes, scalartypes, unitcells) + if S == ComplexSpace + result = _pre_converge_env(T, S(2), S(2), S(χ), unitcell) + elseif S == Z2Space + result = _pre_converge_env( + T, S(0 => 1, 1 => 1), S(0 => 1, 1 => 1), S(0 => χ ÷ 2, 1 => χ ÷ 2), unitcell + ) end - return InfinitePEPS(A′) -end - -@testset "Trivial symmetry ($T) - ($unitcell) - ($ctmrg_alg) - ($projector_alg)" for ( - T, unitcell, ctmrg_alg, projector_alg -) in Iterators.product( - scalartypes, unitcells, ctmrg_algs, projector_algs -) - physical_space = ComplexSpace(2) - peps_space = ComplexSpace(2) - ctm_space = ComplexSpace(χ) - - psi = InfinitePEPS(undef, T, physical_space, peps_space; unitcell) - _semi_random_peps!(psi) - _make_symmetric!(psi) - - Random.seed!(987654321) # Seed RNG to make random environment consistent - env = CTMRGEnv(psi, ctm_space) - alg = ctmrg_alg(; maxiter, projector_alg) - - env = leading_boundary(env, psi, alg) - env′, = ctmrg_iteration(psi, env, alg) - env_fixed, = gauge_fix(env, env′) - @test calc_elementwise_convergence(env, env_fixed) ≈ 0 atol = atol + push!(preconv, (S, T, unitcell) => result) end -@testset "Z2 symmetry ($T) - ($unitcell) - ($ctmrg_alg) - ($projector_alg)" for ( - T, unitcell, ctmrg_alg, projector_alg +@testset "($S) - ($T) - ($unitcell) - ($ctmrg_alg) - ($projector_alg)" for ( + S, T, unitcell, ctmrg_alg, projector_alg ) in Iterators.product( - scalartypes, unitcells, ctmrg_algs, projector_algs + spacetypes, scalartypes, unitcells, ctmrg_algs, projector_algs ) - physical_space = Z2Space(0 => 1, 1 => 1) - peps_space = Z2Space(0 => 1, 1 => 1) - ctm_space = Z2Space(0 => χ ÷ 2, 1 => χ ÷ 2) - - psi = InfinitePEPS(undef, T, physical_space, peps_space; unitcell) - _semi_random_peps!(psi) - _make_symmetric!(psi) - - Random.seed!(29385293852) # Seed RNG to make random environment consistent - psi = InfinitePEPS(physical_space, peps_space; unitcell) - env = CTMRGEnv(psi, ctm_space) - alg = ctmrg_alg(; maxiter, projector_alg) - - env = leading_boundary(env, psi, alg) + alg = ctmrg_alg(; projector_alg) + env_pre, psi = preconv[(S, T, unitcell)] + env_pre + env = leading_boundary(env_pre, psi, alg) env′, = ctmrg_iteration(psi, env, alg) env_fixed, = gauge_fix(env, env′) @test calc_elementwise_convergence(env, env_fixed) ≈ 0 atol = atol