Skip to content

Commit 2b227c1

Browse files
committed
add tests for bp gauge
1 parent 7104084 commit 2b227c1

5 files changed

Lines changed: 55 additions & 9 deletions

File tree

src/BPGauge.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export bp!, bp_update!
1111
export absorb!
1212
export apply_gauge!, gauge!
1313

14+
export chain, square_lattice
15+
1416
include("utils.jl")
1517

1618
# define and construct the network
@@ -19,7 +21,10 @@ include("ansatz.jl")
1921
# bp on the tensor network ansatz
2022
include("bp.jl")
2123

22-
# operations about gauging``
24+
# operations about gauging
2325
include("gauge.jl")
2426

27+
# simple update
28+
include("su.jl")
29+
2530
end

src/su.jl

Whitespace-only changes.

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ function square_lattice(mx::Int, my::Int, p::Float64; seed::Int = 1234)
2020
return g
2121
end
2222

23+
function chain(n::Int)
24+
g = SimpleGraph(n)
25+
for i in 1:n-1
26+
add_edge!(g, i, i+1)
27+
end
28+
return g
29+
end
30+
2331
# codes about constructing the einsum expression
2432

2533
function all_eins(g::SimpleGraph{Int}, count::Int)

test/bp.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ using Test
2424
end
2525

2626
@testset "1d chain" begin
27-
function chain(n::Int)
28-
g = SimpleGraph(n)
29-
for i in 1:n - 1
30-
add_edge!(g, i, i + 1)
31-
end
32-
return g
33-
end
34-
3527
g = chain(10)
3628
for d in [2, 3, 10]
3729
tn = random_state(g, d_virtual = 3)

test/gauge.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using BPGauge
22
using Graphs, LinearAlgebra, OMEinsum
33
using Test
44

5+
using BPGauge: square_root
6+
57
@testset "absorb" begin
68
for g in [random_regular_graph(30, 3), BPGauge.square_lattice(10, 10, 0.8)]
79
tn = random_state(g, d_virtual = 2)
@@ -62,4 +64,43 @@ end
6264

6365
gauge!(tn, bp_state)
6466
@test inner_product(tn, adjoint(tn)) 1.0
67+
end
68+
69+
@testset "guage mps" begin
70+
g = chain(100)
71+
tn = random_state(g, d_virtual = 8)
72+
normalize_state!(tn)
73+
74+
bp_state = BPState(tn)
75+
bp_path = BPPath(tn)
76+
bp!(bp_state, bp_path, tn, verbose = true, err_bound = 1e-14)
77+
78+
gauge!(tn, bp_state)
79+
80+
for i in 1:nv(g) - 2
81+
G = tn.gauge_tensors[tn.gauge_tensors_map[(i, i + 1)]]
82+
T = tn.site_tensors[i + 1]
83+
L = ein"ij, jk, jln, kmn -> lm"(G, G, T, conj(T))
84+
@show i, maximum(abs.(L ./ L[1, 1] - I(size(L, 1))))
85+
end
86+
end
87+
88+
89+
@testset "Vidal gauge" begin
90+
g = chain(100)
91+
tn = random_state(g, d_virtual = 8)
92+
normalize_state!(tn)
93+
94+
bp_state = BPState(tn)
95+
bp_path = BPPath(tn)
96+
bp!(bp_state, bp_path, tn, err_bound = 1e-14)
97+
98+
gauge!(tn, bp_state)
99+
100+
for i in 2:nv(g) - 2
101+
G = tn.gauge_tensors[tn.gauge_tensors_map[(i, i + 1)]]
102+
T = tn.site_tensors[i + 1]
103+
L = ein"ij, jk, jln, kmn -> lm"(G, G, T, conj(T))
104+
@test maximum(abs.(L ./ L[1, 1] - I(size(L, 1)))) < 1e-6
105+
end
65106
end

0 commit comments

Comments
 (0)