Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions test/test_contraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,49 @@ using LinearAlgebra: mul!
using Test: @test, @testset, @test_broken

using BlockSparseArrays: BlockSparseArray
using FusionTensors:
FusionMatrix, FusionTensor, FusionTensorAxes, domain_axes, codomain_axes
using GradedArrays: U1, dual, gradedrange
using FusionTensors: FusionTensor, FusionTensorAxes, domain_axes, codomain_axes
using GradedArrays: SU2, U1, dual, gradedrange
using TensorAlgebra: contract, matricize, permmortar, tuplemortar, unmatricize, unmatricize!

include("setup.jl")

@testset "matricize" begin
@testset "abelian matricize" begin
g1 = gradedrange([U1(0) => 1, U1(1) => 2, U1(2) => 3])
g2 = gradedrange([U1(0) => 2, U1(1) => 2, U1(3) => 1])
g3 = gradedrange([U1(-1) => 1, U1(0) => 2, U1(1) => 1])
g4 = gradedrange([U1(-1) => 1, U1(0) => 1, U1(1) => 1])

ft1 = randn(FusionTensorAxes((g1, g2), (dual(g3), dual(g4))))
m = matricize(ft1, (1, 2), (3, 4))
@test m isa FusionMatrix
ft2 = unmatricize(m, axes(ft1))
@test ft1 ≈ ft2

biperm = permmortar(((3,), (1, 2, 4)))
m2 = matricize(ft1, biperm)
ft_dest = FusionTensor{eltype(ft1)}(undef, axes(ft1)[biperm])
ft_dest = similar(ft1, axes(ft1)[biperm])
unmatricize!(ft_dest, m2, permmortar(((1,), (2, 3, 4))))
@test ft_dest ≈ permutedims(ft1, biperm)

ft2 = similar(ft1)
unmatricize!(ft2, m2, biperm)
@test ft1 ≈ ft2
end

@testset "non-abelian matricize" begin
g1 = gradedrange([SU2(0) => 1, SU2(1//2) => 2, SU2(1) => 3])
g2 = gradedrange([SU2(0) => 2, SU2(1//2) => 2, SU2(3//2) => 1])
g3 = gradedrange([SU2(1//2) => 1, SU2(1) => 2, SU2(2) => 1])
g4 = gradedrange([SU2(0) => 1, SU2(1) => 1, SU2(3//2) => 1])

ft1 = randn(FusionTensorAxes((g1, g2), (dual(g3), dual(g4))))
m = matricize(ft1, (1, 2), (3, 4))
ft2 = unmatricize(m, axes(ft1))
@test ft1 ≈ ft2

biperm = permmortar(((3,), (1, 2, 4)))
m2 = matricize(ft1, biperm)
ft_dest = similar(ft1, axes(ft1)[biperm])
unmatricize!(ft_dest, m2, permmortar(((1,), (2, 3, 4))))
@test ft_dest ≈ permutedims(ft1, biperm)

ft2 = similar(ft1)
Expand Down
30 changes: 27 additions & 3 deletions test/test_permutedims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using FusionTensors:
ndims_domain,
ndims_codomain,
to_fusiontensor
using GradedArrays: O2, U1, SectorProduct, SU2, dual, gradedrange, space_isequal
using GradedArrays: ×, O2, U1, SectorProduct, SU2, dual, gradedrange, space_isequal
using TensorAlgebra: permmortar, tuplemortar

include("setup.jl")
Expand Down Expand Up @@ -178,8 +178,6 @@ end
dual(gradedrange([O2(1//2) => 1])),
gradedrange([SU2(1//2) => 1]),
dual(gradedrange([SU2(1//2) => 1])),
gradedrange([SectorProduct(SU2(1//2), U1(0)) => 1]),
gradedrange([SectorProduct(SU2(1//2), SU2(0)) => 1]),
)
g2b = dual(g2)
for biperm in [
Expand All @@ -201,3 +199,29 @@ end
end
end
end

@testset "SectorProduct permutedims" begin
d = 2
D = 3
tRVB = zeros((d, D, D, D, D)) # tensor RVB SU(2) for spin s
for i in 1:d
tRVB[i, i + 1, 1, 1, 1] = 1.0
tRVB[i, 1, i + 1, 1, 1] = 1.0
tRVB[i, 1, 1, i + 1, 1] = 1.0
tRVB[i, 1, 1, 1, i + 1] = 1.0
end

gd = gradedrange([SU2(1//2) × U1(3) => 1])
gD = dual(gradedrange([SU2(0) × U1(1) => 1, SU2(1//2) × U1(0) => 1]))
ft = to_fusiontensor(tRVB, (gd,), (gD, gD, gD, gD))
@test Array(ft) ≈ tRVB
for biperm in [
permmortar(((1,), (2, 3, 4, 5))),
permmortar(((1, 2, 3), (4, 5))),
permmortar(((3, 1, 4), (2, 5))),
permmortar(((), (2, 4, 1, 5, 3))),
permmortar(((2, 4, 1, 5, 3), ())),
]
@test permutedims(ft, biperm) ≈ naive_permutedims(ft, biperm)
end
end
Loading