From 9f553b0269e736cf10f7d8b662f72af34e744982 Mon Sep 17 00:00:00 2001 From: Jutho Date: Sun, 8 Dec 2024 21:03:19 +0100 Subject: [PATCH] Constructor fixes (#185) * some constructor fixes * add fix and tests * more isometry constructor fixes --- .gitignore | 7 ++++++- src/fusiontrees/fusiontrees.jl | 10 ++++----- src/tensors/linalg.jl | 7 +++---- test/fusiontrees.jl | 37 ++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 5df92310..eec2830b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ __pycache__ .ipynb* Manifest.toml -.vscode \ No newline at end of file +.vscode +benchmark +experimental +refs +*.mathcha + diff --git a/src/fusiontrees/fusiontrees.jl b/src/fusiontrees/fusiontrees.jl index d25a8083..761ebe49 100644 --- a/src/fusiontrees/fusiontrees.jl +++ b/src/fusiontrees/fusiontrees.jl @@ -86,13 +86,11 @@ function FusionTree{I}(uncoupled::NTuple{N}, coupled=one(I), _abelianinner(map(s -> convert(I, s), (uncoupled..., dual(coupled))))) end -function FusionTree(uncoupled::Tuple{I,Vararg{I}}, coupled::I=one(I), - isdual=ntuple(n -> false, length(uncoupled))) where {I<:Sector} - FusionStyle(I) isa UniqueFusion || - error("fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`") - return FusionTree{I}(uncoupled, coupled, isdual, - _abelianinner((uncoupled..., dual(coupled)))) +function FusionTree(uncoupled::NTuple{N,I}, coupled::I, + isdual=ntuple(n -> false, length(uncoupled))) where {N,I<:Sector} + return FusionTree{I}(uncoupled, coupled, isdual) end +FusionTree(uncoupled::Tuple{I,Vararg{I}}) where {I<:Sector} = FusionTree(uncoupled, one(I)) # Properties sectortype(::Type{<:FusionTree{I}}) where {I<:Sector} = I diff --git a/src/tensors/linalg.jl b/src/tensors/linalg.jl index d60158d4..a3f84adb 100644 --- a/src/tensors/linalg.jl +++ b/src/tensors/linalg.jl @@ -120,7 +120,7 @@ the spacetype does not have a Euclidean inner product, an error will be thrown. See also [`isomorphism`](@ref) and [`isometry`](@ref). """ -function unitary(::Type{A}, V::TensorMapSpace{S,N₁,N₂}) where {A<:VecOrNumber,S,N₁,N₂} +function unitary(A::Type, V::TensorMapSpace{S,N₁,N₂}) where {S,N₁,N₂} InnerProductStyle(S) === EuclideanInnerProduct() || throw_invalid_innerproduct(:unitary) return isomorphism(A, V) end @@ -155,9 +155,8 @@ for morphism in (:isomorphism, :unitary, :isometry) @eval begin $morphism(V::TensorMapSpace) = $morphism(Float64, V) $morphism(codomain::TensorSpace, domain::TensorSpace) = $morphism(codomain ← domain) - function $morphism(::Type{T}, codomain::TensorSpace, - domain::TensorSpace) where {T<:VecOrNumber} - return $morphism(T, codomain ← domain) + function $morphism(A::Type, codomain::TensorSpace, domain::TensorSpace) + return $morphism(A, codomain ← domain) end $morphism(t::AbstractTensorMap) = $morphism(storagetype(t), space(t)) end diff --git a/test/fusiontrees.jl b/test/fusiontrees.jl index 8ecccbde..6752b300 100644 --- a/test/fusiontrees.jl +++ b/test/fusiontrees.jl @@ -25,6 +25,43 @@ ti = time() @testset "Fusion tree $Istr: printing" begin @test eval(Meta.parse(sprint(show, f))) == f end + @testset "Fusion tree $Istr: constructor properties" begin + u = one(I) + @constinferred FusionTree((), u, (), (), ()) + @constinferred FusionTree((u,), u, (false,), (), ()) + @constinferred FusionTree((u, u), u, (false, false), (), (1,)) + @constinferred FusionTree((u, u, u), u, (false, false, false), (u,), (1, 1)) + @constinferred FusionTree((u, u, u, u), u, (false, false, false, false), (u, u), + (1, 1, 1)) + @test_throws MethodError FusionTree((u, u, u), u, (false, false), (u,), (1, 1)) + @test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (u, u), + (1, 1)) + @test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (u,), + (1, 1, 1)) + @test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (), (1,)) + + f = FusionTree((u, u, u), u, (false, false, false), (u,), (1, 1)) + @test sectortype(f) == I + @test length(f) == 3 + @test FusionStyle(f) == FusionStyle(I) + @test BraidingStyle(f) == BraidingStyle(I) + + if FusionStyle(I) isa UniqueFusion + @constinferred FusionTree((), u, ()) + @constinferred FusionTree((u,), u, (false,)) + @constinferred FusionTree((u, u), u, (false, false)) + @constinferred FusionTree((u, u, u), u) + @constinferred FusionTree((u, u, u, u)) + @test_throws MethodError FusionTree((u, u), u, (false, false, false)) + else + errstr = "fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`" + @test_throws errstr FusionTree((), u, ()) + @test_throws errstr FusionTree((u,), u, (false,)) + @test_throws errstr FusionTree((u, u), u, (false, false)) + @test_throws errstr FusionTree((u, u, u), u) + @test_throws errstr FusionTree((u, u, u, u)) + end + end @testset "Fusion tree $Istr: insertat" begin N = 4 out2 = ntuple(n -> randsector(I), N)