Skip to content

Commit ea6bff6

Browse files
borisdevoslkdvosJutho
authored
Changes for TensorKitSectors v0.3 (#290)
* change TensorKitSectors compat * add `unitspace` * one -> unit + left/rightone -> left/rightunit + isone -> isunit when concerning sectors + some more unitspace * change conj to dual for sectors * export new functions from TensorKitSectors * introduce `zerospace` to replace `zero` of a space * add `oneunit` for type of space * format * minor changes from #263 * use the const `TK` in tests where appropriate * `otimes` between tensormaps to account for `sectorscalartype` * formatter * update frobeniusschur * reimplement otimes * remove todo comment that breaks docstring * fix test * docs fixes * Reorganize exports in TensorKit.jl * More reorganization of exports * Fix typo in export reorganization --------- Co-authored-by: Lukas Devos <ldevos98@gmail.com> Co-authored-by: Jutho <Jutho@users.noreply.github.com>
1 parent b9d6d2c commit ea6bff6

26 files changed

+221
-209
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PackageExtensionCompat = "1"
3939
Random = "1"
4040
ScopedValues = "1.3.0"
4141
Strided = "2"
42-
TensorKitSectors = "0.1.4, 0.2"
42+
TensorKitSectors = "0.3"
4343
TensorOperations = "5.1"
4444
Test = "1"
4545
TestExtras = "0.2,0.3"

docs/src/lib/sectors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ Irrep
3131

3232
## Methods for defining and characterizing `Sector` subtypes
3333
```@docs
34-
Base.one(::Sector)
35-
dual(::Sector)
34+
unit(::Sector)
35+
dual
3636
Nsymbol
3737
3838
Fsymbol
3939
Rsymbol
4040
Bsymbol
4141
dim(::Sector)
42-
frobeniusschur
42+
frobenius_schur_phase
4343
twist(::Sector)
4444
Base.isreal(::Type{<:Sector})
4545
TensorKitSectors.sectorscalartype

docs/src/lib/spaces.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ The following methods act specifically on `ElementarySpace` spaces:
8686

8787
```@docs
8888
isdual
89-
dual
89+
dual(::VectorSpace)
9090
conj
9191
flip
9292
9393
94-
zero(::ElementarySpace)
95-
oneunit
94+
zerospace
95+
unitspace
9696
supremum
9797
infimum
9898
```

docs/src/man/sectors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ For practical reasons, we also require some additional methods to be defined:
171171

172172
Further information, such as the quantum dimensions ``d_a`` and Frobenius-Schur indicator
173173
``χ_a`` (only if ``a == \overline{a}``) are encoded in the F-symbol. They are obtained as
174-
[`dim(a)`](@ref) and [`frobeniusschur(a)`](@ref). These functions have default definitions
174+
[`dim(a)`](@ref) and [`frobenius_schur_phase(a)`](@ref). These functions have default definitions
175175
which extract the requested data from `Fsymbol(a, conj(a), a, a, one(a), one(a))`, but they
176176
can be overloaded in case the value can be computed more efficiently.
177177

docs/src/man/spaces.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,18 @@ flip(ℂ^4) == ℂ^4
316316
```
317317

318318
We also define the direct sum `V1` and `V2` as `V1 ⊕ V2`, where `` is obtained by typing
319-
`\oplus`+TAB. This is possible only if `isdual(V1) == isdual(V2)`. With a little pun on
320-
Julia Base, `oneunit` applied to an elementary space (in the value or type domain) returns
321-
the one-dimensional space, which is isomorphic to the scalar field of the space itself. Some
322-
examples illustrate this better
319+
`\oplus`+TAB. This is possible only if `isdual(V1) == isdual(V2)`. `unitspace` applied to an elementary space
320+
(in the value or type domain) returns the one-dimensional space, which is isomorphic to the
321+
scalar field of the space itself. Some examples illustrate this better.
323322
```@repl tensorkit
324323
ℝ^5 ⊕ ℝ^3
325324
ℂ^5 ⊕ ℂ^3
326325
ℂ^5 ⊕ (ℂ^3)'
327-
oneunit(ℝ^3)
328-
ℂ^5 ⊕ oneunit(ComplexSpace)
329-
oneunit((ℂ^3)')
330-
(ℂ^5) ⊕ oneunit((ℂ^5))
331-
(ℂ^5)' ⊕ oneunit((ℂ^5)')
326+
unitspace(ℝ^3)
327+
ℂ^5 ⊕ unitspace(ComplexSpace)
328+
unitspace((ℂ^3)')
329+
(ℂ^5) ⊕ unitspace((ℂ^5))
330+
(ℂ^5)' ⊕ unitspace((ℂ^5)')
332331
```
333332

334333
Finally, while spaces have a partial order, there is no unique infimum or supremum of a two

src/TensorKit.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ module TensorKit
77

88
# Exports
99
#---------
10-
# Types:
10+
# Reexport common sector types:
1111
export Sector, AbstractIrrep, Irrep
12-
export FusionStyle, UniqueFusion, MultipleFusion, MultiplicityFreeFusion,
13-
SimpleFusion, GenericFusion
12+
export FusionStyle, UniqueFusion, MultipleFusion, MultiplicityFreeFusion, SimpleFusion, GenericFusion
13+
export UnitStyle, SimpleUnit, GenericUnit
1414
export BraidingStyle, SymmetricBraiding, Bosonic, Fermionic, Anyonic, NoBraiding
1515
export Trivial, Z2Irrep, Z3Irrep, Z4Irrep, ZNIrrep, U1Irrep, SU2Irrep, CU1Irrep
1616
export ProductSector
1717
export FermionParity, FermionNumber, FermionSpin
1818
export FibonacciAnyon, IsingAnyon
1919

20+
# Export common vector space, fusion tree and tensor types
2021
export VectorSpace, Field, ElementarySpace # abstract vector spaces
2122
export InnerProductStyle, NoInnerProduct, HasInnerProduct, EuclideanInnerProduct
2223
export ComplexSpace, CartesianSpace, GeneralSpace, GradedSpace # concrete spaces
@@ -30,18 +31,19 @@ export DiagonalTensorMap, BraidingTensor
3031
export TruncationScheme
3132
export SpaceMismatch, SectorMismatch, IndexError # error types
3233

33-
# general vector space methods
34-
export space, field, dual, dim, reduceddim, dims, fuse, flip, isdual, oplus, ominus,
35-
insertleftunit, insertrightunit, removeunit
36-
37-
# partial order for vector spaces
34+
# Export general vector space methods
35+
export space, field, dual, dim, reduceddim, dims, fuse, flip, isdual
36+
export unitspace, zerospace, oplus, ominus
37+
export insertleftunit, insertrightunit, removeunit
3838
export infimum, supremum, isisomorphic, ismonomorphic, isepimorphic
3939

40-
# methods for sectors and properties thereof
41-
export sectortype, sectors, hassector, Nsymbol, Fsymbol, Rsymbol, Bsymbol,
42-
frobeniusschur, twist, otimes, sectorscalartype, deligneproduct
40+
# Reexport methods for sectors and properties thereof
41+
export sectortype, sectors, hassector
42+
export unit, rightunit, leftunit, allunits, isunit, otimes
43+
export Nsymbol, Fsymbol, Rsymbol, Bsymbol, frobenius_schur_phase, frobenius_schur_indicator, twist, sectorscalartype, deligneproduct
44+
45+
# Export methods for fusion trees
4346
export fusiontrees, braid, permute, transpose
44-
export ZNSpace, SU2Irrep, U1Irrep, CU1Irrep
4547
# other fusion tree manipulations, should not be exported:
4648
# export insertat, split, merge, repartition, artin_braid,
4749
# bendleft, bendright, foldleft, foldright, cycleclockwise, cycleanticlockwise
@@ -52,9 +54,9 @@ export ℤ₂, ℤ₃, ℤ₄, U₁, SU, SU₂, CU₁
5254
export fℤ₂, fU₁, fSU₂
5355
export ℤ₂Space, ℤ₃Space, ℤ₄Space, U₁Space, CU₁Space, SU₂Space
5456

55-
# tensor maps
57+
# Export tensor map methods
5658
export domain, codomain, numind, numout, numin, domainind, codomainind, allind
57-
export spacetype, sectortype, storagetype, scalartype, tensormaptype
59+
export spacetype, storagetype, scalartype, tensormaptype
5860
export blocksectors, blockdim, block, blocks
5961

6062
# random methods for constructor

src/fusiontrees/fusiontrees.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct FusionTree{I <: Sector, N, M, L}
3434
) where
3535
{I <: Sector, N, M, L}
3636
# if N == 0
37-
# @assert coupled == one(coupled)
37+
# @assert coupled == unit(coupled)
3838
# elseif N == 1
3939
# @assert coupled == uncoupled[1]
4040
# elseif N == 2
@@ -89,7 +89,7 @@ function FusionTree(
8989
end
9090

9191
function FusionTree{I}(
92-
uncoupled::NTuple{N}, coupled = one(I), isdual = ntuple(n -> false, N)
92+
uncoupled::NTuple{N}, coupled = unit(I), isdual = ntuple(Returns(false), N)
9393
) where {I <: Sector, N}
9494
FusionStyle(I) isa UniqueFusion ||
9595
error("fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`")
@@ -103,7 +103,7 @@ function FusionTree(
103103
) where {N, I <: Sector}
104104
return FusionTree{I}(uncoupled, coupled, isdual)
105105
end
106-
FusionTree(uncoupled::Tuple{I, Vararg{I}}) where {I <: Sector} = FusionTree(uncoupled, one(I))
106+
FusionTree(uncoupled::Tuple{I, Vararg{I}}) where {I <: Sector} = FusionTree(uncoupled, unit(I))
107107

108108
# Properties
109109
sectortype(::Type{<:FusionTree{I}}) where {I <: Sector} = I
@@ -159,17 +159,17 @@ end
159159

160160
# converting to actual array
161161
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, 0}) where {I}
162-
X = convert(A, fusiontensor(one(I), one(I), one(I)))[1, 1, :]
162+
X = convert(A, fusiontensor(unit(I), unit(I), unit(I)))[1, 1, :]
163163
return X
164164
end
165165
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, 1}) where {I}
166166
c = f.coupled
167167
if f.isdual[1]
168168
sqrtdc = sqrtdim(c)
169-
Zcbartranspose = sqrtdc * convert(A, fusiontensor(conj(c), c, one(c)))[:, :, 1, 1]
169+
Zcbartranspose = sqrtdc * convert(A, fusiontensor(dual(c), c, unit(c)))[:, :, 1, 1]
170170
X = conj!(Zcbartranspose) # we want Zcbar^†
171171
else
172-
X = convert(A, fusiontensor(c, one(c), c))[:, 1, :, 1, 1]
172+
X = convert(A, fusiontensor(c, unit(c), c))[:, 1, :, 1, 1]
173173
end
174174
return X
175175
end
@@ -257,13 +257,13 @@ include("iterator.jl")
257257
# _abelianinner: generate the inner indices for given outer indices in the abelian case
258258
_abelianinner(outer::Tuple{}) = ()
259259
function _abelianinner(outer::Tuple{I}) where {I <: Sector}
260-
return isone(outer[1]) ? () : throw(SectorMismatch())
260+
return isunit(outer[1]) ? () : throw(SectorMismatch())
261261
end
262262
function _abelianinner(outer::Tuple{I, I}) where {I <: Sector}
263263
return outer[1] == dual(outer[2]) ? () : throw(SectorMismatch())
264264
end
265265
function _abelianinner(outer::Tuple{I, I, I}) where {I <: Sector}
266-
return isone(first((outer...))) ? () : throw(SectorMismatch())
266+
return isunit(first((outer...))) ? () : throw(SectorMismatch())
267267
end
268268
function _abelianinner(outer::Tuple{I, I, I, I, Vararg{I}}) where {I <: Sector}
269269
c = first(outer[1] outer[2])

