Skip to content

Commit 81c2141

Browse files
Use LinearSolve's internal methods for preconditioners
1 parent 0846c9e commit 81c2141

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/steadystate.jl

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,20 @@ A solver which solves [`steadystate`](@ref) by finding the zero (or lowest) eige
2323
struct SteadyStateEigenSolver <: SteadyStateSolver end
2424

2525
@doc raw"""
26-
SteadyStateLinearSolver(alg = KrylovJL_GMRES(), Pl = nothing, Pr = nothing)
26+
SteadyStateLinearSolver(
27+
alg = KrylovJL_GMRES(; precs = (A, p) -> (ilu(A, τ = 0.01), I))
28+
)
2729
2830
A solver which solves [`steadystate`](@ref) by finding the inverse of Liouvillian [`SuperOperator`](@ref) using the `alg`orithms given in [`LinearSolve.jl`](https://docs.sciml.ai/LinearSolve/stable/).
2931
3032
# Arguments
3133
- `alg::SciMLLinearSolveAlgorithm=KrylovJL_GMRES()`: algorithms given in [`LinearSolve.jl`](https://docs.sciml.ai/LinearSolve/stable/)
32-
- `Pl::Union{Function,Nothing}=nothing`: left preconditioner, see documentation [Solving for Steady-State Solutions](@ref doc:Solving-for-Steady-State-Solutions) for more details.
33-
- `Pr::Union{Function,Nothing}=nothing`: right preconditioner, see documentation [Solving for Steady-State Solutions](@ref doc:Solving-for-Steady-State-Solutions) for more details.
34+
35+
# Note
36+
Refer to [`LinearSolve.jl`](https://docs.sciml.ai/LinearSolve/stable/) for more details about the available algorithms. For example, the preconditioners can be defined directly in the solver like: `SteadyStateLinearSolver(alg = KrylovJL_GMRES(; precs = (A, p) -> (I, Diagonal(A))))`.
3437
"""
35-
Base.@kwdef struct SteadyStateLinearSolver{
36-
MT<:Union{SciMLLinearSolveAlgorithm,Nothing},
37-
PlT<:Union{Function,Nothing},
38-
PrT<:Union{Function,Nothing},
39-
} <: SteadyStateSolver
40-
alg::MT = KrylovJL_GMRES()
41-
Pl::PlT = nothing
42-
Pr::PrT = nothing
38+
Base.@kwdef struct SteadyStateLinearSolver{MT<:Union{SciMLLinearSolveAlgorithm,Nothing}} <: SteadyStateSolver
39+
alg::MT = KrylovJL_GMRES(; precs = (A, p) -> (ilu(A, τ = 0.01), I))
4340
end
4441

4542
@doc raw"""
@@ -159,14 +156,8 @@ function _steadystate(L::QuantumObject{SuperOperator}, solver::SteadyStateLinear
159156
L_tmp = L_tmp + Tn
160157

161158
(haskey(kwargs, :Pl) || haskey(kwargs, :Pr)) && error("The use of preconditioners must be defined in the solver.")
162-
if !isnothing(solver.Pl)
163-
kwargs = merge((; kwargs...), (Pl = solver.Pl(L_tmp),))
164-
elseif isa(L_tmp, SparseMatrixCSC)
165-
kwargs = merge((; kwargs...), (Pl = ilu(L_tmp, τ = 0.01),))
166-
end
167-
!isnothing(solver.Pr) && (kwargs = merge((; kwargs...), (Pr = solver.Pr(L_tmp),)))
168159

169-
prob = LinearProblem(L_tmp, v0)
160+
prob = LinearProblem{true}(L_tmp, v0)
170161
ρss_vec = solve(prob, solver.alg; kwargs...).u
171162

172163
ρss = reshape(ρss_vec, N, N)
@@ -407,16 +398,10 @@ function _steadystate_fourier(
407398
v0[n_max*N+1] = weight
408399

409400
(haskey(kwargs, :Pl) || haskey(kwargs, :Pr)) && error("The use of preconditioners must be defined in the solver.")
410-
if !isnothing(solver.Pl)
411-
kwargs = merge((; kwargs...), (Pl = solver.Pl(M),))
412-
elseif isa(M, SparseMatrixCSC)
413-
kwargs = merge((; kwargs...), (Pl = ilu(M, τ = 0.01),))
414-
end
415-
!isnothing(solver.Pr) && (kwargs = merge((; kwargs...), (Pr = solver.Pr(M),)))
416401
!haskey(kwargs, :abstol) && (kwargs = merge((; kwargs...), (abstol = tol,)))
417402
!haskey(kwargs, :reltol) && (kwargs = merge((; kwargs...), (reltol = tol,)))
418403

419-
prob = LinearProblem(M, v0)
404+
prob = LinearProblem{true}(M, v0)
420405
ρtot = solve(prob, solver.alg; kwargs...).u
421406

422407
offset1 = n_max * N

0 commit comments

Comments
 (0)