qojulia / QuantumOptics.jl

Library for the numerical simulation of closed as well as open quantum systems.
http://qojulia.org
Other
518 stars 101 forks source link

KrylovKit spectrum solver #367

Closed aryavorskiy closed 11 months ago

aryavorskiy commented 1 year ago

364

The Arnoldi algorithm implementation from the KrylovKit.jl package seems to be much more performant than the ARPACK one. Also a DiagStrategy trait was implemented to make selecting the correct method on the fly (or defining a new one) more flexible

codecov[bot] commented 1 year ago

Codecov Report

Merging #367 (b9dca8c) into master (eff22f1) will decrease coverage by 0.30%. The diff coverage is 88.37%.

@@            Coverage Diff             @@
##           master     #367      +/-   ##
==========================================
- Coverage   98.11%   97.82%   -0.30%     
==========================================
  Files          18       18              
  Lines        1488     1516      +28     
==========================================
+ Hits         1460     1483      +23     
- Misses         28       33       +5     
Impacted Files Coverage Δ
src/spectralanalysis.jl 93.42% <88.37%> (-6.58%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

aryavorskiy commented 12 months ago

@Krastanov thanks for the review! I will implement these requests by Tuesday, 11th, I think. I also have some new ideas:

julia> A = sprand(1000, 1000, 0.001); v0 = rand(1000);

julia> @benchmark eigs(A, v0=v0, nev=5, which=:SR) # Arpack BenchmarkTools.Trial: 589 samples with 1 evaluation. Range (min … max): 7.974 ms … 12.672 ms ┊ GC (min … max): 0.00% … 33.56% Time (median): 8.431 ms ┊ GC (median): 0.00% Time (mean ± σ): 8.492 ms ± 514.293 μs ┊ GC (mean ± σ): 0.64% ± 3.72%

 ▄▆▆█▅▃

▃▄▇██████▆▄▄▃▃▂▁▂▂▂▁▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▂▁▁▂ ▃ 7.97 ms Histogram: frequency by time 12.3 ms <

Memory estimate: 702.83 KiB, allocs estimate: 949.

julia> @benchmark eigsolve(A, v0, 5, :SR) # KrylovKit BenchmarkTools.Trial: 2167 samples with 1 evaluation. Range (min … max): 1.931 ms … 6.259 ms ┊ GC (min … max): 0.00% … 50.37% Time (median): 2.162 ms ┊ GC (median): 0.00% Time (mean ± σ): 2.302 ms ± 457.034 μs ┊ GC (mean ± σ): 2.63% ± 8.01%

▄█

▃▇███▇▇▆▆▅▄▄▃▃▄▄▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▁▁▁▂▁▁▂▁▂▂▂▂▂▂▂▂▂▂▁▂▂▂▂ ▃ 1.93 ms Histogram: frequency by time 4.52 ms <


- Maybe create an `EigenSystem` struct that will store computed eigenvalues and eigevectors? In this format they can be easily dumped to a file or used to construct a density matrix or Green's function.
- Maybe move this functionality to QuantumOpticsBase? Other quantum physics packages depending on it might want to use this as well. I am myself now in progress of creating such one :-) Or is this a generally bad idea?
Krastanov commented 12 months ago
aryavorskiy commented 11 months ago

Done. One final idea: I don't like how two separate keywords are used for nonhermitian warning and info message about the diagonalization method. My proposal is using a verbose keyword for both. This change is breaking, but only a little, so I don't know if it is a good idea. @Krastanov about my package: it is called LatticeModels.jl, it is designed to perform various computations on tight-binding lattices. I decided to use the bases & operators infrastructure from QuantumOpticsBase when I discovered that it is a separate package, and am currently working on its integration. My package is still far from finished, I will definitely rename it sometime, the docs are a little outdated, but most important functionality is already implemented.

Krastanov commented 11 months ago

@aryavorskiy , there was a minor merge conflict that I resolved, but that ended up pushing to your master branch. Be sure to do a pull before you perform other edits. Also, it is a good idea to do your development not to the master branch of your repo, but rather on a separate development branch -- it makes other modifications down the line easier.

I will go through the current changes and review. Thanks for improving this part of the library!

Krastanov commented 11 months ago

I made two small changes to your PR:

I will wait on the tests, give it a final read through, and I should be able to merge it and release it today.

Krastanov commented 11 months ago

My bad, it seems info was something already done to this library so you were just following the established convention. Give me a minute to fix this.

Krastanov commented 11 months ago

It seems the info string was meant to specifically warn about defaulting to the sparse eigsolver when the dense one might be better. I moved it to that location and cleaned it up a bit.