Skip to content

Prevent construction of multifusion tensors with incompatible coloring - #515

Open
borisdevos wants to merge 14 commits into
mainfrom
bd/fusiontree-iterate
Open

Prevent construction of multifusion tensors with incompatible coloring#515
borisdevos wants to merge 14 commits into
mainfrom
bd/fusiontree-iterate

Conversation

@borisdevos

@borisdevos borisdevos commented Aug 26, 2026

Copy link
Copy Markdown
Member

Deals with #514, at least partially.
Now we have

julia> Wis
(Vect[IsingBimodule]((1, 1, 0) => 1)  Vect[IsingBimodule]((1, 1, 0) => 1))  Vect[IsingBimodule]((2, 2, 0) => 1)

julia> blocksectors(Wis)
0-element Dictionaries.Indices{IsingBimodule}

which behaves the same way as

julia> Wu1
Rep[U₁](1 => 1)  (Rep[U₁](0 => 1)  Rep[U₁](0 => 1))

julia> blocksectors(Wu1)
0-element Dictionaries.Indices{U1Irrep}

Edit: decided to actually prevent construction of these kinds of tensors at the level of the product space and hom space.
Since this was incompatible with the previous implementation of unitspace, this now errors for GenericUnit sector types.

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think this is probably quite a big performance hit right in the hot path of the fusiontree constructors though, I don't think there is typically a fast implementation of this. Additionally, I was kind of expecting to convert more things to Nsymbol, to actually make them error if the fusion is disallowed?

@borisdevos

Copy link
Copy Markdown
Member Author

I'm misunderstanding then what kind of behavior we want. So we want Nsymbol checks there, such that forbidden fusion trees shouldn't ever be able to be looked at? And then at the tensor construction level, when colors mismatch this should throw an error, thus preventing constructing forbidden tensors?

@lkdvos

lkdvos commented Aug 26, 2026

Copy link
Copy Markdown
Member

I think that was what I was expecting, especially since we decided Nsymbol errors instead of returning 0

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/spaces/gradedspace.jl 92.57% <100.00%> (+0.04%) ⬆️
src/spaces/homspace.jl 92.98% <100.00%> (+1.61%) ⬆️
src/spaces/productspace.jl 88.75% <100.00%> (+0.85%) ⬆️
src/spaces/vectorspaces.jl 71.31% <100.00%> (+1.63%) ⬆️
src/tensors/tensoroperations.jl 97.37% <100.00%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@borisdevos borisdevos changed the title Replace Nsymbol calls or add guards in fusion tree iteration Prevent construction of multifusion tensors with incompatible coloring Sep 2, 2026

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the comments, looks good, thanks for looking into this!

Comment thread src/spaces/gradedspace.jl
Comment thread src/spaces/productspace.jl Outdated

@inbounds for i in 1:(N - 1)
_rightunit(spaces[i]) == _leftunit(spaces[i + 1]) ||
throw(ArgumentError(lazy"spaces $(i) and $(i + 1) have incompatible coloring"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be SpaceMismatch, or should we just introduce a new error type for this? Do you also want to print which spaces are the offending ones?
This comment also holds for the HomSpace checks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to spacemismatch and return the spaces in both cases

Comment thread src/spaces/productspace.jl Outdated
Comment thread src/spaces/homspace.jl
return HomSpace{S, P1, P2}(codomain, domain)
end

function _check_unit_compatibility(codomain::ProductSpace{S}, domain::ProductSpace{S}) where {S <: ElementarySpace}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are some missing edge cases that are not really handled correctly/consistently here, mostly for the case where leftunit or rightunit cannot be inferred. In principle it is allowed (?) to create 0-dimensional ElementarySpace objects, which in this implementation will always error even though no violation is detected. (In some sense this is because here you check for validity and error if it cant be proven, while you probably want to error if invalidity can be proven).

The only reason I can think of why this might be important is that if you have an SVD that accidentally kills all sectors, you end up with a 0-dim leg on the S which will now error on the space constructions, even though nothing really went wrong

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was also not dealing with length-1 product spaces correctly. My fix for the 0d ones fixed both automatically. Importantly though, I determined that when one of the spaces is 0d, there's no need to check colorings. This is based on the sectors of the total product space always being empty, regardless of valid or invalid coloring, and things like blocksectors and fusiontrees are built on this.

Comment on lines +212 to +213
semisimple unit structure, this returns `true` if `V` is isomorphic to either the left, right or
semisimple unit space.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://en.wikipedia.org/wiki/Semi-simplicity

[edit] it seems like wikipedia isn't even consistent with itself... (https://en.wikipedia.org/wiki/Semisimple_module)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bible doesn't hyphenate it, so I'll follow suit :)

Comment thread src/spaces/gradedspace.jl

function unitspace(S::Type{<:GradedSpace{I}}) where {I <: Sector}
UnitStyle(I) isa GenericUnit &&
throw(ArgumentError("Cannot construct unit space for sector types with semisimple unit structure."))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to actually check if length(allunits(I)) > 1 before erroring? That way simply declaring a normal fusion category as GenericUnit would not immediately trigger the error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of this, we should add a test in the TKS testsuite checking that GenericUnit actually agrees with having length(allunits(I)) > 1, precisely to prevent normal fusion categories from having GenericUnit. I don't see why we would want that in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants