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

Implement KrylovKit.eigsolve for Tensors #157

Merged
merged 12 commits into from
Jul 8, 2024
Merged

Implement KrylovKit.eigsolve for Tensors #157

merged 12 commits into from
Jul 8, 2024

Conversation

jofrevalles
Copy link
Member

Summary

This PR extends the KrylovKit.eigsolve function for Tensors. We added some tests to cover this function too.

Example

julia> using Tenet; using LinearAlgebra; using Test

julia> using KrylovKit
┌ Warning: The project dependencies or compat requirements have changed since the manifest was last resolved.
│ It is recommended to `Pkg.resolve()` or consider `Pkg.update()` if necessary.
└ @ Pkg.API ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/Pkg/src/API.jl:1807
[ Info: Precompiling TenetKrylovKitExt [29b5df5b-24ac-5557-97d4-3d2f1208de95]

julia> A = rand(ComplexF64, 4, 4)
4×4 Matrix{ComplexF64}: ...

julia> data = (A + A') / 2 # Make it Hermitian

julia> tensor = Tensor(data, (:i, :j))
4×4 Tensor{ComplexF64, 2, Matrix{ComplexF64}}: ...

julia> vals, vecs = eigsolve(tensor; left_inds=[:i], right_inds=[:j]) # Perform eigensolve
([2.3507038036026553, -0.7165812403097447, 0.3433988271360078, 0.18227647730800145], Tensor{ComplexF64, 1, Vector{ComplexF64}}[[0.4141738753940685 + 0.3073367327846263im, 0.41661203124364915 + 0.1853467004548118im, 0.29906239280853125 + 0.35035248351300025im, 0.38944025132705234 + 0.40278562887237646im], [0.26352280677272105 + 0.5511773506958907im, -0.14761808542348484 - 0.708632804563461im, -0.24984012828454633 - 0.13660399464451234im, -0.04906317004703921 + 0.13899558206566603im], [-0.011943074391772727 + 0.2694131820645913im, -0.3347917377550906 + 0.3074609885080383im, 0.3989980157520261 - 0.7061959066874091im, 0.10617448539651439 + 0.22687229146630172im], [-0.0816029957725681 + 0.5304509811449717im, -0.16119745313827308 + 0.1884862838094723im, 0.07319838199527906 + 0.20848022238811795im, 0.26215618954309244 - 0.7300021476894631im]])

julia> V_matrix = hcat([reshape(parent(vec), :) for vec in vecs]...) # Convert vecs to matrix form for reconstruction
4×4 Matrix{ComplexF64}: ...

julia> D_matrix = Diagonal(vals)
4×4 Diagonal{Float64, Vector{Float64}}:
 2.3507                       
        -0.716581             
                  0.343399    
                           0.182276

julia> reconstructed_matrix = V_matrix * D_matrix * inv(V_matrix)
4×4 Matrix{ComplexF64}: ...

julia> @test isapprox(reconstructed_matrix, parent(tensor))
Test Passed

@jofrevalles
Copy link
Member Author

@mofeing can we merge this?

@jofrevalles jofrevalles requested a review from mofeing July 4, 2024 10:58
ext/TenetKrylovKitExt.jl Outdated Show resolved Hide resolved
ext/TenetKrylovKitExt.jl Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 55.16%. Comparing base (5ee9b93) to head (34281ef).
Report is 30 commits behind head on master.

Files Patch % Lines
ext/TenetKrylovKitExt.jl 0.00% 17 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (5ee9b93) and HEAD (34281ef). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (5ee9b93) HEAD (34281ef)
4 2
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #157       +/-   ##
===========================================
- Coverage   68.76%   55.16%   -13.60%     
===========================================
  Files          19       20        +1     
  Lines        1050     1084       +34     
===========================================
- Hits          722      598      -124     
- Misses        328      486      +158     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mofeing mofeing merged commit 320cb02 into master Jul 8, 2024
6 checks passed
@mofeing mofeing deleted the feature/eigsolve branch July 8, 2024 08:48
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.

2 participants