Skip to content

Commit 68c83b8

Browse files
authored
Multifusion compatibility (#38)
1 parent a98180a commit 68c83b8

3 files changed

Lines changed: 113 additions & 2 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockTensorKit"
22
uuid = "5f87ffc2-9cf1-4a46-8172-465d160bd8cd"
3-
version = "0.3.4"
3+
version = "0.3.5"
44
authors = ["Lukas Devos <ldevos98@gmail.com> and contributors"]
55

66
[deps]

src/vectorspaces/sumspace.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ end
171171
TensorKit.unitspace(S::Type{<:SumSpace}) = SumSpace(TensorKit.unitspace(eltype(S)))
172172
TensorKit.zerospace(::Type{SumSpace{S}}) where {S} = SumSpace{S}()
173173

174+
function TensorKit.leftunitspace(S::SumSpace)
175+
return SumSpace(leftunitspace(oplus(S)))
176+
end
177+
function TensorKit.rightunitspace(S::SumSpace)
178+
return SumSpace(rightunitspace(oplus(S)))
179+
end
180+
TensorKit.isunitspace(S::SumSpace) = !isempty(S) && all(isunitspace, S.spaces)
181+
174182
# Promotion and conversion
175183
# ------------------------
176184
Base.promote_rule(::Type{S}, ::Type{SumSpace{S}}) where {S <: ElementarySpace} = SumSpace{S}

test/vectorspaces/sumspace.jl

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ end
101101
@test !(V (V, V))
102102
end
103103

104-
@testset"GradedSpace" begin
104+
@testset "GradedSpace" begin
105105
using TensorKit, BlockTensorKit
106106
using Test, TestExtras
107107

@@ -153,3 +153,106 @@ end
153153
@test V (V, V)
154154
@test !(V (V, V))
155155
end
156+
157+
@testset "Multifusion" begin
158+
using TensorKit, BlockTensorKit
159+
using Test, TestExtras
160+
161+
using TensorKit: hassector
162+
using BlockTensorKit:
163+
164+
I = IsingBimodule
165+
166+
C0, C1, D0, D1, M, Mop = I(1, 1, 0), I(1, 1, 1), I(2, 2, 0), I(2, 2, 1), I(1, 2, 0), I(2, 1, 0)
167+
168+
V1 = Vect[I](C0 => 1, C1 => 1)
169+
V2 = Vect[I](D0 => 1, D1 => 1)
170+
V3 = Vect[I](M => 1) # no Mop
171+
d = dim(V1) + dim(V2) + dim(V3)
172+
V = SumSpace(V1, V2, V3)
173+
174+
@test isa(V, VectorSpace)
175+
@test isa(V, ElementarySpace)
176+
177+
@test isa(InnerProductStyle(V), HasInnerProduct)
178+
@test isa(InnerProductStyle(V), EuclideanInnerProduct)
179+
@test isa(V, SumSpace)
180+
181+
@test !isdual(V)
182+
@test isdual(V')
183+
184+
@test @constinferred(hash(V)) == hash(deepcopy(V))
185+
@test @constinferred(dual(V)) == @constinferred(conj(V)) == @constinferred(adjoint(V))
186+
@test field(V) ==
187+
188+
@test unitspace(V) == unitspace(V1)
189+
190+
@test @constinferred(sectortype(V)) == sectortype(V1)
191+
@test ((@constinferred sectors(V))...,) == (C1, C0, D1, D0, M) # ordering matters
192+
@test length(sectors(V)) == 5
193+
@test @constinferred(hassector(V, M))
194+
@test !@constinferred(hassector(V, Mop))
195+
@test @constinferred(dim(V)) ==
196+
d ==
197+
@constinferred(sum(dim(s) for s in sectors(V)))
198+
@test dim(@constinferred(typeof(V)())) == 0
199+
@test (sectors(typeof(V)())...,) == ()
200+
201+
# (left/right)unitspace tests
202+
WC = @constinferred SumSpace(Vect[I](C0 => 1))
203+
WD = @constinferred SumSpace(Vect[I](D0 => 1))
204+
WM = @constinferred SumSpace(V3)
205+
WMop = @constinferred SumSpace(Vect[I](Mop => 1))
206+
for W in [WC, WD]
207+
@test isunitspace(W)
208+
@test W == @constinferred(leftunitspace(W)) == @constinferred(rightunitspace(W))
209+
@test unitspace(typeof(W)) == (Vect[IsingBimodule]((1, 1, 0) => 1, (2, 2, 0) => 1))
210+
end
211+
212+
@test_throws ArgumentError leftunitspace(V)
213+
@test_throws ArgumentError rightunitspace(V)
214+
@test leftunitspace(SumSpace(V1, V3)) == WC
215+
@test rightunitspace(SumSpace(V2, V3)) == WD
216+
@test leftunitspace(WMop) == WD && rightunitspace(WMop) == WC
217+
@test leftunitspace(WM) == WC && rightunitspace(WM) == WD
218+
@test unitspace(WM) == unitspace(WMop) == (Vect[IsingBimodule]((1, 1, 0) => 1, (2, 2, 0) => 1))
219+
220+
Wempty = SumSpace(Vect[I]())
221+
Wzero = zerospace(V)
222+
@test unitspace(Wempty) == unitspace(Wzero)
223+
for f in (leftunitspace, rightunitspace)
224+
@test_throws ArgumentError f(Wempty)
225+
end
226+
227+
VC = SumSpace(V1, V1)
228+
VCM = SumSpace(V1, V3)
229+
VMD = SumSpace(V2, V3)
230+
231+
@test @constinferred((V, V)) == SumSpace(vcat(V.spaces, V.spaces))
232+
@test @constinferred((VCM, unitspace(VCM))) == SumSpace(vcat(VCM.spaces, unitspace(VCM).spaces))
233+
@test @constinferred((VCM, leftunitspace(VCM))) == SumSpace(vcat(VCM.spaces, leftunitspace(VCM).spaces))
234+
@test @constinferred((VMD, rightunitspace(VMD))) == SumSpace(vcat(VMD.spaces, rightunitspace(VMD).spaces))
235+
236+
@test @constinferred((V, V, V, V)) == SumSpace(repeat(V.spaces, 4))
237+
@test @constinferred(fuse(VC, VC)) SumSpace(Vect[I](C0 => 8, C1 => 8))
238+
@test @constinferred(fuse(VC, VC', VC, VC'))
239+
SumSpace(Vect[I](C0 => 128, C1 => 128))
240+
@test @constinferred(flip(V)) SumSpace(flip.(V.spaces)...)
241+
@test flip(V) V
242+
@test flip(V) V
243+
@test flip(V) V
244+
@test V (V, V)
245+
@test !(V (V, V))
246+
247+
# blocksectors tests
248+
@test issetequal(@constinferred(blocksectors(one(V) one(V))), (C0, D0))
249+
@test issetequal(@constinferred(blocksectors(V V)), sectors(V))
250+
@test @constinferred(blocksectors(one(V))) == [C0, D0]
251+
for v in [VC, VCM, VMD]
252+
@test @constinferred(blocksectors(v^2)) == blocksectors(v v)
253+
end
254+
for v in [WM, WMop]
255+
@test isempty(@constinferred(blocksectors(v^2)))
256+
@test @constinferred(blocksectors(v v)) == blocksectors(v)
257+
end
258+
end

0 commit comments

Comments
 (0)