Jutho / TensorKit.jl

A Julia package for large-scale tensor computations, with a hint of category theory
MIT License
231 stars 41 forks source link

`fuse` inconsistent in handling dual spaces #110

Closed lkdvos closed 7 months ago

lkdvos commented 7 months ago

Encountered the folowing inconsistent/inconvenient behaviour for fusing vector spaces: fuse(a, b...) automatically results in a non-dual vectorspace, while fuse(a) simply returns a. I think it might be more convenient to ensure that fuse either always returns a non-dual space, or has a keyword to switch between the outputs.

julia> using TensorKit

julia> a = U1Space(1 => 1)
Rep[U₁](1=>1)

julia> fuse(a * a)
Rep[U₁](2=>1)

julia> fuse(a)
Rep[U₁](1=>1)

julia> fuse(a')
Rep[U₁](1=>1)'

julia> fuse(a' * a)
Rep[U₁](0=>1)

In my particular case, I am iteratively fusing more and more spaces together to determine the maximal virtual spaces of an MPS, and now have to insert a weird special case to catch when a single dual space is being entered.

Jutho commented 7 months ago

replacing fuse(V::ElementarySpace) = V on line 155 in vectorspaces.jl with fuse(V::ElementarySpace) = isdual(V) ? flip(V) : V will fix this, I believe. Should I add this?

lkdvos commented 7 months ago

I would like this, yes please ☺️