From 0f63778449e33e79b4a827e3feb095866ff4e452 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Sun, 7 Jan 2024 15:47:16 -0500 Subject: [PATCH 1/3] Fix UMFPACK to use check=false --- src/factorization.jl | 17 +++++++++++------ test/default_algs.jl | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index 0ef7b754e..efcaaaf00 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -780,21 +780,26 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs. SparseArrays.decrement(SparseArrays.getrowval(A)) == cacheval.rowval) fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), - nonzeros(A))) + nonzeros(A)), check=false) else fact = lu!(cacheval, SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), - nonzeros(A))) + nonzeros(A)), check=false) end else - fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A))) + fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), check=false) end cache.cacheval = fact cache.isfresh = false end - y = ldiv!(cache.u, @get_cacheval(cache, :UMFPACKFactorization), cache.b) - SciMLBase.build_linear_solution(alg, y, nothing, cache) + F = @get_cacheval(cache, :UMFPACKFactorization) + if F.status == SparseArrays.UMFPACK.UMFPACK_OK + y = ldiv!(cache.u, F, cache.b) + SciMLBase.build_linear_solution(alg, y, nothing, cache) + else + SciMLBase.build_linear_solution(alg, cache.u, nothing, cache; retcode=ReturnCode.Infeasible) + end end """ @@ -840,10 +845,10 @@ function init_cacheval(alg::KLUFactorization, A::AbstractSparseArray, b, u, Pl, nonzeros(A))) end +# TODO: guard this against errors function SciMLBase.solve!(cache::LinearCache, alg::KLUFactorization; kwargs...) A = cache.A A = convert(AbstractMatrix, A) - if cache.isfresh cacheval = @get_cacheval(cache, :KLUFactorization) if cacheval !== nothing && alg.reuse_symbolic diff --git a/test/default_algs.jl b/test/default_algs.jl index d2aafba9d..20fba16b9 100644 --- a/test/default_algs.jl +++ b/test/default_algs.jl @@ -35,6 +35,13 @@ solve(prob) LinearSolve.OperatorAssumptions(false)).alg === LinearSolve.DefaultAlgorithmChoice.QRFactorization + +A = spzeros(100, 100) +A[1,1]=1 +# test that solving a singluar problem doesn't error +prob = LinearProblem(A, ones(100)) +solve(prob) + @test LinearSolve.defaultalg(sprand(10^4, 10^4, 1e-5) + I, zeros(1000)).alg === LinearSolve.DefaultAlgorithmChoice.KLUFactorization prob = LinearProblem(sprand(1000, 1000, 0.5), zeros(1000)) From 7452db86d707d9a7dc6fdd10f89d6e1ba2281fbf Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 23 Feb 2024 16:41:28 -0500 Subject: [PATCH 2/3] typo --- test/default_algs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/default_algs.jl b/test/default_algs.jl index 20fba16b9..da998fad1 100644 --- a/test/default_algs.jl +++ b/test/default_algs.jl @@ -38,7 +38,7 @@ solve(prob) A = spzeros(100, 100) A[1,1]=1 -# test that solving a singluar problem doesn't error +# test that solving a singular problem doesn't error prob = LinearProblem(A, ones(100)) solve(prob) From 86e7191bc84891936a0d84b5983c4e0aef1cc94d Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 23 Feb 2024 17:07:07 -0500 Subject: [PATCH 3/3] update tests --- test/default_algs.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/default_algs.jl b/test/default_algs.jl index da998fad1..c604129c9 100644 --- a/test/default_algs.jl +++ b/test/default_algs.jl @@ -36,11 +36,12 @@ solve(prob) LinearSolve.DefaultAlgorithmChoice.QRFactorization -A = spzeros(100, 100) -A[1,1]=1 +A = spzeros(2, 2) # test that solving a singular problem doesn't error -prob = LinearProblem(A, ones(100)) -solve(prob) +prob = LinearProblem(A, ones(2)) +@test solve(prob, UMFPACKFactorization()).retcode == ReturnCode.Infeasible +@test_broken solve(prob, KLUFactorization()).retcode == ReturnCode.Infeasible + @test LinearSolve.defaultalg(sprand(10^4, 10^4, 1e-5) + I, zeros(1000)).alg === LinearSolve.DefaultAlgorithmChoice.KLUFactorization