src/fusiontrees/iterator.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
fusiontrees(uncoupled::NTuple{N,I}[,
3-
coupled::I=one(I)[, isdual::NTuple{N,Bool}=ntuple(n -> false, length(uncoupled))]])
3+
coupled::I=unit(I)[, isdual::NTuple{N,Bool}=ntuple(n -> false, length(uncoupled))]])
44
where {N,I<:Sector} -> FusionTreeIterator{I,N,I}
55
66
Return an iterator over all fusion trees with a given coupled sector label `coupled` and
@@ -17,7 +17,7 @@ function fusiontrees(uncoupled::Tuple{Vararg{I}}, coupled::I) where {I <: Sector
1717
return fusiontrees(uncoupled, coupled, isdual)
1818
end
1919
function fusiontrees(uncoupled::Tuple{I, Vararg{I}}) where {I <: Sector}
20-
coupled = one(I)
20+
coupled = unit(I)
2121
isdual = ntuple(n -> false, length(uncoupled))
2222
return fusiontrees(uncoupled, coupled, isdual)
2323
end
@@ -38,7 +38,7 @@ Base.IteratorEltype(::FusionTreeIterator) = Base.HasEltype()
3838
Base.eltype(::Type{<:FusionTreeIterator{I, N}}) where {I <: Sector, N} = fusiontreetype(I, N)
3939

4040
Base.length(iter::FusionTreeIterator) = _fusiondim(iter.uncouplediterators, iter.coupled)
41-
_fusiondim(::Tuple{}, c::I) where {I <: Sector} = Int(isone(c))
41+
_fusiondim(::Tuple{}, c::I) where {I <: Sector} = Int(isunit(c))
4242
_fusiondim(iters::NTuple{1}, c::I) where {I <: Sector} = Int(c iters[1])
4343
function _fusiondim(iters::NTuple{2}, c::I) where {I <: Sector}
4444
d = 0
@@ -60,7 +60,7 @@ end
6060

6161
# * Iterator methods:
6262
# Start with special cases:
63-
function Base.iterate(it::FusionTreeIterator{I, 0}, state = !isone(it.coupled)) where {I <: Sector}
63+
function Base.iterate(it::FusionTreeIterator{I, 0}, state = !isunit(it.coupled)) where {I <: Sector}
6464
state && return nothing
6565
tree = FusionTree{I}((), it.coupled, (), (), ())
6666
return tree, true

0 commit comments

Comments
 (0)