Skip to content

Commit

Permalink
some cleanup for v0.14 (#191)
Browse files Browse the repository at this point in the history
* some cleanup for v0.14

* try to remove some constprop macros

* bump version

* restore constprop

* remove unused compat entry

---------

Co-authored-by: Lukas Devos <[email protected]>
  • Loading branch information
Jutho and lkdvos authored Dec 19, 2024
1 parent a8aa774 commit 00eb107
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
17 changes: 17 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ Features that are planned to be implemented before the release of v1.0.0, in no

## v0.14

### Use `DiagonalTensorMap` for singular values and eigenvalues

The diagonal (1,1) tensor that contains the singular values or eigenvalues of a tensor
are now explicitly represented as `DiagonalTensorMap` instances.

### New index functionality
There are is new functionality for manipulating the spaces associated with a tensor:
* `flip(t, i)` changes the duality flag of the `i`th index of `t`, in such a way that flipping
a pair of contracted indices in an `@tensor` contraction does not affect the result.
* `insertleftunit(t, i)` and `insertrightunit(t, i)` insert a trivial unit space to the left
or to right of index `i`, whereas `removeunit(t, i)` removes such a trivial unit space.

### SVD truncation change (breaking)
There is a subtle but breaking change in the truncation mechanism in SVD, where now it is
guaranteed that smaller singular values are removed first, irrespective of the (quantum)
dimension of the sector to which they belong

### `DiagonalTensorMap` and `reduceddim`

This adds a `DiagonalTensorMap` type for representing tensor maps in which all of the
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorKit"
uuid = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
authors = ["Jutho Haegeman"]
version = "0.13.2"
version = "0.14"

[deps]
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
Expand Down
1 change: 1 addition & 0 deletions docs/src/lib/spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ There are also specific methods for `HomSpace` instances, that are used in deter
the resuling `HomSpace` after applying certain tensor operations.

```@docs
flip(W::HomSpace{S}, I) where {S}
TensorKit.permute(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
TensorKit.select(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
TensorKit.compose(::HomSpace{S}, ::HomSpace{S}) where {S}
Expand Down
1 change: 1 addition & 0 deletions docs/src/lib/tensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ permute(::AbstractTensorMap, ::Index2Tuple{N₁,N₂}; ::Bool) where {N₁,N₂}
braid(::AbstractTensorMap, ::Index2Tuple, ::IndexTuple; ::Bool)
transpose(::AbstractTensorMap, ::Index2Tuple; ::Bool)
repartition(::AbstractTensorMap, ::Int, ::Int; ::Bool)
flip(t::AbstractTensorMap, I)
twist(::AbstractTensorMap, ::Int; ::Bool)
insertleftunit(::AbstractTensorMap, ::Int)
insertrightunit(::AbstractTensorMap, ::Int)
Expand Down
3 changes: 2 additions & 1 deletion src/TensorKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ import TensorKitSectors: dim, BraidingStyle, FusionStyle, ⊠, ⊗
import TensorKitSectors: dual, type_repr
import TensorKitSectors: twist

using Base: @boundscheck, @propagate_inbounds, OneTo, tail, front,
using Base: @boundscheck, @propagate_inbounds, @constprop,
OneTo, tail, front,
tuple_type_head, tuple_type_tail, tuple_type_cons,
SizeUnknown, HasLength, HasShape, IsInfinite, EltypeUnknown, HasEltype
using Base.Iterators: product, filter
Expand Down
9 changes: 0 additions & 9 deletions src/auxiliary/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ end
@noinline _boundserror(P, i) = throw(BoundsError(P, i))
@noinline _nontrivialspaceerror(P, i) = throw(ArgumentError(lazy"Attempting to remove a non-trivial space $(P[i])"))

# Compat implementation:
@static if VERSION < v"1.7"
macro constprop(setting, ex)
return esc(ex)
end
else
using Base: @constprop
end

const VecOrNumber{T<:Number} = Union{DenseVector{T},T}

"""
Expand Down
13 changes: 6 additions & 7 deletions src/tensors/indexmanipulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
"""
@constprop :aggressive function insertleftunit(t::AbstractTensorMap,
i::Int=numind(t) + 1; copy::Bool=true,
conj::Bool=false, dual::Bool=false)
@constprop :aggressive function insertleftunit(t::AbstractTensorMap, i::Int=numind(t) + 1;
copy::Bool=true, conj::Bool=false,
dual::Bool=false)
W = insertleftunit(space(t), i; conj, dual)
tdst = similar(t, W)
for (c, b) in blocks(t)
Expand All @@ -314,8 +314,8 @@ See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
return tdst
end
@constprop :aggressive function insertleftunit(t::TensorMap, i::Int=numind(t) + 1;
copy::Bool=false,
conj::Bool=false, dual::Bool=false)
copy::Bool=false, conj::Bool=false,
dual::Bool=false)
W = insertleftunit(space(t), i; conj, dual)
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
end
Expand Down Expand Up @@ -360,8 +360,7 @@ This operation undoes the work of [`insertunit`](@ref).
W = removeunit(space(t), i)
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
end
@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int;
copy::Bool=true)
@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int; copy::Bool=true)
W = removeunit(space(t), i)
tdst = similar(t, W)
for (c, b) in blocks(t)
Expand Down
21 changes: 19 additions & 2 deletions src/tensors/vectorinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,25 @@ function VectorInterface.inner(tx::AbstractTensorMap, ty::AbstractTensorMap)
InnerProductStyle(tx) === EuclideanInnerProduct() || throw_invalid_innerproduct(:inner)
T = VectorInterface.promote_inner(tx, ty)
s = zero(T)
for c in blocksectors(tx)
s += convert(T, dim(c)) * inner(block(tx, c), block(ty, c))
for ((cx, bx), (cy, by)) in zip(blocks(tx), blocks(ty))
s += convert(T, dim(cx)) * inner(bx, by)
end
return s
end
function VectorInterface.inner(tx::TensorMap, ty::TensorMap)
space(tx) == space(ty) || throw(SpaceMismatch("$(space(tx))$(space(ty))"))
InnerProductStyle(tx) === EuclideanInnerProduct() || throw_invalid_innerproduct(:inner)
if FusionStyle(sectortype(tx)) isa UniqueFusion # all quantum dimensions are one
return inner(tx.data, ty.data)
else
T = VectorInterface.promote_inner(tx, ty)
s = zero(T)
for c in blocksectors(tx)
bx = parent(block(tx, c)) # matrix structure (reshape) does not matter
by = parent(block(ty, c)) # but does lead to slower path in inner
s += convert(T, dim(c)) * inner(bx, by)
end
end
return s
end
# TODO: do we need a fast path for `AdjointTensorMap` instances?

6 comments on commit 00eb107

@Jutho
Copy link
Owner Author

@Jutho Jutho commented on 00eb107 Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121696

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" 00eb107e80e0a4abe1ed5da6e2b7e655c6b416dc
git push origin v0.14.0

@lkdvos
Copy link
Collaborator

@lkdvos lkdvos commented on 00eb107 Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Various index functionalities have been added: flip can be used to change arrows, insertleftunit, insertrightunit and removeunit will manipulate trivial indices.
  • The DiagonalTensorMap is now the default output type for the diagonal singular and eigenvalue tensors returned by tsvd, eig and related functions
  • There is a small change in the truncation of singular values for non-abelian symmetries, where now it is guaranteed that smaller singular values are removed first

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/121696

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" 00eb107e80e0a4abe1ed5da6e2b7e655c6b416dc
git push origin v0.14.0

@lkdvos
Copy link
Collaborator

@lkdvos lkdvos commented on 00eb107 Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Various index functionalities have been added: flip can be used to change arrows, insertleftunit, insertrightunit and removeunit will manipulate trivial indices.

Breaking changes

  • The DiagonalTensorMap is now the default output type for the diagonal singular and eigenvalue tensors returned by tsvd, eig and related functions
  • There is a small change in the truncation of singular values for non-abelian symmetries, where now it is guaranteed that smaller singular values are removed first

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/121696

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" 00eb107e80e0a4abe1ed5da6e2b7e655c6b416dc
git push origin v0.14.0

Please sign in to comment.