Implementation Guidelines

This section provides practical advice for implementing new sector types efficiently and correctly.

Helper Type: SectorProductIterator

Instead of materializing all fusion outputs in a tuple or array, one can use SectorProductIterator for type-stable, lazy iteration.

TensorKitSectors.SectorProductIteratorType
struct SectorProductIterator{I <: Sector}
SectorProductIterator(a::I, b::I) where {I <: Sector}

Custom iterator to represent the (unique) fusion outputs of $a ⊗ b$.

Custom sectors that aim to use this have to provide the following functionality:

  • Base.iterate(::SectorProductIterator{I}, state...) where {I <: Sector}: iterate over the fusion outputs of a ⊗ b

If desired and it is possible to easily compute the number of unique fusion outputs, it is also possible to define Base.IteratorSize(::Type{SectorProductIterator{I}}) = Base.HasLength(), in which case Base.length(::SectorProductIterator{I}) has to be implemented.

See also .

source

This is enabled by default, and new sectors should provide implementations for the following functions:

Base.iterate(ab::SectorProductIterator{I}, [state]) = ...
# optional optimizations:
Base.IteratorSize(::Type{SectorProductIterator{I}}) = HasLength()
Base.length(ab::SectorProductIterator{I}) = ...

This has the benefit of helping with type stability, and has a pretty-printing overload:

SU2Irrep(1) ⊗ SU2Irrep(1)
Irrep[SU₂](1) ⊗ Irrep[SU₂](1):
 0
 1
 2

Shape of Topological Data

The size of Fsymbol and Rsymbol data depends on the fusion multiplicities (Nsymbol). For multiplicity‑free sectors scalars are sufficient; for generic fusion we need arrays. Therefore, we distinguish the behavior through the FusionStyle.

MultiplicityFreeFusion

  • Nsymbol(a, b, c): Returns a Bool.
  • Fsymbol(a, b, c, d, e, f): Returns a scalar of type sectorscalartype(I).
  • Rsymbol(a, b, c): Returns a scalar of type sectorscalartype(I).

Additionally, if the Fsymbol and Rsymbol do not correspond to valid fusion channels, the result is $0$. Therefore, computing the number of valid fusion channels for both diagrams as the product of the relevant Nsymbols, we have:

\[\left(N^{ab}_e N^{ec}_d = 0 \lor N^{af}_d N^{bc}_f = 0\right) \implies (F_{abc}^d)^e_f = 0\]

\[N^{ab}_c = 0 \implies R^{ab}_c = 0\]

GenericFusion

  • Nsymbol(a, b, c): Returns a positive Integer.
  • Fsymbol(a, b, c, d, e, f): Returns a $N^{ab}_e \times N^{ec}_d \times N^{af}_d \times N^{bc}_f$ array of sectorscalartype(I) elements.
  • Rsymbol(a, b, c): Returns a $N^{ab}_c \times N^{ba}_c$ array of sectorscalartype(I) elements.

Here invalid fusion channels will necessarily lead to empty arrays.