Skip to content

Commit

Permalink
Merge pull request #13 from Jutho/tensorkit-0.13
Browse files Browse the repository at this point in the history
Tensorkit v0.13
  • Loading branch information
Jutho authored Nov 5, 2024
2 parents d136b39 + 6ec6779 commit d7e11e2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 53 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6' # LTS version
- 'lts' # LTS version
- '1' # automatically expands to the latest stable 1.x release of Julia
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
# - x86
# exclude:
# - os: macOS-latest
# arch: x86
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "TensorKitManifolds"
uuid = "11fa318c-39cb-4a83-b1ed-cdc7ba1e3684"
authors = ["Jutho Haegeman <[email protected]>", "Markus Hauru <[email protected]>"]
version = "0.7"
version = "0.7.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"

[compat]
TensorKit = "0.12.1"
julia = "1.6"
TensorKit = "0.13"
julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 2 additions & 2 deletions src/grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ mutable struct GrassmannTangent{T<:AbstractTensorMap,
U::Union{Nothing,TU}
S::Union{Nothing,TS}
V::Union{Nothing,TV}
function GrassmannTangent(W::AbstractTensorMap{S,N₁,N₂},
Z::AbstractTensorMap{S,N₁,N₂}) where {S,N₁,N₂}
function GrassmannTangent(W::AbstractTensorMap{TT₁,S,N₁,N₂},
Z::AbstractTensorMap{TT₂,S,N₁,N₂}) where {TT₁,TT₂,S,N₁,N₂}
T = typeof(W)
TT = promote_type(float(scalartype(W)), scalartype(Z))
M = similarstoragetype(W, TT)
Expand Down
47 changes: 17 additions & 30 deletions src/stiefel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,18 @@ function stiefelexp(W::AbstractTensorMap,
A::AbstractTensorMap,
Z::AbstractTensorMap,
α::Real)
S = spacetype(W)
G = sectortype(W)
Wdata′ = TensorKit.SectorDict{G,storagetype(W)}()
Qdata = TensorKit.SectorDict{G,storagetype(W)}()
Qdata′ = TensorKit.SectorDict{G,storagetype(W)}()
Rdata′ = TensorKit.SectorDict{G,storagetype(W)}()
dims = TensorKit.SectorDict{G,Int}()
for c in blocksectors(W)
w′, q, q′, r′ = _stiefelexp(block(W, c), block(A, c), block(Z, c), α)
Wdata′[c] = w′
Qdata[c] = q
Qdata′[c] = q′
Rdata′[c] = r′
dims[c] = size(q, 2)
V = fuse(domain(W))
W′ = similar(W)
Q = similar(W, codomain(W) V)
Q′ = similar(Q)
R′ = similar(W, V domain(W))
for (c, b) in blocks(W)
w′, q, q′, r′ = _stiefelexp(b, block(A, c), block(Z, c), α)
copy!(block(W′, c), w′)
copy!(block(Q, c), q)
copy!(block(Q′, c), q′)
copy!(block(R′, c), r′)
end
V = S(dims)
W′ = TensorMap(Wdata′, space(W))
Q = TensorMap(Qdata, codomain(W) V)
Q′ = TensorMap(Qdata′, codomain(W) V)
R′ = TensorMap(Rdata′, V domain(W))
return W′, Q, Q′, R′
end

Expand All @@ -201,18 +193,13 @@ end
function invretract_exp(Wold::AbstractTensorMap, Wnew::AbstractTensorMap;
tol=scalareps(Wold)^(2 / 3))
space(Wold) == space(Wnew) || throw(SectorMismatch())

S = spacetype(Wold)
G = sectortype(Wold)
Adata = TensorKit.SectorDict{G,storagetype(Wold)}()
Zdata = TensorKit.SectorDict{G,storagetype(Wold)}()
for c in blocksectors(Wold)
a, q, r = _stiefellog(block(Wold, c), block(Wnew, c); tol=tol)
Adata[c] = a
Zdata[c] = q * r
A = similar(Wold, domain(Wold) domain(Wold))
Z = similar(Wold, space(Wold))
for (c, b) in blocks(Wold)
a, q, r = _stiefellog(b, block(Wnew, c); tol)
copy!(block(A, c), a)
mul!(block(Z, c), q, r)
end
A = TensorMap(Adata, domain(Wold) domain(Wold))
Z = TensorMap(Zdata, space(Wold))
return StiefelTangent(Wold, A, Z)
end

Expand Down
4 changes: 2 additions & 2 deletions src/unitary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import ..TensorKitManifolds: base, checkbase, inner, retract, transport, transpo
struct UnitaryTangent{T<:AbstractTensorMap,TA<:AbstractTensorMap}
W::T
A::TA
function UnitaryTangent(W::AbstractTensorMap{S,N₁,N₂},
A::AbstractTensorMap{S,N₂,N₂}) where {S,N₁,N₂}
function UnitaryTangent(W::AbstractTensorMap{T₁,S,N₁,N₂},
A::AbstractTensorMap{T₂,S,N₂,N₂}) where {T₁,T₂,S,N₁,N₂}
T = typeof(W)
TA = typeof(A)
return new{T,TA}(W, A)
Expand Down
22 changes: 11 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const α = 0.75

@testset "Grassmann with space $V" for V in spaces
for T in (Float64,)
W, = leftorth(TensorMap(randn, T, V * V * V, V * V); alg=Polar())
X = TensorMap(randn, T, space(W))
Y = TensorMap(randn, T, space(W))
W, = leftorth(randn(T, V * V * V, V * V); alg=Polar())
X = randn(T, space(W))
Y = randn(T, space(W))
Δ = @inferred Grassmann.project(X, W)
Θ = Grassmann.project(Y, W)
γ = randn(T)
Expand Down Expand Up @@ -42,7 +42,7 @@ const α = 0.75
@test Grassmann.inner(W2, Δ2, Θ2) Grassmann.inner(W, Δ, Θ)
@test Grassmann.inner(W2, Ξ2, Θ2) Grassmann.inner(W, Ξ, Θ)

Wend = TensorMap(randhaar, T, codomain(W), domain(W))
Wend = randisometry(T, codomain(W), domain(W))
Δ3, V = Grassmann.invretract(W, Wend)
@test Wend retract(W, Δ3, 1)[1] * V
U = Grassmann.relativegauge(W, Wend)
Expand All @@ -53,9 +53,9 @@ end

@testset "Stiefel with space $V" for V in spaces
for T in (Float64, ComplexF64)
W = TensorMap(randhaar, T, V * V * V, V * V)
X = TensorMap(randn, T, space(W))
Y = TensorMap(randn, T, space(W))
W = randisometry(T, V * V * V, V * V)
X = randn(T, space(W))
Y = randn(T, space(W))
Δ = @inferred Stiefel.project_euclidean(X, W)
Θ = Stiefel.project_canonical(Y, W)
γ = rand()
Expand Down Expand Up @@ -116,17 +116,17 @@ end
@test Stiefel.inner_canonical(W2, Δ2, Θ2) Stiefel.inner_canonical(W, Δ, Θ)
@test Stiefel.inner_canonical(W2, Ξ2, Θ2) Stiefel.inner_canonical(W, Ξ, Θ)

W3 = projectisometric!(W + 1e-1 * TensorMap(rand, T, codomain(W), domain(W)))
W3 = projectisometric!(W + 1e-1 * rand(T, codomain(W), domain(W)))
Δ3 = Stiefel.invretract(W, W3)
@test W3 retract(W, Δ3, 1)[1]
end
end

@testset "Unitary with space $V" for V in spaces
for T in (Float64, ComplexF64)
W, = leftorth(TensorMap(randn, T, V * V * V, V * V); alg=Polar())
X = TensorMap(randn, T, space(W))
Y = TensorMap(randn, T, space(W))
W, = leftorth(randn(T, V * V * V, V * V); alg=Polar())
X = randn(T, space(W))
Y = randn(T, space(W))
Δ = @inferred Unitary.project(X, W)
Θ = Unitary.project(Y, W)
γ = randn()
Expand Down

2 comments on commit d7e11e2

@Jutho
Copy link
Owner Author

@Jutho Jutho commented on d7e11e2 Nov 5, 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/118730

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.7.1 -m "<description of version>" d7e11e27db54b018c4bd879e6a6080c76c69069d
git push origin v0.7.1

Please sign in to comment.