Skip to content

Commit 7ccd853

Browse files
authored
adapt to GradedArrays v0.4 (#56)
1 parent d891cbb commit 7ccd853

18 files changed

+247
-201
lines changed

Project.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FusionTensors"
22
uuid = "e16ca583-1f51-4df0-8e12-57d32947d33e"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.3.2"
4+
version = "0.4.0"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -18,16 +18,16 @@ TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
1818
WignerSymbols = "9f57e263-0b3d-5e2e-b1be-24f2bb48858b"
1919

2020
[compat]
21-
Accessors = "0.1.39"
22-
BlockArrays = "1.2.0"
23-
BlockSparseArrays = "0.4.0"
24-
GradedArrays = "0.2.1"
25-
HalfIntegers = "1.6.0"
26-
LRUCache = "1.6.1"
27-
LinearAlgebra = "1.10.0"
28-
Strided = "2.2.0"
29-
TensorAlgebra = "0.2.4"
30-
TensorProducts = "0.1.3"
31-
TypeParameterAccessors = "0.3.0"
21+
Accessors = "0.1.42"
22+
BlockArrays = "1.6"
23+
BlockSparseArrays = "0.7.4"
24+
GradedArrays = "0.4.7"
25+
HalfIntegers = "1.6"
26+
LRUCache = "1.6"
27+
LinearAlgebra = "1.10"
28+
Strided = "2.3"
29+
TensorAlgebra = "0.3.8"
30+
TensorProducts = "0.1.7"
31+
TypeParameterAccessors = "0.4"
3232
WignerSymbols = "2.0.0"
3333
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
55

66
[compat]
77
Documenter = "1.10.0"
8-
FusionTensors = "0.3.0"
8+
FusionTensors = "0.4"
99
Literate = "2.20.1"

src/fusion_trees/clebsch_gordan_tensors.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
using HalfIntegers: half
66
using WignerSymbols: clebschgordan
77

8-
using GradedArrays: dual
9-
using GradedArrays.SymmetrySectors:
8+
using GradedArrays:
109
AbelianStyle,
1110
AbstractSector,
1211
NotAbelianStyle,
13-
SymmetryStyle,
1412
O2,
1513
SU,
14+
SymmetryStyle,
15+
dual,
1616
istrivial,
1717
quantum_dimension,
1818
sector_label,
19+
sectors,
1920
trivial,
2021
zero_odd
2122
using TensorAlgebra: contract
@@ -66,7 +67,7 @@ function clebsch_gordan_tensor(s1::O2, s2::O2, s3::O2)
6667
d2 = quantum_dimension(s2)
6768
d3 = quantum_dimension(s3)
6869
cgt = zeros((d1, d2, d3))
69-
s3 blocklabels(s1 s2) && return cgt
70+
s3 sectors(s1 s2) && return cgt
7071

7172
# adapted from TensorKit
7273
l1 = sector_label(s1)

src/fusion_trees/fusiontree.jl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
# TBD
44
# compatibility with TensorKit conventions?
55

6-
using GradedArrays: GradedArrays, AbstractGradedUnitRange, flip, isdual, sector_type
7-
using GradedArrays.SymmetrySectors:
6+
using GradedArrays:
7+
GradedArrays,
88
×,
9+
AbstractGradedUnitRange,
910
AbstractSector,
1011
SectorProduct,
11-
SymmetrySectors,
1212
arguments,
13+
flip,
14+
flip_dual,
15+
isdual,
1316
nsymbol,
17+
sector_multiplicities,
18+
sector_type,
19+
sectors,
1420
to_gradedrange,
1521
trivial
1622
using TensorAlgebra: flatten_tuples
@@ -41,7 +47,7 @@ using TensorProducts: ⊗
4147
#
4248
#
4349
# The interface uses AbstractGradedArrays as input for interface simplicity
44-
# however only blocklabels are used and blocklengths are never read.
50+
# however only sectors are used and blocklengths are never read.
4551

4652
struct SectorFusionTree{S,N,M}
4753
leaves::NTuple{N,S} # TBD rename outer_sectors or leave_sectors?
@@ -98,8 +104,7 @@ function GradedArrays.flip(f::SectorFusionTree)
98104
)
99105
end
100106

