Skip to content

Commit 9258396

Browse files
committed
Add add_bwt option to NTU bondenv
1 parent a57d4f6 commit 9258396

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

src/algorithms/contractions/bondenv/benv_ntu.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Construct the "NTU-NN" bond environment.
2020
(+1 +0)══(+1 +1)
2121
```
2222
"""
23-
struct NTUEnvNN <: NTUEnvAlgorithm end
23+
@kwdef struct NTUEnvNN <: NTUEnvAlgorithm
24+
add_bwt::Bool = true
25+
end
2426
"""
2527
Calculate the bond environment within "NTU-NN" approximation.
2628
"""
2729
function bondenv_ntu(
28-
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, ::NTUEnvNN
30+
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, alg::NTUEnvNN
2931
) where {T<:Union{PEPSTensor,PEPSOrth}}
3032
neighbors = [
3133
(-1, 0, [NORTH, WEST]),
@@ -35,7 +37,7 @@ function bondenv_ntu(
3537
(0, 2, [NORTH, EAST, SOUTH]),
3638
(-1, 1, [NORTH, EAST]),
3739
]
38-
m = collect_neighbors(peps, row, col, neighbors)
40+
m = collect_neighbors(peps, row, col, neighbors, alg.add_bwt)
3941
#= contraction indices
4042
4143
(-1 +0) ══ Dn ══ (-1 +1)
@@ -75,12 +77,14 @@ Construct the "NTU-NNN" bond environment.
7577
(+1 -1)=(+1 +0)══(+1 +1)=(+1 +2)
7678
```
7779
"""
78-
struct NTUEnvNNN <: NTUEnvAlgorithm end
80+
@kwdef struct NTUEnvNNN <: NTUEnvAlgorithm
81+
add_bwt::Bool = true
82+
end
7983
"""
8084
Calculates the bond environment within "NTU-NNN" approximation.
8185
"""
8286
function bondenv_ntu(
83-
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, ::NTUEnvNNN
87+
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, alg::NTUEnvNNN
8488
) where {T<:Union{PEPSTensor,PEPSOrth}}
8589
neighbors = [
8690
(-1, -1, [NORTH, WEST]),
@@ -94,7 +98,7 @@ function bondenv_ntu(
9498
(-1, 1, [NORTH]),
9599
(-1, 0, [NORTH]),
96100
]
97-
m = collect_neighbors(peps, row, col, neighbors)
101+
m = collect_neighbors(peps, row, col, neighbors, alg.add_bwt)
98102
#= left half
99103
(-1 -1)══════(-1 +0)═ -1/-2
100104
║ ║
@@ -144,12 +148,14 @@ Construct the "NTU-NNN+" bond environment.
144148
(+2 -1) (+2 +0) (+2 +1) (+2 +2)
145149
```
146150
"""
147-
struct NTUEnvNNNp <: NTUEnvAlgorithm end
151+
@kwdef struct NTUEnvNNNp <: NTUEnvAlgorithm
152+
add_bwt::Bool = true
153+
end
148154
"""
149155
Calculates the bond environment within "NTU-NNN+" approximation.
150156
"""
151157
function bondenv_ntu(
152-
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, ::NTUEnvNNNp
158+
row::Int, col::Int, X::T, Y::T, peps::InfiniteWeightPEPS, alg::NTUEnvNNNp
153159
) where {T<:Union{PEPSTensor,PEPSOrth}}
154160
EMPTY = Vector{Int}()
155161
neighbors = [
@@ -178,7 +184,7 @@ function bondenv_ntu(
178184
(2, 1, [EAST, SOUTH, WEST]),
179185
(2, 2, [EAST, SOUTH, WEST]),
180186
]
181-
m = collect_neighbors(peps, row, col, neighbors)
187+
m = collect_neighbors(peps, row, col, neighbors, alg.add_bwt)
182188
#= left half
183189
(-2 -1) (-2 +0)
184190
║ ║

src/algorithms/contractions/bondenv/benv_tools.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ function collect_neighbors(
3131
row::Int,
3232
col::Int,
3333
neighbors::Vector{Tuple{Int,Int,Vector{Int}}},
34+
add_bwt::Bool=true,
3435
)
3536
Nr, Nc = size(peps)
3637
axs = Tuple(1:4)
3738
return Dict(
3839
(x, y) => begin
3940
r, c = mod1(row + x, Nr), mod1(col + y, Nc)
40-
sqrts = Tuple(!(ax in open_axs) for ax in 1:4)
41+
sqrts = if add_bwt
42+
Tuple(!(ax in open_axs) for ax in 1:4)
43+
else
44+
ntuple(Returns(true), 4)
45+
end
4146
_absorb_weights(peps.vertices[r, c], peps.weights, r, c, axs, sqrts, false)
4247
end for (x, y, open_axs) in neighbors
4348
)

test/bondenv/benv_ntu.jl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,37 @@ using Random
88
Nr, Nc = 2, 2
99
Random.seed!(20)
1010
Pspace = Vect[FermionParity](0 => 1, 1 => 1)
11-
V2 = Vect[FermionParity](0 => 1, 1 => 1)
12-
V3 = Vect[FermionParity](0 => 1, 1 => 2)
11+
V2 = Vect[FermionParity](0 => 4, 1 => 1)
12+
V3 = Vect[FermionParity](0 => 3, 1 => 2)
1313
V4 = Vect[FermionParity](0 => 2, 1 => 2)
14-
V5 = Vect[FermionParity](0 => 3, 1 => 2)
15-
W1 = Vect[FermionParity](0 => 2, 1 => 3)
16-
W2 = Vect[FermionParity](0 => 4, 1 => 1)
14+
V5 = Vect[FermionParity](0 => 2, 1 => 3)
1715
Pspaces = fill(Pspace, (Nr, Nc))
1816
Nspaces = [V2 V2; V4 V4]
1917
Espaces = [V3 V5; V5 V3]
2018

2119
peps = InfiniteWeightPEPS(randn, ComplexF64, Pspaces, Nspaces, Espaces)
22-
for I in CartesianIndices(peps.vertices)
23-
peps.vertices[I] /= norm(peps.vertices[I], Inf)
20+
normalize!.(peps.vertices, Inf)
21+
for wt in peps.weights
22+
wt.data[:] = normalize(rand(length(wt.data)), Inf)
2423
end
25-
# The NTU bond environments are constructed exactly
26-
# and should be positive definite
27-
for env_alg in (NTUEnvNN(), NTUEnvNNN(), NTUEnvNNNp())
28-
@info "Testing $(typeof(env_alg))"
29-
for row in 1:Nr, col in 1:Nc
30-
cp1 = PEPSKit._next(col, Nc)
31-
A, B = peps.vertices[row, col], peps.vertices[row, cp1]
32-
X, a, b, Y = PEPSKit._qr_bond(A, B)
33-
benv = PEPSKit.bondenv_ntu(row, col, X, Y, peps, env_alg)
34-
# benv should be Hermitian
35-
@test benv' ≈ benv
36-
# benv should be positive definite
37-
D, U = eigh(benv)
38-
@test all(all(x -> x >= 0, diag(b)) for (k, b) in blocks(D))
24+
for add_bwt in (true, false)
25+
for env_alg in (NTUEnvNN(; add_bwt), NTUEnvNNN(; add_bwt), NTUEnvNNNp(; add_bwt))
26+
@info "Testing $(typeof(env_alg))"
27+
for row in 1:Nr, col in 1:Nc
28+
cp1 = PEPSKit._next(col, Nc)
29+
A, B = peps.vertices[row, col], peps.vertices[row, cp1]
30+
X, a, b, Y = PEPSKit._qr_bond(A, B)
31+
@tensor ab[DX DY; da db] := a[DX da D] * b[D db DY]
32+
benv = PEPSKit.bondenv_ntu(row, col, X, Y, peps, env_alg)
33+
# NTU bond environments are constructed exactly
34+
# and should be positive definite
35+
@test benv' ≈ benv
36+
@assert [isdual(space(benv, ax)) for ax in 1:numind(benv)] == [0, 0, 1, 1]
37+
nrm1 = PEPSKit.inner_prod(benv, ab, ab)
38+
@test nrm1 ≈ real(nrm1)
39+
D, U = eigh(benv)
40+
@test all(all(x -> x >= 0, diag(b)) for (k, b) in blocks(D))
41+
@assert benv ≈ U * D * U'
42+
end
3943
end
4044
end

0 commit comments

Comments
 (0)