Skip to content

Commit e175131

Browse files
authored
Small fixes for InfiniteSquareNetwork and InfinitePartitionFunction (#306)
* Fix `TensorKit.spacetype` and `TensorKit.sectortype` for `InfiniteSquareNetwork` * Fix random `InfinitePartitionFunction` constructor * Set up test stubs for types and add some coverage already * Add a few more small tests * Fix typo
1 parent 9d9f163 commit e175131

File tree

11 files changed

+124
-12
lines changed

11 files changed

+124
-12
lines changed

.github/workflows/Tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- 'lts' # minimal supported version
2727
- '1'
2828
group:
29+
- types
2930
- ctmrg
3031
- boundarymps
3132
- gradients

src/networks/infinitesquarenetwork.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ end
5555

5656
## Spaces
5757

58+
TensorKit.spacetype(::Type{T}) where {T <: InfiniteSquareNetwork} = spacetype(eltype(T))
5859
function virtualspace(n::InfiniteSquareNetwork, r::Int, c::Int, dir)
5960
Nr, Nc = size(n)
6061
return virtualspace(n[mod1(r, Nr), mod1(c, Nc)], dir)
@@ -98,7 +99,7 @@ function Base.:(==)(A₁::InfiniteSquareNetwork, A₂::InfiniteSquareNetwork)
9899
end
99100
function Base.isapprox(A₁::InfiniteSquareNetwork, A₂::InfiniteSquareNetwork; kwargs...)
100101
return all(zip(unitcell(A₁), unitcell(A₂))) do (p₁, p₂)
101-
return isapprox(p₁, p₂; kwargs...)
102+
return _isapprox_localsandwich(p₁, p₂; kwargs...)
102103
end
103104
end
104105

src/networks/local_sandwich.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ _rot180_localsandwich(O) = rot180.(O)
3131
_add_localsandwich(O1, O2) = O1 .+ O2
3232
_subtract_localsandwich(O1, O2) = O1 .- O2
3333
_mul_localsandwich(α::Number, O) = α .* O
34+
_isapprox_localsandwich(O1, O2; kwargs...) = all(isapprox.(O1, O2; kwargs...))
3435

3536
## PartitionFunction
3637

@@ -43,6 +44,7 @@ _rot180_localsandwich(O::PFTensor) = rot180(O)
4344
_add_localsandwich(O1::PFTensor, O2::PFTensor) = O1 + O2
4445
_subtract_localsandwich(O1::PFTensor, O2::PFTensor) = O1 - O2
4546
_mul_localsandwich(α::Number, O::PFTensor) = α * O
47+
_isapprox_localsandwich(O1::PFTensor, O2::PFTensor; kwargs...) = isapprox(O1, O2; kwargs...)
4648

4749
## PEPS
4850

@@ -55,6 +57,8 @@ function virtualspace(O::PEPSSandwich, dir)
5557
return virtualspace(ket(O), dir) virtualspace(bra(O), dir)'
5658
end
5759

60+
TensorKit.spacetype(::Type{P}) where {P <: PEPSSandwich} = spacetype(eltype(P))
61+
5862
# not overloading MPOTensor because that defines AbstractTensorMap{<:Any,S,2,2}(::PEPSTensor, ::PEPSTensor)
5963
# ie type piracy
6064
mpotensor(top::PEPSTensor) = mpotensor((top, top))
@@ -106,3 +110,5 @@ function virtualspace(O::PEPOSandwich, dir)
106110
]
107111
)
108112
end
113+
114+
TensorKit.spacetype(::Type{P}) where {P <: PEPOSandwich} = spacetype(eltype(P))

src/networks/tensors.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ and west spaces, respectively.
2222
const PartitionFunctionTensor{S <: ElementarySpace} = AbstractTensorMap{<:Any, S, 2, 2}
2323
const PFTensor = PartitionFunctionTensor
2424

25+
"""
26+
PartitionFunctionTensor(f, ::Type{T}, Pspace::S, Nspace::S,
27+
[Espace::S], [Sspace::S], [Wspace::S]) where {T,S<:Union{Int,ElementarySpace}}
28+
29+
Construct a PartitionFunctionTensor tensor based on the north, east, west and south spaces.
30+
The tensor elements are generated based on `f` and the element type is specified in `T`.
31+
"""
32+
function PartitionFunctionTensor(
33+
f, ::Type{T},
34+
Nspace::S, Espace::S = Nspace, Sspace::S = Nspace, Wspace::S = Espace,
35+
) where {T, S <: ElementarySpace}
36+
return f(T, Wspace Sspace Nspace Espace)
37+
end
38+
2539
Base.rotl90(t::PFTensor) = permute(t, ((3, 1), (4, 2)))
2640
Base.rotr90(t::PFTensor) = permute(t, ((2, 4), (1, 3)))
2741
Base.rot180(t::PFTensor) = permute(t, ((4, 3), (2, 1)))

src/states/infinitepartitionfunction.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ function InfinitePartitionFunction(
5555
size(Nspaces) == size(Espaces) ||
5656
throw(ArgumentError("Input spaces should have equal sizes."))
5757

58-
Sspaces = adjoint.(circshift(Nspaces, (-1, 0)))
59-
Wspaces = adjoint.(circshift(Espaces, (0, 1)))
58+
Sspaces = circshift(Nspaces, (-1, 0))
59+
Wspaces = circshift(Espaces, (0, 1))
6060

61-
A = map(Nspaces, Espaces, Sspaces, Wspaces) do P, N, E, S, W
61+
A = map(Nspaces, Espaces, Sspaces, Wspaces) do N, E, S, W
6262
return PartitionFunctionTensor(f, T, N, E, S, W)
6363
end
6464

test/runtests.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ else
1010
end
1111

1212
@time begin
13+
if GROUP == "ALL" || GROUP == "TYPES"
14+
@time @safetestset "InfiniteSquareNetwork" begin
15+
include("types/infinitesquarenetwork.jl")
16+
end
17+
@time @safetestset "InfinitePartitionFunction" begin
18+
include("types/infinitepartitionfunction.jl")
19+
end
20+
@time @safetestset "SUWeight" begin
21+
include("types/suweight.jl")
22+
end
23+
@time @safetestset "LocalOperator" begin
24+
include("types/localoperator.jl")
25+
end
26+
end
1327
if GROUP == "ALL" || GROUP == "CTMRG"
1428
@time @safetestset "Gauge Fixing" begin
1529
include("ctmrg/gaugefix.jl")
@@ -77,9 +91,6 @@ end
7791
end
7892
end
7993
if GROUP == "ALL" || GROUP == "UTILITY"
80-
@time @safetestset "LocalOperator" begin
81-
include("utility/localoperator.jl")
82-
end
8394
@time @safetestset "SVD wrapper" begin
8495
include("utility/svd_wrapper.jl")
8596
end
@@ -92,9 +103,6 @@ end
92103
@time @safetestset "Norm-preserving retractions" begin
93104
include("utility/retractions.jl")
94105
end
95-
@time @safetestset "Rotation of SUWeight" begin
96-
include("utility/suweight_rotation.jl")
97-
end
98106
@time @safetestset "Correlators" begin
99107
include("utility/correlator.jl")
100108
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Test
2+
using TensorKit
3+
using PEPSKit
4+
using PEPSKit: PFTensor
5+
6+
T = ComplexF64
7+
Ss = [Trivial, U1Irrep]
8+
Vs = [ComplexSpace(3), U1Space(0 => 2, -1 => 1, 1 => 1)]
9+
10+
sizes = [(1, 1), (3, 3)]
11+
12+
@testset "$(sz) InfinitePartitionFunction with $(Ss[i]) symmetry" for (i, sz) in
13+
Iterators.product(eachindex(Ss), sizes)
14+
15+
S = Ss[i]
16+
V = Vs[i]
17+
18+
pf = InfinitePartitionFunction(randn, T, V; unitcell = sz)
19+
20+
@test scalartype(pf) == T
21+
@test eltype(pf) <: PFTensor{typeof(V)}
22+
@test spacetype(pf) == typeof(V)
23+
24+
@test (rotl90 rotl90)(pf) rot180(pf)
25+
@test (rotr90 rotr90 rotr90)(pf) rotl90(pf)
26+
@test length(pf) == prod(sz)
27+
end
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Test
2+
using TensorKit
3+
using PEPSKit
4+
using PEPSKit: PEPSTensor, PFTensor, PEPSSandwich, PEPOSandwich
5+
6+
T = ComplexF64
7+
Ss = [Trivial, U1Irrep]
8+
Ps = [ComplexSpace(2), U1Space(0 => 1, 1 => 1)]
9+
Vs = [ComplexSpace(3), U1Space(0 => 2, -1 => 1, 1 => 1)]
10+
11+
sizes = [(1, 1), (3, 3)]
12+
13+
@testset "$(sz) InfiniteSquareNetwork with $(Ss[i]) symmetry" for (i, sz) in
14+
Iterators.product(eachindex(Ss), sizes)
15+
16+
S = Ss[i]
17+
P = Ps[i]
18+
V = Vs[i]
19+
20+
peps_tensor = PEPSTensor(randn, T, P, V)
21+
pf_tensor = PFTensor(randn, T, V)
22+
pepo_tensor = randn(T, P P' ← V ⊗ V ⊗ V' V')
23+
24+
peps = InfinitePEPS(peps_tensor; unitcell = sz)
25+
pf = InfinitePartitionFunction(pf_tensor; unitcell = sz)
26+
pepo = InfinitePEPO(pepo_tensor; unitcell = (sz..., 2))
27+
28+
peps_n = InfiniteSquareNetwork(peps)
29+
pf_n = InfiniteSquareNetwork(pf)
30+
pepo_n = InfiniteSquareNetwork(peps, pepo)
31+
32+
@test scalartype(peps_n) == T
33+
@test eltype(peps_n) == PEPSSandwich{typeof(peps_tensor)}
34+
@test spacetype(peps_n) == typeof(P)
35+
@test sectortype(peps_n) == S
36+
37+
@test scalartype(pf_n) == T
38+
@test eltype(pf_n) == typeof(pf_tensor)
39+
@test spacetype(pf_n) == typeof(V)
40+
@test sectortype(pf_n) == S
41+
42+
@test scalartype(pepo_n) == T
43+
@test eltype(pepo_n) == PEPOSandwich{2, typeof(peps_tensor), typeof(pepo_tensor)}
44+
@test spacetype(pepo_n) == typeof(P)
45+
@test sectortype(pepo_n) == S
46+
47+
@test peps_n + peps_n ≈ 2 * peps_n
48+
@test repeat(InfiniteSquareNetwork(InfinitePEPS(peps_tensor)), sz...) == peps_n
49+
@test (rotl90 ∘ rotl90)(peps_n) ≈ rot180(peps_n)
50+
51+
@test pf_n + pf_n ≈ 2 * pf_n
52+
@test (rotr90 ∘ rotr90)(pf_n) ≈ rot180(pf_n)
53+
54+
@test length(peps_n) == prod(sz)
55+
end

0 commit comments

Comments
 (0)