Skip to content
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

Expose algorithm kwargs for Grassmann methods #11

Merged
merged 9 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/TensorKitManifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ checkbase(x, y, z, args...) = checkbase(checkbase(x, y), z, args...)
# the machine epsilon for the elements of an object X, name inspired from eltype
scalareps(X) = eps(real(scalartype(X)))

# default SVD algorithm used in the algorithms
default_svd_alg(::AbstractTensorMap) = TensorKit.SVD()

function isisometry(W::AbstractTensorMap; tol=10 * scalareps(W))
WdW = W' * W
s = zero(float(real(scalartype(W))))
Expand Down Expand Up @@ -61,7 +64,7 @@ end

struct PolarNewton <: TensorKit.OrthogonalFactorizationAlgorithm
end
function projectisometric!(W::AbstractTensorMap; alg=Polar())
function projectisometric!(W::AbstractTensorMap; alg=default_svd_alg(W))
if alg isa TensorKit.Polar || alg isa TensorKit.SDD
foreach(blocks(W)) do (c, b)
return _polarsdd!(b)
Expand Down Expand Up @@ -98,7 +101,7 @@ projecthermitian(W::AbstractTensorMap) = projecthermitian!(copy(W))
projectantihermitian(W::AbstractTensorMap) = projectantihermitian!(copy(W))

function projectisometric(W::AbstractTensorMap;
alg::TensorKit.OrthogonalFactorizationAlgorithm=Polar())
alg=default_svd_alg(W))
return projectisometric!(copy(W); alg=alg)
end
function projectcomplement(X::AbstractTensorMap, W::AbstractTensorMap,
Expand Down
17 changes: 9 additions & 8 deletions src/grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Grassmann
using TensorKit
using TensorKit: similarstoragetype, SectorDict
using ..TensorKitManifolds: projecthermitian!, projectantihermitian!,
projectisometric!, projectcomplement!, PolarNewton
projectisometric!, projectcomplement!, PolarNewton,
default_svd_alg
import ..TensorKitManifolds: base, checkbase, inner, retract, transport, transport!

# special type to store tangent vectors using Z
Expand Down Expand Up @@ -56,7 +57,7 @@ function Base.getproperty(Δ::GrassmannTangent, sym::Symbol)
elseif sym ∈ (:U, :S, :V)
v = Base.getfield(Δ, sym)
v !== nothing && return v
U, S, V, = tsvd(Δ.Z)
U, S, V, = tsvd(Δ.Z; alg=default_svd_alg(Δ.Z))
Base.setfield!(Δ, :U, U)
Base.setfield!(Δ, :S, S)
Base.setfield!(Δ, :V, V)
Expand Down Expand Up @@ -191,15 +192,15 @@ for the isometries `U`, `V`, and `Y`, and the diagonal matrix `S`, and returning
`Z = U * S * V` and `Y`.
"""
function invretract(Wold::AbstractTensorMap, Wnew::AbstractTensorMap; alg=nothing)
space(Wold) == space(Wnew) || throw(SectorMismatch())
space(Wold) == space(Wnew) || throw(SpaceMismatch())
WodWn = Wold' * Wnew # V' * cos(S) * V * Y
Wneworth = Wnew - Wold * WodWn
Vd, cS, VY = tsvd!(WodWn)
Vd, cS, VY = tsvd!(WodWn; alg=default_svd_alg(WodWn))
Scmplx = acos(cS)
# acos always returns a complex TensorMap. We cast back to real if possible.
S = scalartype(WodWn) <: Real && isreal(sectortype(Scmplx)) ? real(Scmplx) : Scmplx
UsS = Wneworth * VY' # U * sin(S) # should be in polar decomposition form
U = projectisometric!(UsS; alg=Polar())
U = projectisometric!(UsS)
Y = Vd * VY
V = Vd'
Z = Grassmann.GrassmannTangent(Wold, U * S * V)
Expand All @@ -213,9 +214,9 @@ Return the unitary Y such that V*Y and W are "in the same Grassmann gauge" (tech
from fibre bundles: in the same section), such that they can be related by a Grassmann
retraction.
"""
function relativegauge(W::AbstractTensorMap, V::AbstractTensorMap)
space(W) == space(V) || throw(SectorMismatch())
return projectisometric!(V' * W; alg=Polar())
function relativegauge(W::AbstractTensorMap, V::AbstractTensorMap; alg=nothing)
space(W) == space(V) || throw(SpaceMismatch())
return projectisometric!(V' * W)
end

function transport!(Θ::GrassmannTangent, W::AbstractTensorMap, Δ::GrassmannTangent, α, W′;
Expand Down
Loading