From b7489fcc0bb52d732835a7b5f2f024b2a81a214d Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Wed, 8 Nov 2023 16:11:11 +0530 Subject: [PATCH 1/4] Remove SuiteSparse --- Project.toml | 2 -- src/LinearSolve.jl | 1 - 2 files changed, 3 deletions(-) diff --git a/Project.toml b/Project.toml index 4790227e6..1b5614d67 100644 --- a/Project.toml +++ b/Project.toml @@ -28,7 +28,6 @@ SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Sparspak = "e56a9233-b9d6-4f03-8d0f-1825330902ac" -SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" [weakdeps] @@ -88,7 +87,6 @@ SciMLOperators = "0.3" Setfield = "1" SparseArrays = "1.9" Sparspak = "0.3.6" -SuiteSparse = "1.9" UnPack = "1" julia = "1.9" diff --git a/src/LinearSolve.jl b/src/LinearSolve.jl index 38ff9d366..982211e39 100644 --- a/src/LinearSolve.jl +++ b/src/LinearSolve.jl @@ -18,7 +18,6 @@ PrecompileTools.@recompile_invalidations begin using SciMLOperators: AbstractSciMLOperator, IdentityOperator using Setfield using UnPack - using SuiteSparse using KLU using Sparspak using FastLapackInterface From 0c3a08aae438e2e71238c4ce3d142a79dd64848e Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Wed, 8 Nov 2023 16:17:13 +0530 Subject: [PATCH 2/4] Replace all usages of SuiteSparse with SparseArrays --- src/factorization.jl | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index 1ec3bd861..7a283c465 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -33,7 +33,7 @@ Julia's built in `lu`. Equivalent to calling `lu!(A)` * On dense matrices, this uses the current BLAS implementation of the user's computer, which by default is OpenBLAS but will use MKL if the user does `using MKL` in their system. -* On sparse matrices, this will use UMFPACK from SuiteSparse. Note that this will not +* On sparse matrices, this will use UMFPACK from SparseArrays. Note that this will not cache the symbolic factorization. * On CuMatrix, it will use a CUDA-accelerated LU from CuSolver. * On BandedMatrix and BlockBandedMatrix, it will use a banded LU. @@ -139,7 +139,7 @@ Julia's built in `qr`. Equivalent to calling `qr!(A)`. * On dense matrices, this uses the current BLAS implementation of the user's computer which by default is OpenBLAS but will use MKL if the user does `using MKL` in their system. -* On sparse matrices, this will use SPQR from SuiteSparse +* On sparse matrices, this will use SPQR from SparseArrays * On CuMatrix, it will use a CUDA-accelerated QR from CuSolver. * On BandedMatrix and BlockBandedMatrix, it will use a banded QR. """ @@ -681,7 +681,7 @@ patterns with “more structure”. !!! note - By default, the SuiteSparse.jl are implemented for efficiency by caching the + By default, the SparseArrays.jl are implemented for efficiency by caching the symbolic factorization. I.e., if `set_A` is used, it is expected that the new `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. @@ -692,11 +692,11 @@ Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization end @static if VERSION < v"1.9.0-DEV.1622" - const PREALLOCATED_UMFPACK = SuiteSparse.UMFPACK.UmfpackLU(C_NULL, C_NULL, 0, 0, + const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(C_NULL, C_NULL, 0, 0, [0], Int[], Float64[], 0) - finalizer(SuiteSparse.UMFPACK.umfpack_free_symbolic, PREALLOCATED_UMFPACK) + finalizer(SparseArrays.UMFPACK.umfpack_free_symbolic, PREALLOCATED_UMFPACK) else - const PREALLOCATED_UMFPACK = SuiteSparse.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], + const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1], Int[], Float64[])) end @@ -722,17 +722,17 @@ function init_cacheval(alg::UMFPACKFactorization, A::AbstractSparseArray, b, u, A = convert(AbstractMatrix, A) zerobased = SparseArrays.getcolptr(A)[1] == 0 @static if VERSION < v"1.9.0-DEV.1622" - res = SuiteSparse.UMFPACK.UmfpackLU(C_NULL, C_NULL, size(A, 1), size(A, 2), + res = SparseArrays.UMFPACK.UmfpackLU(C_NULL, C_NULL, size(A, 1), size(A, 2), zerobased ? copy(SparseArrays.getcolptr(A)) : - SuiteSparse.decrement(SparseArrays.getcolptr(A)), + SparseArrays.decrement(SparseArrays.getcolptr(A)), zerobased ? copy(rowvals(A)) : - SuiteSparse.decrement(rowvals(A)), + SparseArrays.decrement(rowvals(A)), copy(nonzeros(A)), 0) - finalizer(SuiteSparse.UMFPACK.umfpack_free_symbolic, res) + finalizer(SparseArrays.UMFPACK.umfpack_free_symbolic, res) return res else - return SuiteSparse.UMFPACK.UmfpackLU(SparseMatrixCSC(size(A)..., getcolptr(A), + return SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))) end end @@ -744,9 +744,9 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs. cacheval = @get_cacheval(cache, :UMFPACKFactorization) if alg.reuse_symbolic # Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738 - if alg.check_pattern && !(SuiteSparse.decrement(SparseArrays.getcolptr(A)) == + if alg.check_pattern && !(SparseArrays.decrement(SparseArrays.getcolptr(A)) == cacheval.colptr && - SuiteSparse.decrement(SparseArrays.getrowval(A)) == + SparseArrays.decrement(SparseArrays.getrowval(A)) == cacheval.rowval) fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))) @@ -773,7 +773,7 @@ A fast sparse LU-factorization which specializes on sparsity patterns with “le !!! note - By default, the SuiteSparse.jl are implemented for efficiency by caching the + By default, the SparseArrays.jl are implemented for efficiency by caching the symbolic factorization. I.e., if `set_A` is used, it is expected that the new `A` has the same sparsity pattern as the previous `A`. If this algorithm is to be used in a context where that assumption does not hold, set `reuse_symbolic=false`. @@ -816,9 +816,9 @@ function SciMLBase.solve!(cache::LinearCache, alg::KLUFactorization; kwargs...) if cache.isfresh cacheval = @get_cacheval(cache, :KLUFactorization) if cacheval !== nothing && alg.reuse_symbolic - if alg.check_pattern && !(SuiteSparse.decrement(SparseArrays.getcolptr(A)) == + if alg.check_pattern && !(SparseArrays.decrement(SparseArrays.getcolptr(A)) == cacheval.colptr && - SuiteSparse.decrement(SparseArrays.getrowval(A)) == cacheval.rowval) + SparseArrays.decrement(SparseArrays.getrowval(A)) == cacheval.rowval) fact = KLU.klu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))) else @@ -1378,4 +1378,4 @@ for alg in InteractiveUtils.subtypes(AbstractFactorization) maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) end -end + From 35dcfb0336c29bab94bf7ab5c3fead9421cdbd08 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Wed, 8 Nov 2023 16:18:22 +0530 Subject: [PATCH 3/4] Fix syntax bug in factorization --- src/factorization.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factorization.jl b/src/factorization.jl index 7a283c465..a0c7abf71 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -1378,4 +1378,4 @@ for alg in InteractiveUtils.subtypes(AbstractFactorization) maxiters::Int, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) end - +end From 788ad2fc18ff4a1bd742012da47d3f3bd083cbf1 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Wed, 8 Nov 2023 16:23:31 +0530 Subject: [PATCH 4/4] Replace all SuiteSparse in factorization_sparse --- src/factorization_sparse.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/factorization_sparse.jl b/src/factorization_sparse.jl index b633796dd..357e46446 100644 --- a/src/factorization_sparse.jl +++ b/src/factorization_sparse.jl @@ -2,14 +2,14 @@ # Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242 function _ldiv!(x::Vector, A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY, - SuiteSparse.SPQR.QRSparse, - SuiteSparse.CHOLMOD.Factor}, b::Vector) + SparseArrays.SPQR.QRSparse, + SparseArrays.CHOLMOD.Factor}, b::Vector) x .= A \ b end function _ldiv!(x::AbstractVector, A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY, - SuiteSparse.SPQR.QRSparse, - SuiteSparse.CHOLMOD.Factor}, b::AbstractVector) + SparseArrays.SPQR.QRSparse, + SparseArrays.CHOLMOD.Factor}, b::AbstractVector) x .= A \ b end