1- using Test
1+ using Test, TestExtras
22using Random
33using TensorKit
44using PEPSKit
@@ -10,10 +10,10 @@ A dummy Hamiltonian containing identity gates on all nearest neighbor bonds.
1010function dummy_ham (elt:: Type{<:Number} , lattice:: Matrix{S} ) where {S <: ElementarySpace }
1111 terms = []
1212 for site1 in CartesianIndices (lattice)
13- r1, c1 = ( mod1 (x, N) for (x, N) in zip ( site1. I , size (lattice) ))
13+ r1, c1 = mod1 .( Tuple ( site1) , size (lattice))
1414 for d in (CartesianIndex (1 , 0 ), CartesianIndex (0 , 1 ))
1515 site2 = site1 + d
16- r2, c2 = ( mod1 (x, N) for (x, N) in zip ( site2. I , size (lattice) ))
16+ r2, c2 = mod1 .( Tuple ( site2) , size (lattice))
1717 V1, V2 = lattice[r1, c1], lattice[r2, c2]
1818 h = TensorKit. id (elt, V1 ⊗ V2)
1919 push! (terms, (site1, site2) => h)
@@ -46,6 +46,8 @@ function gauge_fix_su(peps::InfinitePEPS; maxiter::Int = 100, tol::Float64 = 1.0
4646 return
4747end
4848
49+ isapproxone (X; kwargs... ) = isapprox (X, id! (similar (X)); kwargs... )
50+
4951@testset " Compare BP and SU (no symmetry)" begin
5052 unitcell = (3 , 3 )
5153 stype = ComplexF64
5759 Espaces = random_dual! (ComplexSpace .(rand (2 : 4 , unitcell... )))
5860 peps = InfinitePEPS (randn, stype, Pspaces, Nspaces, Espaces)
5961
62+ # start by gauging with SU
6063 peps1, wts1 = gauge_fix_su (peps; maxiter, tol)
61- @test all (space .(peps1. A) .== space .(peps. A))
64+ for (a1, a2) in zip (peps1. A, peps. A)
65+ @test space (a1) == space (a2)
66+ end
6267 normalize! .(wts1. data)
6368
69+ # gauging again with BP should give unitary gauge
6470 bp_alg = BeliefPropagation (; maxiter, tol)
6571 env0 = BPEnv (ones, stype, peps)
66- peps2, wts2 = gauge_fix (peps , bp_alg, env0)
67- @test all ( space .(peps2 . A) .== space .( peps. A) )
68- normalize! .(wts2 . data )
69-
70- # Even with the same bond weights, the PEPS can still
71- # differ by a unitary gauge transformation on virtual legs.
72- @test isapprox (wts1, wts2)
72+ peps2, XXinv, env = @constinferred gauge_fix (peps1 , bp_alg, env0)
73+ for (a1, a2) in zip (peps1 . A, peps. A)
74+ @test space (a1) == space (a2 )
75+ end
76+ for (X, Xinv) in XXinv
77+ @test inv (X) ≈ adjoint (X) ≈ Xinv
78+ end
7379end
0 commit comments