• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RimuQMC / Rimu.jl / 12502640809

26 Dec 2024 10:13AM UTC coverage: 94.948% (+0.4%) from 94.566%
12502640809

push

github

web-flow
Consistently apply snake_case (#301)

# Apply snake_case to keyword arguments

## Breaking changes
- IDs for replicas and spectral states are swapped: replica ids defining
the row in the matrix of `state_vectors` now are appended first and
spectral ids second. If there is only a single replica, or a single
spectral state, the respective ids are ommitted.

## Deprecations 
- in keyword arguments to `ProjectorMonteCarloProblem`
  - `maxlength` deprecated, replaced by `max_length`
  - `walltime` deprecated, replaced by `walltime`
- `lomc!` now prints a deprecation warning

## Internal changes
- fix random seeding of tests
- minor docstring changes
- remove `lomc!` from most tests

69 of 69 new or added lines in 6 files covered. (100.0%)

3 existing lines in 2 files now uncovered.

6728 of 7086 relevant lines covered (94.95%)

17171334.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.48
/src/ExactDiagonalization/algorithms.jl
1
abstract type AbstractAlgorithm{MatrixFree} end
2
ismatrixfree(::AbstractAlgorithm{MatrixFree}) where {MatrixFree} = MatrixFree
10✔
3

4
"""
5
    KrylovKitSolver(matrix_free::Bool; kwargs...)
6
    KrylovKitSolver(; matrix_free = false, kwargs...)
7

8
Algorithm for solving a large [`ExactDiagonalizationProblem`](@ref) to find a few
9
eigenvalues and vectors using the KrylovKit.jl package.
10
The Lanczos method is used for hermitian matrices, and the Arnoldi method is used for
11
non-hermitian matrices.
12

13
# Arguments
14
- `matrix_free = false`: Whether to use a matrix-free algorithm. If `false`, a sparse matrix
15
    will be instantiated. This is typically faster and recommended for small matrices,
16
    but requires more memory. If `true`, the matrix is not instantiated, which is useful for
17
    large matrices that would not fit into memory. The calculation will parallelise using
18
    threading and MPI if available by making use of [`PDVec`](@ref).
19
- `kwargs`: Additional keyword arguments are passed on to the function
20
    [`KrylovKit.eigsolve()`](https://jutho.github.io/KrylovKit.jl/stable/man/eig/#KrylovKit.eigsolve).
21

22
See also [`ExactDiagonalizationProblem`](@ref),
23
[`solve`](@ref solve(::ExactDiagonalizationProblem)).
24

25
!!! note
26
    Requires the KrylovKit.jl package to be loaded with `using KrylovKit`.
27
"""
28
struct KrylovKitSolver{MatrixFree} <: AbstractAlgorithm{MatrixFree}
29
    kw_nt::NamedTuple
30
    # the inner constructor checks if KrylovKit is loaded
31
    function KrylovKitSolver{MF}(; kwargs...) where MF
48✔
32
        ext = Base.get_extension(@__MODULE__, :KrylovKitExt)
24✔
33
        if ext === nothing
24✔
UNCOV
34
            error("KrylovKitSolver requires that KrylovKit is loaded, i.e. `using KrylovKit`")
×
35
        else
36
            kw_nt = NamedTuple(kwargs)
24✔
37
            return new{MF}(kw_nt)
24✔
38
        end
39
    end
40
end
41
KrylovKitSolver(matrix_free::Bool; kwargs...) = KrylovKitSolver{matrix_free}(; kwargs...)
48✔
42
KrylovKitSolver(; matrix_free=true, kwargs...) = KrylovKitSolver(matrix_free; kwargs...)
28✔
43

44
function Base.show(io::IO, s::KrylovKitSolver)
10✔
45
    nt = (; matrix_free=ismatrixfree(s), s.kw_nt...)
14✔
46
    io = IOContext(io, :compact => true)
10✔
47
    print(io, "KrylovKitSolver")
10✔
48
    show(io, nt)
10✔
49
end
50

51

52
"""
53
    ArpackSolver(; kwargs...)
54

55
Algorithm for solving an [`ExactDiagonalizationProblem`](@ref) after instantiating a sparse
56
matrix. It uses the Lanzcos method for hermitian problems, and the Arnoldi method for
57
non-hermitian problems, using the Arpack Fortran library. This is faster than
58
[`KrylovKitSolver(; matrix_free=true)`](@ref), but it requires more memory and will only be
59
useful if the matrix fits into memory.
60

61
The `kwargs` are passed on to the function
62
[`Arpack.eigs()`](https://arpack.julialinearalgebra.org/stable/eigs/).
63

64
See also [`ExactDiagonalizationProblem`](@ref),
65
[`solve`](@ref solve(::ExactDiagonalizationProblem)).
66
!!! note
67
    Requires the Arpack.jl package to be loaded with `using Arpack`.
68
"""
69
struct ArpackSolver <: AbstractAlgorithm{false}
70
    kw_nt::NamedTuple
71
    # the inner constructor checks if Arpack is loaded
72
    function ArpackSolver(; kwargs...)
24✔
73
        ext = Base.get_extension(@__MODULE__, :ArpackExt)
12✔
74
        if ext === nothing
12✔
75
            error("ArpackSolver() requires that Arpack.jl is loaded, i.e. `using Arpack`")
2✔
76
        else
77
            kw_nt = NamedTuple(kwargs)
10✔
78
            return new(kw_nt)
10✔
79
        end
80
    end
81
end
82
function Base.show(io::IO, s::ArpackSolver)
2✔
83
    io = IOContext(io, :compact => true)
2✔
84
    if isempty(s.kw_nt)
4✔
85
        print(io, "ArpackSolver()")
×
86
    else
87
        print(io, "ArpackSolver")
2✔
88
        show(io, s.kw_nt)
2✔
89
    end
90
end
91

92
"""
93
    LOBPCGSolver(; kwargs...)
94

95
The Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG).
96
Algorithm for solving an [`ExactDiagonalizationProblem`](@ref) after instantiating a
97
sparse matrix.
98

99
LOBPCG is not suitable for non-hermitian eigenvalue problems.
100

101
The `kwargs` are passed on to the function
102
[`IterativeSolvers.lobpcg()`](https://iterativesolvers.julialinearalgebra.org/dev/eigenproblems/lobpcg/).
103

104
See also [`ExactDiagonalizationProblem`](@ref),
105
[`solve`](@ref solve(::ExactDiagonalizationProblem)).
106
!!! note
107
    Requires the IterativeSolvers.jl package to be loaded with `using IterativeSolvers`.
108
"""
109
struct LOBPCGSolver <: AbstractAlgorithm{false}
110
    kw_nt::NamedTuple
111
    # the inner constructor checks if LinearSolvers is loaded
112
    function LOBPCGSolver(; kwargs...)
12✔
113
        ext = Base.get_extension(@__MODULE__, :IterativeSolversExt)
6✔
114
        if ext === nothing
6✔
115
            error("LOBPCGSolver() requires that IterativeSolvers.jl is loaded, i.e. `using IterativeSolvers`")
2✔
116
        else
117
            kw_nt = NamedTuple(kwargs)
4✔
118
            return new(kw_nt)
4✔
119
        end
120
    end
121
end
122
function Base.show(io::IO, s::LOBPCGSolver)
2✔
123
    io = IOContext(io, :compact => true)
2✔
124
    if isempty(s.kw_nt)
4✔
125
        print(io, "LOBPCGSolver()")
×
126
    else
127
        print(io, "LOBPCGSolver")
2✔
128
        show(io, s.kw_nt)
2✔
129
    end
130
end
131

132

133
"""
134
    LinearAlgebraSolver(; kwargs...)
135

136
Algorithm for solving an [`ExactDiagonalizationProblem`](@ref) using the dense-matrix
137
eigensolver from the `LinearAlgebra` standard library. This is only suitable for small
138
matrices.
139

140
The `kwargs` are passed on to function [`LinearAlgebra.eigen`](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.eigen).
141

142
# Keyword arguments
143
- `permute = true`: Whether to permute the matrix before diagonalization.
144
- `scale = true`: Whether to scale the matrix before diagonalization.
145
- `sortby`: The sorting order for the eigenvalues.
146

147
See also [`ExactDiagonalizationProblem`](@ref),
148
[`solve`](@ref solve(::ExactDiagonalizationProblem)).
149
"""
150
struct LinearAlgebraSolver <: AbstractAlgorithm{false}
151
    kw_nt::NamedTuple
24✔
152
end
153
LinearAlgebraSolver(; kwargs...) = LinearAlgebraSolver(NamedTuple(kwargs))
48✔
154

155
function Base.show(io::IO, s::LinearAlgebraSolver)
6✔
156
    io = IOContext(io, :compact => true)
6✔
157
    if isempty(s.kw_nt)
10✔
158
        print(io, "LinearAlgebraSolver()")
2✔
159
    else
160
        print(io, "LinearAlgebraSolver")
4✔
161
        show(io, s.kw_nt)
4✔
162
    end
163
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc