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

EigenSolvers as extensions #298

Merged
merged 8 commits into from
Jun 25, 2024
Merged

EigenSolvers as extensions #298

merged 8 commits into from
Jun 25, 2024

Conversation

pablosanjose
Copy link
Owner

@pablosanjose pablosanjose commented Jun 25, 2024

Closes #297

We introduce extensions for LinearMaps, ArnoldiMethod, KrylovKit and Arpack.

This has revealed yet another issue with FunctionWrappers.jl, similar to #235, but not quite the same. When attempting to call spectrum(h; solver = ...) with an unloaded extension for the solver, it would error as expected. Then, after loading the relevant package, calling spectrum again would yield a weird error such as

julia> spectrum(h, (0,), solver = ES.ShiftInvert(ES.ArnoldiMethod(nev = 4), 0))
ERROR: TypeError: in cfunction, expected Union{}, got a value of type LinearAlgebra.Eigen{ComplexF64, ComplexF64, Matrix{ComplexF64}, Vector{ComplexF64}}
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:137 [inlined]
 [2] do_ccall
   @ ~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:125 [inlined]
 [3] FunctionWrapper
   @ ~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:144 [inlined]
 [4] AppliedEigenSolver
   @ ~/.julia/dev/Quantica/src/types.jl:1716 [inlined]
 [5] spectrum(h::Quantica.ParametricHamiltonian{Float64, 1, 1, ComplexF64, Tuple{…}}, φs::Tuple{Int64}; solver::Quantica.EigenSolvers.ShiftInvert{Int64, Quantica.EigenSolvers.ArnoldiMethod{…}}, transform::Missing, kw::@Kwargs{})
   @ Quantica ~/.julia/dev/Quantica/src/bands.jl:11
 [6] top-level scope
   @ REPL[5]:1

This likely stems from FunctionWrappers' issues with the world age system, and is, interestingly, fixed by the same approach as #235. However this impacts also aarch64 (macos) and Julia 1.11, unlike #235, so it seems to be more general.

We have implemented a cheaper fix, trying for the moment to avoid excising FunctionWrappers altogether (which, admittedly, improves compile and runtime performance in Quantica). It consists of always running the wrapped eigensolver with a dryrun=true option to make it almost free, but force it to compile.

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.55%. Comparing base (fc93e65) to head (e1b1ddc).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #298      +/-   ##
==========================================
- Coverage   92.61%   92.55%   -0.07%     
==========================================
  Files          37       37              
  Lines        6299     6270      -29     
==========================================
- Hits         5834     5803      -31     
- Misses        465      467       +2     

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

@pablosanjose
Copy link
Owner Author

The test failures on nightly are unrelated, and caused by CairoMakie, so they are not blocking.

@pablosanjose pablosanjose merged commit b12ba01 into master Jun 25, 2024
6 of 9 checks passed
@pablosanjose pablosanjose deleted the extensions branch June 28, 2024 14:11
@pablosanjose pablosanjose mentioned this pull request Feb 6, 2025
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.

Migrate eigensolver packages to extensions
2 participants