Skip to content

Commit faacc54

Browse files
committed
remove TK interface (mostly)
1 parent f181136 commit faacc54

File tree

1 file changed

+23
-158
lines changed

1 file changed

+23
-158
lines changed

src/bimodulesector.jl

Lines changed: 23 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,28 @@ function extract_dual(::Type{I}) where {I <: BimoduleSector}
136136
map(1:ncats) do i
137137
Niii = N[i, i, i]
138138
nobji = maximum(first, keys(N[i, i, i]))
139-
# want to return a leftone and rightone for each entry in multifusion cat
140-
# leftone/rightone needs to at least be the unit object within a fusion cat
139+
# want to return a leftunit and rightunit for each entry in multifusion cat
140+
# leftunit/rightunit needs to at least be the unit object within a fusion cat
141141
Is[i] = findfirst(1:nobji) do a
142142
get(Niii, (a, a, a), 0) == 1 || return false # I x I -> I
143143
for othera in 1:nobji
144144
get(Niii, (othera, a, othera), 0) == 1 || return false # a x I -> a
145145
get(Niii, (a, othera, othera), 0) == 1 || return false # I x a -> a
146146
end
147147

148-
# check leftone
148+
# check leftunit
149149
map(1:ncats) do j
150150
nobjj = maximum(first, keys(N[j, j, j]))
151151
for b in 1:nobjj
152-
get(N[i, j, j], (a, b, b), 0) == 1 || return false # I = leftone(b)
152+
get(N[i, j, j], (a, b, b), 0) == 1 || return false # I = leftunit(b)
153153
end
154154
end
155155

156-
# check rightone
156+
# check rightunit
157157
map(1:ncats) do k
158158
nobjk = maximum(first, keys(N[k, k, k]))
159159
for c in 1:nobjk
160-
get(N[k, i, k], (c, a, c), 0) == 1 || return false # I = rightone(c)
160+
get(N[k, i, k], (c, a, c), 0) == 1 || return false # I = rightunit(c)
161161
end
162162
end
163163
return true
@@ -175,8 +175,8 @@ function extract_dual(::Type{I}) where {I <: BimoduleSector}
175175
Niji = N[i, j, i] # 𝒞_ij x 𝒞_ji -> C_ii
176176
Njij = N[j, i, j] # 𝒞_ji x 𝒞_ij -> C_jj
177177
for i_ob in 1:nobji, j_ob in 1:nobjj
178-
get(Niji, (i_ob, j_ob, Is[i]), 0) == 1 || continue # leftone(c_ij) ∈ c_ij x c_ji
179-
get(Njij, (j_ob, i_ob, Is[j]), 0) == 1 || continue # rightone(c_ij) ∈ c_ji x c_ij
178+
get(Niji, (i_ob, j_ob, Is[i]), 0) == 1 || continue # leftunit(c_ij) ∈ c_ij x c_ji
179+
get(Njij, (j_ob, i_ob, Is[j]), 0) == 1 || continue # rightunit(c_ij) ∈ c_ji x c_ij
180180
push!(allduals[i, j], j_ob)
181181
end
182182
end
@@ -189,15 +189,13 @@ function TensorKitSectors.unit(a::BimoduleSector)
189189
return typeof(a)(a.i, a.i, _get_dual_cache(typeof(a))[1][a.i])
190190
end
191191

192-
# Base.isone(a::BimoduleSector) = leftone(a) == a == rightone(a)
193-
194192
function TensorKitSectors.allunits(::Type{I}) where {I <: BimoduleSector}
195193
s = size(I)
196194
return I[I(i, i, _get_dual_cache(I)[1][i]) for i in 1:s]
197195
end
198196

199197
function TensorKitSectors.unit(::Type{<:BimoduleSector})
200-
throw(ArgumentError("one of Type BimoduleSector doesn't exist"))
198+
throw(ArgumentError("unit of Type BimoduleSector doesn't exist"))
201199
end
202200

203201
function TensorKitSectors.leftunit(a::BimoduleSector)
@@ -286,59 +284,7 @@ end
286284
# interface with TensorKit where necessary
287285
#-----------------------------------------
288286

289-
#TODO: generalise
290-
# is this blocksectors necessary with the productspace one?
291-
function TensorKit.blocksectors(W::TensorMapSpace{S,N₁,N₂}) where
292-
{S<:Union{Vect[A4Object],
293-
SumSpace{Vect[A4Object]}},N₁,N₂}
294-
codom = codomain(W)
295-
dom = domain(W)
296-
if N₁ == 0 && N₂ == 0 # 0x0-dimensional TensorMap is just a scalar, return all units
297-
# this is a problem in full contractions where the coloring outside is 𝒞
298-
return NTuple{size(A4Object),A4Object}(one(A4Object(i, i, 1))
299-
for i in 1:size(A4Object)) # have to return all units b/c no info on W in this case
300-
elseif N₁ == 0
301-
@assert N₂ != 0 "one of Type A4Object doesn't exist"
302-
return filter!(isone, collect(blocksectors(dom)))
303-
elseif N₂ == 0
304-
@assert N₁ != 0 "one of Type A4Object doesn't exist"
305-
return filter!(isone, collect(blocksectors(codom)))
306-
elseif N₂ <= N₁ # keep intersection
307-
return filter!(c -> hasblock(codom, c), collect(blocksectors(dom)))
308-
else
309-
return filter!(c -> hasblock(dom, c), collect(blocksectors(codom)))
310-
end
311-
end
312-
313-
#TODO: generalise
314-
# function TensorKit.blocksectors(P::ProductSpace{S,N}) where {S<:Union{Vect[A4Object],SumSpace{Vect[A4Object]}},N}
315-
# I = sectortype(S) # currently just A4Object
316-
# bs = Vector{I}()
317-
# if N == 0
318-
# return I[one(I(i, i, 1)) for i in 1:size(I)]
319-
# elseif N == 1
320-
# for s in sectors(P)
321-
# push!(bs, first(s))
322-
# end
323-
# else
324-
# for s in sectors(P)
325-
# for c in ⊗(s...)
326-
# if !(c in bs)
327-
# push!(bs, c)
328-
# end
329-
# end
330-
# end
331-
# end
332-
# return sort!(bs)
333-
# end
334-
335-
function TensorKit.dim(V::GradedSpace{<:BimoduleSector})
336-
T = Base.promote_op(*, Int, real(sectorscalartype(sectortype(V))))
337-
return reduce(+, dim(V, c) * dim(c) for c in sectors(V); init=zero(T))
338-
end
339-
340-
Base.zero(S::Type{<:GradedSpace{<:BimoduleSector}}) = S()
341-
287+
# TODO: can remove this once the otimes assert is removed
342288
function TensorKit.fuse(V₁::GradedSpace{I}, V₂::GradedSpace{I}) where {I<:BimoduleSector}
343289
dims = TensorKit.SectorDict{I,Int}()
344290
for a in sectors(V₁), b in sectors(V₂)
@@ -351,100 +297,19 @@ function TensorKit.fuse(V₁::GradedSpace{I}, V₂::GradedSpace{I}) where {I<:Bi
351297
end
352298

353299
#TODO: these might not be necessary anymore after TensorKit#291
300+
# check after BlockTensorKit#38
354301

355-
# limited unitspace
356-
function TensorKit.unitspace(S::GradedSpace{<:BimoduleSector})
357-
allequal(a.i for a in sectors(S)) && allequal(a.j for a in sectors(S)) ||
358-
throw(ArgumentError("sectors of $S are not all equal"))
359-
first(sectors(S)).i == first(sectors(S)).j ||
360-
throw(ArgumentError("sectors of $S are non-diagonal"))
361-
sector = one(first(sectors(S)))
362-
return spacetype(S)(sector => 1)
363-
end
364-
365-
function TensorKit.unitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
366-
@assert !isempty(S) "Cannot determine type of empty space"
367-
return SumSpace(oneunit(first(S.spaces))) # assuming diagonal SumSpace (like in MPSKit)
368-
end
369-
370-
# oneunit for spaces whose elements all belong to the same sector
371-
function rightunitspace(S::GradedSpace{<:BimoduleSector})
372-
allequal(a.j for a in sectors(S)) ||
373-
throw(ArgumentError("sectors of $S do not have the same rightunit"))
374-
375-
sector = rightunit(first(sectors(S)))
376-
return spacetype(S)(sector => 1)
377-
end
378-
379-
function rightunitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
380-
@assert !isempty(S) "Cannot determine type of empty space"
381-
return SumSpace(rightunitspace(first(S.spaces)))
382-
end
383-
384-
function leftunitspace(S::GradedSpace{<:BimoduleSector})
385-
allequal(a.i for a in sectors(S)) ||
386-
throw(ArgumentError("sectors of $S do not have the same leftunit"))
387-
388-
sector = leftunit(first(sectors(S)))
389-
return spacetype(S)(sector => 1)
390-
end
391-
392-
function leftunitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
393-
@assert !isempty(S) "Cannot determine type of empty space"
394-
return SumSpace(leftunitspace(first(S.spaces)))
395-
end
396-
397-
398-
function TensorKit.insertrightunit(P::ProductSpace{V,N}, ::Val{i};
399-
conj::Bool=false,
400-
dual::Bool=false) where {i,V<:GradedSpace{I},N} where {I<:BimoduleSector}
401-
i > N && error("cannot insert a sensible right unit onto $P at index $(i+1)")
402-
# possible change to rightunit of correct space for N = 0
403-
u = N > 0 ? rightunitspace(P[i]) : error("no unit object in $P")
404-
if dual
405-
u = TensorKit.dual(u)
406-
end
407-
if conj
408-
u = TensorKit.conj(u)
409-
end
410-
return ProductSpace(TupleTools.insertafter(P.spaces, i, (u,)))
411-
end
412-
413-
# possible TODO: overwrite defaults at level of HomSpace and TensorMap?
414-
function TensorKit.insertleftunit(P::ProductSpace{V,N}, ::Val{i}; # want no defaults?
415-
conj::Bool=false,
416-
dual::Bool=false) where {i,V<:GradedSpace{I},N} where {I<:BimoduleSector}
417-
i > N && error("cannot insert a sensible left unit onto $P at index $i") # do we want this to error in the diagonal case?
418-
u = N > 0 ? leftunitspace(P[i]) : error("no unit object in $P")
419-
if dual
420-
u = TensorKit.dual(u)
421-
end
422-
if conj
423-
u = TensorKit.conj(u)
424-
end
425-
return ProductSpace(TupleTools.insertafter(P.spaces, i - 1, (u,)))
426-
end
427-
428-
function TensorKit.scalar(t::AbstractTensorMap{T,S,0,0}) where {T,
429-
S<:GradedSpace{<:BimoduleSector}}
430-
Bs = collect(blocks(t))
431-
inds = findall(!iszero last, Bs)
432-
isempty(inds) && return zero(scalartype(t))
433-
return only(last(Bs[only(inds)]))
434-
end
302+
# function TensorKit.unitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
303+
# @assert !isempty(S) "Cannot determine type of empty space"
304+
# return SumSpace(oneunit(first(S.spaces))) # assuming diagonal SumSpace (like in MPSKit)
305+
# end
435306

436-
# is this even necessary? can let it error at TensorKit fusiontrees.jl:93 from the one(<:BimoduleSector) call
437-
# but these errors are maybe more informative
438-
function TensorKit.FusionTree(uncoupled::Tuple{<:I,Vararg{I}}) where {I<:BimoduleSector}
439-
coupled = collect((uncoupled...))
440-
if length(coupled) == 0 # illegal fusion somewhere
441-
throw(ArgumentError("Forbidden fusion with uncoupled sectors $uncoupled"))
442-
else # allowed fusions require inner lines
443-
error("fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`")
444-
end
445-
end
307+
# function rightunitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
308+
# @assert !isempty(S) "Cannot determine type of empty space"
309+
# return SumSpace(rightunitspace(first(S.spaces)))
310+
# end
446311

447-
# this one might also be overkill, since `FusionTreeIterator`s don't check whether the fusion is allowed
448-
function TensorKit.fusiontrees(uncoupled::Tuple{I,Vararg{I}}) where {I<:BimoduleSector}
449-
return throw(ArgumentError("coupled sector must be provided for $I fusion"))
450-
end
312+
# function leftunitspace(S::SumSpace{<:GradedSpace{<:BimoduleSector}})
313+
# @assert !isempty(S) "Cannot determine type of empty space"
314+
# return SumSpace(leftunitspace(first(S.spaces)))
315+
# end

0 commit comments

Comments
 (0)