From f2ab66f0e1acd216e90ba401700e941f50fbd068 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Mon, 17 Nov 2025 17:18:14 +0800 Subject: [PATCH 1/3] use `LinearSolve`'s internal methods for pre-conditioners --- Project.toml | 8 ++++---- docs/src/LS_solvers.md | 4 ++++ src/steadystate.jl | 28 ++++++---------------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Project.toml b/Project.toml index acf02c51..eb22b9b4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "HierarchicalEOM" uuid = "a62dbcb7-80f5-4d31-9a88-8b19fd92b128" -version = "2.9.0" +version = "2.10.0" authors = ["Yi-Te Huang"] [deps] @@ -28,8 +28,8 @@ CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" HierarchicalEOM_CUDAExt = "CUDA" [compat] -CUDA = "5" -DiffEqCallbacks = "2 - 4" +CUDA = "5.0 - 5.8, 5.9.4 - 5" +DiffEqCallbacks = "4.2.1 - 4" FastExpm = "1.1" FillArrays = "1" IncompleteLU = "0.2" @@ -42,7 +42,7 @@ ProgressMeter = "1.11.0" QuantumToolbox = "0.39" Reexport = "1" SciMLBase = "2.105" -SciMLOperators = "1.4" +SciMLOperators = "1.11" SparseArrays = "1" StaticArraysCore = "1" julia = "1.10" diff --git a/docs/src/LS_solvers.md b/docs/src/LS_solvers.md index b03c2c07..f62a532f 100644 --- a/docs/src/LS_solvers.md +++ b/docs/src/LS_solvers.md @@ -13,6 +13,10 @@ using LinearSolve ### A generic GMRES implementation from Krylov (Default algorithm) ```julia +# for steadystate +KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I)) + +# for PowerSpectrum and DensityOfStates KrylovJL_GMRES(rtol=1e-12, atol=1e-14) ``` diff --git a/src/steadystate.jl b/src/steadystate.jl index 3c16c716..2d685d44 100644 --- a/src/steadystate.jl +++ b/src/steadystate.jl @@ -4,19 +4,19 @@ Solve the steady state of the auxiliary density operators based on `LinearSolve. # Parameters - `M::AbstractHEOMLSMatrix` : the matrix given from HEOM model, where the parity should be `EVEN`. -- `alg::SciMLLinearSolveAlgorithm` : The solving algorithm in package `LinearSolve.jl`. Default to `KrylovJL_GMRES(rtol=1e-12, atol=1e-14)`. +- `alg::SciMLLinearSolveAlgorithm` : The solving algorithm in package `LinearSolve.jl`. Default to `KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I))`. - `verbose::Bool` : To display verbose output or not. Defaults to `true`. - `kwargs` : The keyword arguments for the `LinearProblem` # Notes -- For more details about `alg`, `kwargs`, and `LinearProblem`, please refer to [`LinearSolve.jl`](http://linearsolve.sciml.ai/stable/) +- For more details about `alg`, `kwargs`, and `LinearProblem`, please refer to [`LinearSolve.jl`](http://linearsolve.sciml.ai/stable/). For example, the preconditioners can be defined directly in the `alg`orithm like: `KrylovJL_GMRES(; precs = (A, p) -> (I, Diagonal(A))))`. # Returns - `::ADOs` : The steady state of auxiliary density operators. """ function QuantumToolbox.steadystate( M::AbstractHEOMLSMatrix{<:MatrixOperator}; - alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(rtol = 1e-12, atol = 1e-14), + alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I)), verbose::Bool = true, kwargs..., ) @@ -31,29 +31,13 @@ function QuantumToolbox.steadystate( A = _HandleSteadyStateMatrix(M) b = sparsevec([1], [1.0 + 0.0im], size(M, 1)) - if verbose - println("Solving steady state for ADOs by linear-solve method...") - flush(stdout) - end - if (!haskey(kwargs, :Pl)) && (isa(A, SparseMatrixCSC)) - if verbose - print("Calculating left preconditioner with ilu...") - flush(stdout) - end - kwargs = merge((; kwargs...), (Pl = ilu(A, τ = 0.01),)) - if verbose - println("[DONE]") - flush(stdout) - end - end - # solving x where A * x = b if verbose - print("Solving linear problem...") + print("Solving steady state for ADOs by linear-solve method...") flush(stdout) end - cache = init(LinearProblem(A, _HandleVectorType(M, b)), alg, kwargs...) - sol = solve!(cache) + prob = LinearProblem{true}(A, _HandleVectorType(M, b)) + sol = solve(prob, alg; kwargs...) if verbose println("[DONE]") flush(stdout) From 42545bf3c88b06439b88bc7140a53a1b2ad4a70d Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Mon, 17 Nov 2025 17:21:19 +0800 Subject: [PATCH 2/3] format files --- src/steadystate.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/steadystate.jl b/src/steadystate.jl index 2d685d44..c2df3ac0 100644 --- a/src/steadystate.jl +++ b/src/steadystate.jl @@ -16,7 +16,11 @@ Solve the steady state of the auxiliary density operators based on `LinearSolve. """ function QuantumToolbox.steadystate( M::AbstractHEOMLSMatrix{<:MatrixOperator}; - alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I)), + alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(; + rtol = 1e-12, + atol = 1e-14, + precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I), + ), verbose::Bool = true, kwargs..., ) From d125d59056af44bd44c0a2cfac310f255a9027d3 Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Mon, 17 Nov 2025 19:42:21 +0800 Subject: [PATCH 3/3] Remove preconditioner in `steadystate` --- docs/src/LS_solvers.md | 4 ---- src/steadystate.jl | 11 ++++------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/src/LS_solvers.md b/docs/src/LS_solvers.md index f62a532f..b03c2c07 100644 --- a/docs/src/LS_solvers.md +++ b/docs/src/LS_solvers.md @@ -13,10 +13,6 @@ using LinearSolve ### A generic GMRES implementation from Krylov (Default algorithm) ```julia -# for steadystate -KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I)) - -# for PowerSpectrum and DensityOfStates KrylovJL_GMRES(rtol=1e-12, atol=1e-14) ``` diff --git a/src/steadystate.jl b/src/steadystate.jl index c2df3ac0..4408d485 100644 --- a/src/steadystate.jl +++ b/src/steadystate.jl @@ -4,23 +4,19 @@ Solve the steady state of the auxiliary density operators based on `LinearSolve. # Parameters - `M::AbstractHEOMLSMatrix` : the matrix given from HEOM model, where the parity should be `EVEN`. -- `alg::SciMLLinearSolveAlgorithm` : The solving algorithm in package `LinearSolve.jl`. Default to `KrylovJL_GMRES(; rtol = 1e-12, atol = 1e-14, precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I))`. +- `alg::SciMLLinearSolveAlgorithm` : The solving algorithm in package `LinearSolve.jl`. Default to `KrylovJL_GMRES(rtol = 1e-12, atol = 1e-14)`. - `verbose::Bool` : To display verbose output or not. Defaults to `true`. - `kwargs` : The keyword arguments for the `LinearProblem` # Notes -- For more details about `alg`, `kwargs`, and `LinearProblem`, please refer to [`LinearSolve.jl`](http://linearsolve.sciml.ai/stable/). For example, the preconditioners can be defined directly in the `alg`orithm like: `KrylovJL_GMRES(; precs = (A, p) -> (I, Diagonal(A))))`. +- For more details about `alg`, `kwargs`, and `LinearProblem`, please refer to [`LinearSolve.jl`](http://linearsolve.sciml.ai/stable/). # Returns - `::ADOs` : The steady state of auxiliary density operators. """ function QuantumToolbox.steadystate( M::AbstractHEOMLSMatrix{<:MatrixOperator}; - alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(; - rtol = 1e-12, - atol = 1e-14, - precs = (A, p) -> A isa SparseMatrixCSC ? (ilu(A, τ = 0.01), I) : (I, I), - ), + alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES(rtol = 1e-12, atol = 1e-14), verbose::Bool = true, kwargs..., ) @@ -40,6 +36,7 @@ function QuantumToolbox.steadystate( print("Solving steady state for ADOs by linear-solve method...") flush(stdout) end + prob = LinearProblem{true}(A, _HandleVectorType(M, b)) sol = solve(prob, alg; kwargs...) if verbose