Skip to content

Commit

Permalink
modify extension algs
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Jul 1, 2024
1 parent be1244e commit a07a096
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ JET = "0.8.28"
KLU = "0.6"
KernelAbstractions = "0.9.16"
Krylov = "0.9"
KrylovPreconditioners = "0.2"
KrylovKit = "0.8"
LazyArrays = "1.8, 2"
Libdl = "1.10"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/advanced/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The inputs to the function are as follows:
- `p`, a set of parameters
- `newA`, a `Bool` which is `true` if `A` has been modified since last solve
- `Pl`, left-preconditioner
- `Pr`, right-preconditioner
- `Pr`, right-preconditionerz
- `solverdata`, solver cache set to `nothing` if solver hasn't been initialized
- `kwargs`, standard SciML keyword arguments such as `verbose`, `maxiters`, `abstol`, `reltol`

Expand Down
11 changes: 5 additions & 6 deletions docs/src/basics/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ a few ways:

## How do I use IterativeSolvers solvers with a weighted tolerance vector?

IterativeSolvers.jl computes the norm after the application of the left preconditioner
`Pl`. Thus, in order to use a vector tolerance `weights`, one can mathematically
IterativeSolvers.jl computes the norm after the application of the left preconditioner.
Thus, in order to use a vector tolerance `weights`, one can mathematically
hack the system via the following formulation:

```@example FAQPrec
Expand All @@ -57,11 +57,10 @@ A = rand(n, n)
b = rand(n)
weights = [1e-1, 1]
Pl = LinearSolve.InvPreconditioner(Diagonal(weights))
Pr = Diagonal(weights)
precs = Returns(LinearSolve.InvPreconditioner(Diagonal(weights)), Diagonal(weights))
prob = LinearProblem(A, b)
sol = solve(prob, KrylovJL_GMRES(), Pl = Pl, Pr = Pr)
sol = solve(prob, KrylovJL_GMRES(precs))
sol.u
```
Expand All @@ -84,5 +83,5 @@ Pl = LinearSolve.ComposePreconditioner(LinearSolve.InvPreconditioner(Diagonal(we
Pr = Diagonal(weights)
prob = LinearProblem(A, b)
sol = solve(prob, KrylovJL_GMRES(), Pl = Pl, Pr = Pr)
sol = solve(prob, KrylovJL_GMRES(precs=Returns((Pl,Pr))))
```
4 changes: 2 additions & 2 deletions ext/LinearSolveIterativeSolversExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ end

function LinearSolve.IterativeSolversJL(args...;
generate_iterator = IterativeSolvers.gmres_iterable!,
gmres_restart = 0, kwargs...)
gmres_restart = 0, precs = DEFAULT_PRECS, kwargs...)
return IterativeSolversJL(generate_iterator, gmres_restart,
args, kwargs)
precs, args, kwargs)
end

function LinearSolve.IterativeSolversJL_CG(args...; kwargs...)
Expand Down
5 changes: 3 additions & 2 deletions ext/LinearSolveKrylovKitExt.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module LinearSolveKrylovKitExt

using LinearSolve, KrylovKit, LinearAlgebra
using LinearSolve: LinearCache
using LinearSolve: LinearCache, DEFAULT_PRECS

function LinearSolve.KrylovKitJL(args...;
KrylovAlg = KrylovKit.GMRES, gmres_restart = 0,
precs = DEFAULT_PRECS,
kwargs...)
return KrylovKitJL(KrylovAlg, gmres_restart, args, kwargs)
return KrylovKitJL(KrylovAlg, gmres_restart, precs, args, kwargs)
end

function LinearSolve.KrylovKitJL_CG(args...; kwargs...)
Expand Down
6 changes: 4 additions & 2 deletions src/extension_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ solvers.
Using this solver requires adding the package KrylovKit.jl, i.e. `using KrylovKit`
"""
struct KrylovKitJL{F, A, I, K} <: LinearSolve.AbstractKrylovSubspaceMethod
struct KrylovKitJL{F, I, P, A, K} <: LinearSolve.AbstractKrylovSubspaceMethod
KrylovAlg::F
gmres_restart::I
precs::P
args::A
kwargs::K
end
Expand Down Expand Up @@ -306,9 +307,10 @@ A generic wrapper over the IterativeSolvers.jl solvers.
Using this solver requires adding the package IterativeSolvers.jl, i.e. `using IterativeSolvers`
"""
struct IterativeSolversJL{F, I, A, K} <: LinearSolve.AbstractKrylovSubspaceMethod
struct IterativeSolversJL{F, I, P, A, K} <: LinearSolve.AbstractKrylovSubspaceMethod
generate_iterator::F
gmres_restart::I
precs::P
args::A
kwargs::K
end
Expand Down
2 changes: 1 addition & 1 deletion src/iterative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ KrylovJL(args...; KrylovAlg = Krylov.gmres!,
A generic wrapper over the Krylov.jl krylov-subspace iterative solvers.
"""
struct KrylovJL{F, I, A, P, K} <: AbstractKrylovSubspaceMethod
struct KrylovJL{F, I, P, A, K} <: AbstractKrylovSubspaceMethod
KrylovAlg::F
gmres_restart::I
window::I
Expand Down
2 changes: 1 addition & 1 deletion test/static_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for alg in (nothing, LUFactorization(), SVDFactorization(), CholeskyFactorizatio
@test norm(A * sol .- b) < 1e-10

if __non_native_static_array_alg(alg)
@test_broken __solve_no_alloc(A, b, alg)
@test_nowarn __solve_no_alloc(A, b, alg)
else
@test_nowarn __solve_no_alloc(A, b, alg)
end
Expand Down

0 comments on commit a07a096

Please sign in to comment.