Jutho/TensorKit.jl

`ComplexSpace` constructor from sector-degeneracy pairs similar to that of `GradedSpace`?

Closed this issue · 1 comments

At some point I needed a routine to increase the degeneracies in a given space while preserving its sectors. The (seemingly) simplest way to do this fails for the ComplexSpace case, since this doesn't have a constructor which takes sector-degeneracy pairs as input.

using TensorKit

function expand_degeneracies(V::ElementarySpace; fact=1.5)
    return Vect[sectortype(V)](s => ceil(Int, dim(V, s) * fact) for s in sectors(V))
end
V1 = Z2Space(0 => 2, 1 => 2)
expand_degeneracies(V1)
Rep[ℤ₂](0=>3, 1=>3)
V2 =^4
expand_degeneracies(V2)
ERROR: MethodError: no method matching ComplexSpace(::Base.Generator{TensorKit.OneOrNoneIterator{Trivial}, var"#8#9"{Float64, ComplexSpace}})

Closest candidates are:
  ComplexSpace(::Any, ::Any)
   @ TensorKit ~/.julia/packages/TensorKit/j71BN/src/spaces/complexspace.jl:9
  ComplexSpace()
   @ TensorKit ~/.julia/packages/TensorKit/j71BN/src/spaces/complexspace.jl:12
  ComplexSpace(::AbstractDict; kwargs...)
   @ TensorKit ~/.julia/packages/TensorKit/j71BN/src/spaces/complexspace.jl:21
  ...

Would it make sense to add such a constructor for ComplexSpace, since it already behaves like a GradedSpace in most cases anyway?

Also, even then the CartesianSpace case is a bit tricky, since Vect[sectortype(::CartesianSpace)] == ComplexSpace.

I think the following should work after #120 (before, you might have to unpack the generator for Cartesian/Complex spaces

function expand_degeneracies(V::GradedSpace; factor::Real=1.5)
       dual = isdual(V)
       return spacetype(V)((dual ? conj(s) : s) => ceil(Int, dim(V, s) * factor) for s in sectors(V); dual)
end