Skip to content

Dimension mismatch in SVD pullback due to rank_atol for FixedSVD #351

@pbrehmer

Description

@pbrehmer

I was running into a dimension mismatch error in the pullback of FixedSVD due to the default finite rank_atol for MatrixAlgebraKit's svd_pullback function. Note that we here compute the forward using a full SVD such that we can utilize the full SVD pullback. Here's the full error message:

Details

...the stacktrace before and after this part make the message to long for GitHub...

nested task error: DimensionMismatch: second dimension of ΔU (40) does not match rank of S (25)
    Stacktrace:
      [1] svd_pullback!(ΔA::Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}, A::Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}, USVᴴ::Tuple{Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}, LinearAlgebra.Diagonal{Float64, SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}}, Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}}, ΔUSVᴴ::Vector{Any}, ind::UnitRange{Int64}; rank_atol::Float64, degeneracy_atol::Float64, gauge_atol::Float64)
        @ MatrixAlgebraKit ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/pullbacks/svd.jl:58
      [2] (::TensorKit.Factorizations.var"#163#164"{@Kwargs{gauge_atol::Float64, degeneracy_atol::Float64}, Tuple{TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}, DiagonalTensorMap{Float64, ComplexSpace, Vector{Float64}}, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}}, Vector{Any}, TensorKit.SortedVectorDict{Trivial, UnitRange{Int64}}})(c::Trivial, ::Tuple{Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}, Base.ReshapedArray{ComplexF64, 2, SubArray{ComplexF64, 1, Vector{ComplexF64}, Tuple{UnitRange{Int64}}, true}, Tuple{}}})
        @ TensorKit.Factorizations ~/.julia/packages/TensorKit/JBtTy/src/factorizations/pullbacks.jl:40
      [3] #150
        @ ~/.julia/packages/TensorKit/JBtTy/src/tensors/blockiterator.jl:37 [inlined]
      [4] foreach(f::TensorKit.var"#150#151"{TensorKit.Factorizations.var"#163#164"{@Kwargs{gauge_atol::Float64, degeneracy_atol::Float64}, Tuple{TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}, DiagonalTensorMap{Float64, ComplexSpace, Vector{Float64}}, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}}, Vector{Any}, TensorKit.SortedVectorDict{Trivial, UnitRange{Int64}}}, Tuple{TensorMap{ComplexF64, ComplexSpace, 3, 3, Vector{ComplexF64}}, TensorMap{ComplexF64, ComplexSpace, 3, 3, Vector{ComplexF64}}}}, d::Dictionaries.Indices{Trivial})
        @ Dictionaries ~/.julia/packages/Dictionaries/P05gc/src/foreach.jl:36
      [5] #foreachblock#148
        @ ~/.julia/packages/TensorKit/JBtTy/src/tensors/blockiterator.jl:36 [inlined]
      [6] foreachblock
        @ ~/.julia/packages/TensorKit/JBtTy/src/tensors/blockiterator.jl:33 [inlined]
      [7] #svd_pullback!#161
        @ ~/.julia/packages/TensorKit/JBtTy/src/factorizations/pullbacks.jl:35 [inlined]
      [8] (::PEPSKit.var"#svd_trunc!_full_pullback#72"{TensorMap{ComplexF64, ComplexSpace, 3, 3, Vector{ComplexF64}}, SVDAdjoint{PEPSKit.FixedSVD{TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}, DiagonalTensorMap{Float64, ComplexSpace, Vector{Float64}}, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}, TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}, DiagonalTensorMap{Float64, ComplexSpace, Vector{Float64}}, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}, TensorKit.SortedVectorDict{Trivial, UnitRange{Int64}}}, PEPSKit.FullSVDPullback}, PEPSKit.var"#_get_pullback_gauge_tol##0#_get_pullback_gauge_tol##1", TensorKit.SortedVectorDict{Trivial, UnitRange{Int64}}, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}, DiagonalTensorMap{Float64, ComplexSpace, Vector{Float64}}, TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}})(ΔUSV′::ChainRulesCore.Tangent{Any, Tuple{TensorKit.AdjointTensorMap{ComplexF64, ComplexSpace, 3, 1, TensorMap{ComplexF64, ComplexSpace, 1, 3, Vector{ComplexF64}}}, TensorMap{ComplexF64, ComplexSpace, 1, 1, Vector{ComplexF64}}, TensorKit.AdjointTensorMap{ComplexF64, ComplexSpace, 1, 3, TensorMap{ComplexF64, ComplexSpace, 3, 1, Vector{ComplexF64}}}, ChainRulesCore.ZeroTangent}})
        @ PEPSKit ~/.julia/packages/PEPSKit/coqnJ/src/utility/svd.jl:373

...

I think this could easily be fixed by just setting rank_atol = 0 for FixedSVD. I will open up a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions