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

Print degenerate singular values warning only during derivation #92

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

pbrehmer
Copy link
Collaborator

@pbrehmer pbrehmer commented Nov 8, 2024

As suggested in #89, this PR will implement the degenerate singular value warning such that it is printed only when CTMRG is being differentiated.

This makes sense since degenerate values shouldn't really be problematic in the forward pass but in the reverse pass degenerate singular values will make the SVD adjoint diverge and thereby render the CTMRG gradient useless.

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/algorithms/ctmrg/ctmrg.jl 92.30% <100.00%> (+0.95%) ⬆️

@pbrehmer
Copy link
Collaborator Author

pbrehmer commented Nov 8, 2024

This can be tested e.g. using a product state PEPS which will lead to a singular value spectrum $S = (1, 0, 0, \dots)$. Correspondingly, the forward pass doesn't print any warnings:

julia> psi = product_peps(2, 2; noise_amp=0);
julia> leading_boundary(CTMRGEnv(psi, ComplexSpace(16)), psi, CTMRG());
[ Info: CTMRG init:     obj = +1.235387069986e-01 -7.116847020371e-02im err = 1.0000e+00
[ Info: CTMRG conv 66:  obj = +1.000000000000e+00       err = 3.3306690739e-16  time = 0.71 sec

But the reverse pass will warn and fail:

fixedpoint(psi, heisenberg_XYZ(InfiniteSquare()), PEPSOptimize(), CTMRGEnv(psi, ComplexSpace(16)))
[ Info: CTMRG init:     obj = +7.495770233902e-02 -1.901630443277e-01im err = 1.0000e+00
[ Info: CTMRG conv 83:  obj = +1.000000000000e+00       err = 2.2204460493e-16  time = 0.23 sec
┌ Warning: degenerate singular values detected: 
│   svals =
│    TensorKit.SortedVectorDict{Trivial, Vector{Float64}} with 1 entry:
│      Trivial() => [1.0, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17,…
└ @ PEPSKit ~/repos/PEPSKit.jl/src/algorithms/ctmrg/ctmrg.jl:280
┌ Warning: degenerate singular values detected: 
│   svals =
│    TensorKit.SortedVectorDict{Trivial, Vector{Float64}} with 1 entry:
│      Trivial() => [1.0, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17,…
└ @ PEPSKit ~/repos/PEPSKit.jl/src/algorithms/ctmrg/ctmrg.jl:280
┌ Warning: degenerate singular values detected: 
│   svals =
│    TensorKit.SortedVectorDict{Trivial, Vector{Float64}} with 1 entry:
│      Trivial() => [1.0, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17,…
└ @ PEPSKit ~/repos/PEPSKit.jl/src/algorithms/ctmrg/ctmrg.jl:280
┌ Warning: degenerate singular values detected: 
│   svals =
│    TensorKit.SortedVectorDict{Trivial, Vector{Float64}} with 1 entry:
│      Trivial() => [1.0, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17, 9.99201e-17,…
└ @ PEPSKit ~/repos/PEPSKit.jl/src/algorithms/ctmrg/ctmrg.jl:280
┌ Warning: Invariant subspace of dimension 2 (up to requested tolerance `tol = 1.0e-8`), which is smaller than the number of requested eigenvalues (i.e. `howmany == 16`); setting `howmany = 2`.
└ @ KrylovKit ~/.julia/packages/KrylovKit/Y0zG7/src/eigsolve/arnoldi.jl:350
┌ Warning: Invariant subspace of dimension 2 (up to requested tolerance `tol = 1.0e-8`), which is smaller than the number of requested eigenvalues (i.e. `howmany == 16`); setting `howmany = 2`.
└ @ KrylovKit ~/.julia/packages/KrylovKit/Y0zG7/src/eigsolve/arnoldi.jl:350
┌ Warning: Invariant subspace of dimension 2 (up to requested tolerance `tol = 1.0e-8`), which is smaller than the number of requested eigenvalues (i.e. `howmany == 16`); setting `howmany = 2`.
└ @ KrylovKit ~/.julia/packages/KrylovKit/Y0zG7/src/eigsolve/arnoldi.jl:350
┌ Warning: Invariant subspace of dimension 2 (up to requested tolerance `tol = 1.0e-8`), which is smaller than the number of requested eigenvalues (i.e. `howmany == 16`); setting `howmany = 2`.
└ @ KrylovKit ~/.julia/packages/KrylovKit/Y0zG7/src/eigsolve/arnoldi.jl:350
...

Copy link
Member

@lkdvos lkdvos left a comment

Choose a reason for hiding this comment

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

Great, thanks for getting this done! Fixes #89

@lkdvos lkdvos merged commit 08cf1dc into master Nov 8, 2024
27 checks passed
@lkdvos lkdvos deleted the pb-degenerate-warning branch November 8, 2024 11:32
@Yue-Zhengyuan
Copy link
Contributor

Thanks! Now I know about Zygote.isderiving 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants