diff --git a/src/algorithms/ctmrg.jl b/src/algorithms/ctmrg.jl index d9144827..f31eebad 100644 --- a/src/algorithms/ctmrg.jl +++ b/src/algorithms/ctmrg.jl @@ -182,7 +182,6 @@ function left_move(state, env::CTMRGEnv{C,T}, alg::ProjectorAlg) where {C,T} for col in 1:size(state, 2) cprev = _prev(col, size(state, 2)) - cnext = _next(col, size(state, 2)) # Compute projectors for row in 1:size(state, 1) diff --git a/src/algorithms/ctmrg_all_sides.jl b/src/algorithms/ctmrg_all_sides.jl index 046ae3ee..7a48ba1e 100644 --- a/src/algorithms/ctmrg_all_sides.jl +++ b/src/algorithms/ctmrg_all_sides.jl @@ -152,19 +152,19 @@ function renormalize_corners_edges(state, env::CTMRGEnv, Q, P_left, P_right) P_left[NORTH, r, c][χ2 D3 D4; χ_E] * P_right[NORTH, r, cprev][χ_W; χ1 D5 D6] @diffset @autoopt @tensor edges[EAST, r, c][χ_N D_Wab D_Wbe; χ_S] := - env.edges[EAST, r, _next(c, end)][χ1 D1 D2; χ2] * + env.edges[EAST, r, cnext][χ1 D1 D2; χ2] * state[r, c][d; D5 D1 D3 D_Wab] * conj(state[r, c][d; D6 D2 D4 D_Wbe]) * P_left[EAST, r, c][χ2 D3 D4; χ_S] * P_right[EAST, rprev, c][χ_N; χ1 D5 D6] @diffset @autoopt @tensor edges[SOUTH, r, c][χ_E D_Nab D_Nbe; χ_W] := - env.edges[SOUTH, _next(r, end), c][χ1 D1 D2; χ2] * + env.edges[SOUTH, rnext, c][χ1 D1 D2; χ2] * state[r, c][d; D_Nab D5 D1 D3] * conj(state[r, c][d; D_Nbe D6 D2 D4]) * P_left[SOUTH, r, c][χ2 D3 D4; χ_W] * P_right[SOUTH, r, cnext][χ_E; χ1 D5 D6] @diffset @autoopt @tensor edges[WEST, r, c][χ_S D_Eab D_Ebe; χ_N] := - env.edges[WEST, r, _prev(c, end)][χ1 D1 D2; χ2] * + env.edges[WEST, r, cprev][χ1 D1 D2; χ2] * state[r, c][d; D3 D_Eab D5 D1] * conj(state[r, c][d; D4 D_Ebe D6 D2]) * P_left[WEST, r, c][χ2 D3 D4; χ_N] * diff --git a/src/algorithms/ctmrg_gauge_fix.jl b/src/algorithms/ctmrg_gauge_fix.jl index fdf3dd91..b7925c58 100644 --- a/src/algorithms/ctmrg_gauge_fix.jl +++ b/src/algorithms/ctmrg_gauge_fix.jl @@ -6,7 +6,7 @@ This assumes that the `envfinal` is the result of one CTMRG iteration on `envpre Given that the CTMRG run is converged, the returned environment will be element-wise converged to `envprev`. """ -function gauge_fix(envprev::CTMRGEnv{C,T}, envfinal::CTMRGEnv{C,T}) where {C,T} +function gauge_fix(envprev::CTMRGEnv{C,T}, envfinal::CTMRGEnv{C′,T′}) where {C,C′,T,T′} # Check if spaces in envprev and envfinal are the same same_spaces = map(Iterators.product(axes(envfinal.edges)...)) do (dir, r, c) space(envfinal.edges[dir, r, c]) == space(envprev.edges[dir, r, c]) && @@ -189,14 +189,12 @@ function check_elementwise_convergence( ΔC = envfinal.corners .- envfix.corners ΔCmax = norm(ΔC, Inf) ΔCmean = norm(ΔC) - # @debug "maxᵢⱼ|Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmax mean |Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmean" - println("maxᵢⱼ|Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmax mean |Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmean") + @debug "maxᵢⱼ|Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmax mean |Cⁿ⁺¹ - Cⁿ|ᵢⱼ = $ΔCmean" ΔT = envfinal.edges .- envfix.edges ΔTmax = norm(ΔT, Inf) ΔTmean = norm(ΔT) - # @debug "maxᵢⱼ|Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmax mean |Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmean" - println("maxᵢⱼ|Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmax mean |Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmean") + @debug "maxᵢⱼ|Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmax mean |Tⁿ⁺¹ - Tⁿ|ᵢⱼ = $ΔTmean" # Check differences for all tensors in unit cell to debug properly for (dir, r, c) in Iterators.product(axes(envfinal.edges)...) diff --git a/test/ctmrg/gaugefix.jl b/test/ctmrg/gaugefix.jl index 10a5e17e..f56ab00d 100644 --- a/test/ctmrg/gaugefix.jl +++ b/test/ctmrg/gaugefix.jl @@ -2,86 +2,57 @@ using Test using Random using PEPSKit using TensorKit -using Accessors using PEPSKit: ctmrg_iter, gauge_fix, check_elementwise_convergence scalartypes = [Float64, ComplexF64] unitcells = [(1, 1), (2, 2), (3, 2)] -# scalartypes = [ComplexF64] -# unitcells = [(2, 2)] -χ = 6 - -function _make_symmetric(psi) - if ==(size(psi)...) - return PEPSKit.symmetrize(psi, PEPSKit.Full()) - else - return PEPSKit.symmetrize(PEPSKit.symmetrize(psi, PEPSKit.Depth()), PEPSKit.Width()) - end -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 - end - return InfinitePEPS(A′) -end +χ = Dict([(1, 1) => 8, (2, 2) => 26, (3, 2) => 26]) # Increase χ to converge non-symmetric environments @testset "Trivial symmetry ($T) - ($unitcell)" for (T, unitcell) in Iterators.product(scalartypes, unitcells) physical_space = ComplexSpace(2) peps_space = ComplexSpace(2) - ctm_space = ComplexSpace(χ) + ctm_space = ComplexSpace(χ[unitcell]) - psi = InfinitePEPS(undef, T, physical_space, peps_space; unitcell) - semi_random_peps!(psi) - psi = _make_symmetric(psi) - - Random.seed!(987654321) # Seed RNG to make random environment consistent - # psi = InfinitePEPS(physical_space, peps_space; unitcell) + Random.seed!(2938293852938) # Seed RNG to make random environment consistent + psi = InfinitePEPS(randn, T, physical_space, peps_space; unitcell) ctm = CTMRGEnv(psi; Venv=ctm_space) - verbosity = 1 alg = CTMRG(; - tol=1e-10, miniter=4, maxiter=5000, verbosity, trscheme=FixedSpaceTruncation() + tol=1e-10, + maxiter=100, + verbosity=1, + trscheme=FixedSpaceTruncation(), + ctmrgscheme=:AllSides, # In general :AllSides is faster ) ctm = leading_boundary(ctm, psi, alg) ctm2, = ctmrg_iter(psi, ctm, alg) ctm_fixed, = gauge_fix(ctm, ctm2) - @test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-4) + @test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-6) end @testset "Z2 symmetry ($T) - ($unitcell)" for (T, unitcell) in Iterators.product(scalartypes, unitcells) 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) - psi = _make_symmetric(psi) + ctm_space = Z2Space(0 => χ[(1, 1)] ÷ 2, 1 => χ[(1, 1)] ÷ 2) - Random.seed!(123456789) # Seed RNG to make random environment consistent + Random.seed!(2938293852938) # Seed RNG to make random environment consistent + psi = InfinitePEPS(physical_space, peps_space; unitcell) ctm = CTMRGEnv(psi; Venv=ctm_space) - verbosity = 1 alg = CTMRG(; - tol=1e-10, miniter=4, maxiter=400, verbosity, trscheme=truncdim(dim(ctm_space)) - ) - alg_fixed = CTMRG(; - verbosity, svd_alg=alg.projector_alg.svd_alg, trscheme=FixedSpaceTruncation() + tol=1e-10, + maxiter=400, + verbosity=1, + trscheme=FixedSpaceTruncation(), + ctmrgscheme=:LeftMoves, # Weirdly, only :LeftMoves converges ) ctm = leading_boundary(ctm, psi, alg) - ctm2, = ctmrg_iter(psi, ctm, alg_fixed) + ctm2, = ctmrg_iter(psi, ctm, alg) ctm_fixed, = gauge_fix(ctm, ctm2) - @test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-4) + @test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-6) end