Skip to content

Commit a42e715

Browse files
committed
small fixes
1 parent 0979971 commit a42e715

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/environments/bp_environments.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ Base.eachindex(env::BPEnv) = eachindex(IndexCartesian(), env.messages)
140140
VectorInterface.scalartype(::Type{BPEnv{T}}) where {T} = scalartype(T)
141141
TensorKit.spacetype(::Type{BPEnv{T}}) where {T} = spacetype(T)
142142

143+
function eachcoordinate(x::BPEnv)
144+
return collect(Iterators.product(axes(x, 2), axes(x, 3)))
145+
end
146+
function eachcoordinate(x::BPEnv, dirs)
147+
return collect(Iterators.product(dirs, axes(x, 2), axes(x, 3)))
148+
end
149+
143150
# conversion to CTMRGEnv
144151
"""
145152
CTMRGEnv(bp_env::BPEnv)

test/bp/gaugefix.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Test
1+
using Test, TestExtras
22
using Random
33
using TensorKit
44
using PEPSKit
@@ -10,10 +10,10 @@ A dummy Hamiltonian containing identity gates on all nearest neighbor bonds.
1010
function 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
4747
end
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
@@ -57,17 +59,21 @@ end
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
7379
end

test/bp/unitcell.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ stype = ComplexF64
1111
function test_unitcell(unitcell, Pspaces, Nspaces, Espaces)
1212
peps = InfinitePEPS(randn, stype, Pspaces, Nspaces, Espaces)
1313
env0 = BPEnv(ones, stype, peps)
14+
alg = BeliefPropagation()
1415

1516
# apply one BP iteration
16-
env1 = bp_iteration(InfiniteSquareNetwork(peps), env0)
17+
env1 = bp_iteration(InfiniteSquareNetwork(peps), env0, alg)
1718
# another iteration to detect bond mismatches
18-
env1 = bp_iteration(InfiniteSquareNetwork(peps), env1)
19+
env1 = bp_iteration(InfiniteSquareNetwork(peps), env1, alg)
1920

2021
# compute random expecation value to test matching bonds
2122
random_op = LocalOperator(

0 commit comments

Comments
 (0)