101-
# SymmetrySectors interface
102-
function SymmetrySectors.:×(f1::SectorFusionTree, f2::SectorFusionTree)
107+
function GradedArrays.:×(f1::SectorFusionTree, f2::SectorFusionTree)
103108
@assert arrows(f1) == arrows(f2)
104109
product_leaves = (leaves(f1), leaves(f2))
105110
product_root_sector = root_sector(f1) × root_sector(f2)
@@ -120,7 +125,7 @@ function SymmetrySectors.:×(f1::SectorFusionTree, f2::SectorFusionTree)
120125
)
121126
end
122127

123-
function SymmetrySectors.arguments(f::SectorFusionTree{<:SectorProduct})
128+
function GradedArrays.arguments(f::SectorFusionTree{<:SectorProduct})
124129
transposed_indices = outer_multiplicity_split.(
125130
Base.tail(leaves(f)),
126131
branch_sectors(f),
@@ -144,11 +149,11 @@ function SymmetrySectors.arguments(f::SectorFusionTree{<:SectorProduct})
144149
)
145150
end
146151

147-
function SymmetrySectors.arguments(f::SectorFusionTree{<:SectorProduct,0})
152+
function GradedArrays.arguments(f::SectorFusionTree{<:SectorProduct,0})
148153
return map(arg -> SectorFusionTree((), (), arg, (), ()), arguments(root_sector(f)))
149154
end
150155

151-
function SymmetrySectors.arguments(f::SectorFusionTree{<:SectorProduct,1})
156+
function GradedArrays.arguments(f::SectorFusionTree{<:SectorProduct,1})
152157
arguments_root = arguments(root_sector(f))
153158
arguments_leave = arguments(only(leaves(f)))
154159
# use map(keys) to stay agnostic with respect to SectorProduct implementation
@@ -164,7 +169,7 @@ fusiontree_eltype(::Type{<:AbstractSector}) = Float64
164169
function build_trees(legs::Vararg{AbstractGradedUnitRange})
165170
# construct all authorized trees for each outer block in legs
166171
tree_arrows = isdual.(legs)
167-
return mapreduce(vcat, Iterators.product(blocklabels.(legs)...)) do it
172+
return mapreduce(vcat, Iterators.product(sectors.(flip_dual.(legs))...)) do it
168173
return build_trees(it, tree_arrows)
169174
end
170175
end
@@ -240,7 +245,9 @@ function fuse_next_sector(
240245
parent_tree::SectorFusionTree, branch_sector::AbstractSector, level_arrow::Bool
241246
)
242247
new_space = to_gradedrange(root_sector(parent_tree) branch_sector)
243-
return mapreduce(vcat, zip(blocklabels(new_space), blocklengths(new_space))) do (la, n)
248+
return mapreduce(
249+
vcat, zip(sectors(new_space), sector_multiplicities(new_space))
250+
) do (la, n)
244251
return [
245252
append_tree_leave(parent_tree, branch_sector, level_arrow, la, outer_mult) for
246253
outer_mult in 1:n

src/fusiontensor/array_cast.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
using BlockArrays: AbstractBlockArray, BlockedArray, blockedrange, blocklengths, findblock
44

55
using BlockSparseArrays: BlockSparseArrays, BlockSparseArray
6-
using GradedArrays: AbstractGradedUnitRange, blocklabels
7-
using GradedArrays.SymmetrySectors: block_dimensions, quantum_dimension
6+
using GradedArrays: AbstractGradedUnitRange, quantum_dimension
87
using TensorAlgebra: contract
98

109
# ================================= High level interface =================================
@@ -20,11 +19,13 @@ end
2019
function to_fusiontensor(
2120
array::AbstractArray,
2221
codomain_legs::Tuple{Vararg{AbstractGradedUnitRange}},
23-
domain_legs::Tuple{Vararg{AbstractGradedUnitRange}},
22+
domain_legs::Tuple{Vararg{AbstractGradedUnitRange}};
23+
atol::Real=0,
24+
rtol::Real=rtoldefault(array),
2425
)
25-
bounds = block_dimensions.((codomain_legs..., domain_legs...))
26+
bounds = blocklengths.((codomain_legs..., domain_legs...))
2627
blockarray = BlockedArray(array, bounds...)
27-
return to_fusiontensor(blockarray, codomain_legs, domain_legs)
28+
return to_fusiontensor(blockarray, codomain_legs, domain_legs; atol, rtol)
2829
end
2930

3031
rtoldefault(a::AbstractArray) = rtoldefault(eltype(a))
@@ -72,7 +73,7 @@ function to_fusiontensor_no_checknorm(
7273
end
7374

7475
function to_array(ft::FusionTensor)
75-
bounds = block_dimensions.((codomain_axes(ft)..., domain_axes(ft)...))
76+
bounds = blocklengths.((codomain_axes(ft)..., domain_axes(ft)...))
7677
bsa = BlockSparseArray{eltype(ft)}(undef, blockedrange.(bounds))
7778
for (f1, f2) in keys(trees_block_mapping(ft))
7879
b = findblock(ft, f1, f2)

src/fusiontensor/base_interface.jl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ function Base.:*(left::FusionTensor, right::FusionTensor)
1717
return FusionTensor(new_data_matrix, codomain_axes(left), domain_axes(right))
1818
end
1919

20-
Base.:+(ft::FusionTensor) = ft
21-
2220
# tensor addition is a block data_matrix add.
2321
function Base.:+(left::FusionTensor, right::FusionTensor)
2422
checkaxes(axes(left), axes(right))
@@ -89,37 +87,34 @@ function Base.similar(ft::FusionTensor, T::Type)
8987

9088
# some fusion trees have Float64 eltype: need compatible type
9189
@assert promote_type(T, fusiontree_eltype(sector_type(ft))) === T
92-
mat = similar(data_matrix(ft), T)
93-
initialize_allowed_sectors!(mat)
90+
mat = initialize_data_matrix(T, codomain_axis(ft), domain_axis(ft))
9491
return FusionTensor(mat, axes(ft), trees_block_mapping(ft))
9592
end
9693

97-
# trigger explicit error in TensorAlgebra.contract
98-
# TBD impose some convention? Remove?
9994
function Base.similar(
100-
ft::FusionTensor,
101-
T::Type,
102-
new_axes::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}},
95+
::FusionTensor, ::Type, t::Tuple{AbstractGradedUnitRange,Vararg{AbstractGradedUnitRange}}
10396
)
104-
throw(DimensionMismatch("Need bituple of axes"))
97+
throw(MethodError(similar, (typeof(t),)))
10598
end
106-
function Base.similar(ft::FusionTensor, T::Type, new_axes::Tuple{})
107-
throw(DimensionMismatch("Need bituple of axes"))
99+
function Base.similar(::FusionTensor, ::Type, ::Tuple{})
100+
throw(MethodError(similar, (Tuple{},)))
108101
end
109102

110-
function Base.similar(ft::FusionTensor, T::Type, new_axes::Tuple{<:Tuple,<:Tuple})
103+
function Base.similar(
104+
ft::FusionTensor, ::Type{T}, new_axes::Tuple{<:Tuple,<:Tuple}
105+
) where {T}
111106
return similar(ft, T, tuplemortar(new_axes))
112107
end
113-
function Base.similar(::FusionTensor, T::Type, new_axes::BlockedTuple{2})
108+
function Base.similar(::FusionTensor, ::Type{T}, new_axes::BlockedTuple{2}) where {T}
114109
return FusionTensor(T, new_axes)
115110
end
116111

117112
Base.show(io::IO, ft::FusionTensor) = print(io, "$(ndims(ft))-dim FusionTensor")
118113

119114
function Base.show(io::IO, ::MIME"text/plain", ft::FusionTensor)
120-
println(io, "$(ndims(ft))-dim FusionTensor with axes:")
115+
print(io, "$(ndims(ft))-dim FusionTensor with axes:")
121116
for ax in axes(ft)
122-
println(io, ax)
117+
print(io, "\n", ax)
123118
end
124119
return nothing
125120
end

0 commit comments

Comments
 (0)