From 5155d795fba6c5d1673af44857c33b7d94fef016 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 17:32:26 -0500 Subject: [PATCH 1/6] Update TensorKit compat --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 9d32a65..e98de75 100644 --- a/Project.toml +++ b/Project.toml @@ -1,14 +1,14 @@ name = "TensorKitManifolds" uuid = "11fa318c-39cb-4a83-b1ed-cdc7ba1e3684" authors = ["Jutho Haegeman ", "Markus Hauru "] -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" +TensorKit = "0.13" julia = "1.6" [extras] From 3b53efeed8a53ed6e697a3499f42d1c02cfa7e96 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 17:32:47 -0500 Subject: [PATCH 2/6] update tests: use new constructors --- test/runtests.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index ab9d77f..f9fd9c2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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) @@ -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() @@ -116,7 +116,7 @@ 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 @@ -124,9 +124,9 @@ 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() From 7cc3c06d5ac280e3acce7b3f27710d07aff198ba Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 17:33:12 -0500 Subject: [PATCH 3/6] Fix extra type parameter in TensorMap --- src/grassmann.jl | 4 ++-- src/unitary.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/grassmann.jl b/src/grassmann.jl index 742198c..e4fc1fc 100644 --- a/src/grassmann.jl +++ b/src/grassmann.jl @@ -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) diff --git a/src/unitary.jl b/src/unitary.jl index ea74042..a5b8c2a 100644 --- a/src/unitary.jl +++ b/src/unitary.jl @@ -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) From 462b48544c69f4b50e6c55fda73357867a8021f8 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 17:34:41 -0500 Subject: [PATCH 4/6] Use new format for blocks --- src/stiefel.jl | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/stiefel.jl b/src/stiefel.jl index 16c216a..0c71196 100644 --- a/src/stiefel.jl +++ b/src/stiefel.jl @@ -169,19 +169,17 @@ function stiefelexp(W::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′ + generator = Iterators.map(blocks(W)) do (c, b) + w′, q, q′, r′ = _stiefelexp(b, block(A, c), block(Z, c), α) dims[c] = size(q, 2) + return c => (w′, q, q′, r′) end + wqqr = TensorKit.SectorDict(generator) + Wdata′ = SectorDict(c => w′ for (c, (w′, q, q′, r′)) in wqqr) + Qdata = SectorDict(c => q for (c, (w′, q, q′, r′)) in wqqr) + Qdata′ = SectorDict(c => q′ for (c, (w′, q, q′, r′)) in wqqr) + Rdata′ = SectorDict(c => r′ for (c, (w′, q, q′, r′)) in wqqr) V = S(dims) W′ = TensorMap(Wdata′, space(W)) Q = TensorMap(Qdata, codomain(W) ← V) @@ -201,18 +199,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 From 466c75ca1d2e882b6132dd869a6339fa6946ca8f Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 18:19:41 -0500 Subject: [PATCH 5/6] Update minimal julia version --- .github/workflows/CI.yml | 6 +----- Project.toml | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f56ac38..db92e43 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -21,7 +21,7 @@ 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 @@ -29,10 +29,6 @@ jobs: - windows-latest arch: - x64 - # - x86 - # exclude: - # - os: macOS-latest - # arch: x86 steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 diff --git a/Project.toml b/Project.toml index e98de75..a40ad6e 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,7 @@ TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec" [compat] TensorKit = "0.13" -julia = "1.6" +julia = "1.10" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From 6ec6779f42b5b68937f08476d28ade08de7c9e85 Mon Sep 17 00:00:00 2001 From: Lukas Devos Date: Mon, 4 Nov 2024 18:37:18 -0500 Subject: [PATCH 6/6] Update implementation `stiefelexp` --- src/stiefel.jl | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/stiefel.jl b/src/stiefel.jl index 0c71196..dd6b602 100644 --- a/src/stiefel.jl +++ b/src/stiefel.jl @@ -167,24 +167,18 @@ function stiefelexp(W::AbstractTensorMap, A::AbstractTensorMap, Z::AbstractTensorMap, α::Real) - S = spacetype(W) - G = sectortype(W) - dims = TensorKit.SectorDict{G,Int}() - generator = Iterators.map(blocks(W)) do (c, b) + 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), α) - dims[c] = size(q, 2) - return c => (w′, q, q′, r′) + copy!(block(W′, c), w′) + copy!(block(Q, c), q) + copy!(block(Q′, c), q′) + copy!(block(R′, c), r′) end - wqqr = TensorKit.SectorDict(generator) - Wdata′ = SectorDict(c => w′ for (c, (w′, q, q′, r′)) in wqqr) - Qdata = SectorDict(c => q for (c, (w′, q, q′, r′)) in wqqr) - Qdata′ = SectorDict(c => q′ for (c, (w′, q, q′, r′)) in wqqr) - Rdata′ = SectorDict(c => r′ for (c, (w′, q, q′, r′)) in wqqr) - 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