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

svd for Tensor including optional truncation + compression method in progress #326

Merged
merged 8 commits into from
Feb 7, 2025

Conversation

josepamigoo
Copy link
Collaborator

  • Addition of maxdim argumnent in LinearAlgebra.svd in Numerics.jl
  • First steps of compression method for MPS (further development needed)

@mofeing mofeing linked an issue Feb 6, 2025 that may be closed by this pull request
src/Numerics.jl Outdated
@@ -201,6 +201,12 @@ function LinearAlgebra.svd(tensor::Tensor; left_inds=(), right_inds=(), virtuali
s = Tensor(s, [virtualind])
Vt = Tensor(reshape(conj(V), right_sizes..., size(V, 2)), [right_inds..., virtualind])

if maxdim !== nothing
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if maxdim !== nothing
if isnothing(maxdim)

src/Numerics.jl Outdated
Comment on lines 205 to 207
U=view(u, virtualind => 1:maxdim)
s=view(s, virtualind => 1:maxdim)
Vt=view(v, virtualind => 1:maxdim)
Copy link
Member

Choose a reason for hiding this comment

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

just some formatting so that it passes the format check

Suggested change
U=view(u, virtualind => 1:maxdim)
s=view(s, virtualind => 1:maxdim)
Vt=view(v, virtualind => 1:maxdim)
U = view(u, virtualind => 1:maxdim)
s = view(s, virtualind => 1:maxdim)
Vt = view(v, virtualind => 1:maxdim)

@mofeing
Copy link
Member

mofeing commented Feb 6, 2025

thanks @josepamigoo! are you planning to continue working on this PR or do you want to get this PR merged soon?

the compression part is not yet finished but the SVD think could be merged fast, so depending on what you're planning we can move the changes to MPS.jl to another PR or leave it here

@josepamigoo
Copy link
Collaborator Author

i think it would be useful to merge the SVD part first and continue working with the changes to MPS.jl in a separate PR

@mofeing
Copy link
Member

mofeing commented Feb 7, 2025

great, then do you mind removing the changes to MPS.jl from this PR?

@josepamigoo
Copy link
Collaborator Author

done!

@josepamigoo
Copy link
Collaborator Author

Forgot to make the suggested changes (and the some typo I didn't notice).

Format check still failling though.

src/MPS.jl Outdated
@@ -727,4 +727,4 @@ function LinearAlgebra.normalize!(config::Canonical, ψ::AbstractMPO; bond=nothi
end

return ψ
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
end
end

@mofeing
Copy link
Member

mofeing commented Feb 7, 2025

I think that with my last proposal the format check should pass.

Remind me next week to teach you how to run the formatter.

@mofeing
Copy link
Member

mofeing commented Feb 7, 2025

Also, do you mind adding a lil test on "test/unit/Numerics_test.jl"? If you feel lost, we can do it on Monday.

src/Numerics.jl Outdated
@@ -201,6 +201,12 @@ function LinearAlgebra.svd(tensor::Tensor; left_inds=(), right_inds=(), virtuali
s = Tensor(s, [virtualind])
Vt = Tensor(reshape(conj(V), right_sizes..., size(V, 2)), [right_inds..., virtualind])

if isnothing(maxdim)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if isnothing(maxdim)
if !isnothing(maxdim)

right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

ups, that was my fault 😅

@josepamigoo
Copy link
Collaborator Author

Also, do you mind adding a lil test on "test/unit/Numerics_test.jl"? If you feel lost, we can do it on Monday.

I will take a look at it, but it will be helpful to talk about it on Monday yes.

@josepamigoo
Copy link
Collaborator Author

I uploaded a small test, tell me if you had something similar in mind

Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

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

this is great! just what i had in my mind

only one change request (if you are already in the "svd" testset, you don't need to name it again in "svd truncated"; you can just name it "truncated")

@test isapprox(contract(contract(U, s; dims=Symbol[]), V), tensor)
end

@testset "svd truncated" begin
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@testset "svd truncated" begin
@testset "truncated" begin

@mofeing
Copy link
Member

mofeing commented Feb 7, 2025

ah wait, the CI tests say that there is an error in your implementation

svd truncated: Error During Test at /home/runner/work/Tenet.jl/Tenet.jl/test/unit/Numerics_test.jl:184
  Got exception outside of a @test
  UndefVarError: `u` not defined
  Stacktrace:
    [1] svd(tensor::Tensor{ComplexF64, 4, Array{ComplexF64, 4}}; left_inds::Vector{Symbol}, right_inds::Vector{Symbol}, virtualind::Symbol, maxdim::Int64, kwargs::@Kwargs{})
      @ Tenet ~/work/Tenet.jl/Tenet.jl/src/Numerics.jl:205

@mofeing mofeing merged commit 4dd87e3 into master Feb 7, 2025
5 of 7 checks passed
@mofeing mofeing deleted the feature/compression branch February 7, 2025 16:58
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.

Truncate SVD for Tensor not defined
3 participants