-
Notifications
You must be signed in to change notification settings - Fork 126
[GradedAxes] Replace GradedAxes
with GradedAxesNext
#1355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
NDTensors/src/lib/GradedAxes/ext/GradedAxesSectorsExt/Project.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[deps] | ||
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" | ||
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" |
7 changes: 4 additions & 3 deletions
7
NDTensors/src/lib/GradedAxes/ext/GradedAxesSectorsExt/src/GradedAxesSectorsExt.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module GradedAxesSectorsExt | ||
using ..GradedAxes: GradedAxes | ||
using ...Sectors: Sectors, AbstractCategory, ⊗, dual | ||
using ...Sectors: Sectors, AbstractCategory, ⊗ # , dual | ||
|
||
GradedAxes.fuse(c1::AbstractCategory, c2::AbstractCategory) = only(c1 ⊗ c2) | ||
GradedAxes.fuse_labels(c1::AbstractCategory, c2::AbstractCategory) = only(c1 ⊗ c2) | ||
|
||
GradedAxes.dual(c::AbstractCategory) = dual(c) | ||
# TODO: Decide the fate of `dual`. | ||
## GradedAxes.dual(c::AbstractCategory) = dual(c) | ||
end |
8 changes: 4 additions & 4 deletions
8
NDTensors/src/lib/GradedAxes/ext/GradedAxesSectorsExt/test/runtests.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
module GradedAxes | ||
include("groupsortperm.jl") | ||
include("tensor_product.jl") | ||
include("abstractgradedunitrange.jl") | ||
include("gradedunitrange.jl") | ||
include("fusion.jl") | ||
include("../ext/GradedAxesSectorsExt/src/GradedAxesSectorsExt.jl") | ||
end |
150 changes: 0 additions & 150 deletions
150
NDTensors/src/lib/GradedAxes/src/abstractgradedunitrange.jl
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using BlockArrays: BlockedUnitRange | ||
|
||
# TODO: Decide what to do about `dual`. Should there just | ||
# be a version in `Sectors`? | ||
## function dual end | ||
|
||
# Represents the range `1:1` or `Base.OneTo(1)`. | ||
struct OneToOne{T} <: AbstractUnitRange{T} end | ||
OneToOne() = OneToOne{Bool}() | ||
Base.first(a::OneToOne) = one(eltype(a)) | ||
Base.last(a::OneToOne) = one(eltype(a)) | ||
|
||
# https://github.com/ITensor/ITensors.jl/blob/v0.3.57/NDTensors/src/lib/GradedAxes/src/tensor_product.jl | ||
# https://en.wikipedia.org/wiki/Tensor_product | ||
# https://github.com/KeitaNakamura/Tensorial.jl | ||
function tensor_product( | ||
a1::AbstractUnitRange, | ||
a2::AbstractUnitRange, | ||
a3::AbstractUnitRange, | ||
a_rest::Vararg{AbstractUnitRange}, | ||
) | ||
return foldl(tensor_product, (a1, a2, a3, a_rest...)) | ||
end | ||
|
||
function tensor_product(a1::AbstractUnitRange, a2::AbstractUnitRange) | ||
return error("Not implemented yet.") | ||
end | ||
|
||
function tensor_product(a1::Base.OneTo, a2::Base.OneTo) | ||
return Base.OneTo(length(a1) * length(a2)) | ||
end | ||
|
||
function tensor_product(a1::OneToOne, a2::AbstractUnitRange) | ||
return a2 | ||
end | ||
|
||
function tensor_product(a1::AbstractUnitRange, a2::OneToOne) | ||
return a1 | ||
end | ||
|
||
function tensor_product(a1::OneToOne, a2::OneToOne) | ||
return OneToOne() | ||
end | ||
|
||
function fuse_labels(x, y) | ||
return error( | ||
"`fuse_labels` not implemented for object of type `$(typeof(x))` and `$(typeof(y))`." | ||
) | ||
end | ||
|
||
function fuse_blocklengths(x::Integer, y::Integer) | ||
return x * y | ||
end | ||
|
||
using ..LabelledNumbers: LabelledInteger, label, labelled, unlabel | ||
function fuse_blocklengths(x::LabelledInteger, y::LabelledInteger) | ||
return labelled(unlabel(x) * unlabel(y), fuse_labels(label(x), label(y))) | ||
end | ||
|
||
using BlockArrays: blockedrange, blocks | ||
function tensor_product(a1::BlockedUnitRange, a2::BlockedUnitRange) | ||
blocklengths = map(vec(collect(Iterators.product(blocks(a1), blocks(a2))))) do x | ||
return mapreduce(length, fuse_blocklengths, x) | ||
end | ||
return blockedrange(blocklengths) | ||
end | ||
|
||
function blocksortperm(a::BlockedUnitRange) | ||
# TODO: Figure out how to deal with dual sectors. | ||
# TODO: `rev=isdual(a)` may not be correct for symmetries beyond `U(1)`. | ||
## return Block.(sortperm(nondual_sectors(a); rev=isdual(a))) | ||
return Block.(sortperm(blocklabels(a))) | ||
end | ||
|
||
using BlockArrays: Block, BlockVector | ||
using SplitApplyCombine: groupcount | ||
# Get the permutation for sorting, then group by common elements. | ||
# groupsortperm([2, 1, 2, 3]) == [[2], [1, 3], [4]] | ||
function groupsortperm(v; kwargs...) | ||
perm = sortperm(v; kwargs...) | ||
v_sorted = @view v[perm] | ||
group_lengths = collect(groupcount(identity, v_sorted)) | ||
return BlockVector(perm, group_lengths) | ||
end | ||
|
||
# Used by `TensorAlgebra.splitdims` in `BlockSparseArraysGradedAxesExt`. | ||
# Get the permutation for sorting, then group by common elements. | ||
# groupsortperm([2, 1, 2, 3]) == [[2], [1, 3], [4]] | ||
function blockmergesortperm(a::BlockedUnitRange) | ||
# If it is dual, reverse the sorting so the sectors | ||
# end up sorted in the same way whether or not the space | ||
# is dual. | ||
# TODO: Figure out how to deal with dual sectors. | ||
# TODO: `rev=isdual(a)` may not be correct for symmetries beyond `U(1)`. | ||
mtfishman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## return Block.(groupsortperm(nondual_sectors(a); rev=isdual(a))) | ||
return Block.(groupsortperm(blocklabels(a))) | ||
end | ||
|
||
# Used by `TensorAlgebra.splitdims` in `BlockSparseArraysGradedAxesExt`. | ||
invblockperm(a::Vector{<:Block{1}}) = Block.(invperm(Int.(a))) | ||
|
||
# Used by `TensorAlgebra.fusedims` in `BlockSparseArraysGradedAxesExt`. | ||
function blockmergesortperm(a::GradedUnitRange) | ||
# If it is dual, reverse the sorting so the sectors | ||
# end up sorted in the same way whether or not the space | ||
# is dual. | ||
# TODO: Figure out how to deal with dual sectors. | ||
# TODO: `rev=isdual(a)` may not be correct for symmetries beyond `U(1)`. | ||
return Block.(groupsortperm(blocklabels(a))) | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.