-
-
Couldn't load subscription status.
- Fork 235
Fix Radau methods to support KLU with sparse jacobian prototypes #2893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChrisRackauckas-Claude
wants to merge
1
commit into
SciML:master
Choose a base branch
from
ChrisRackauckas-Claude:fix/radau-klu-jacobian-prototype
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name = "OrdinaryDiffEq" | ||
| uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" | ||
| authors = ["Chris Rackauckas <[email protected]>", "Yingbo Ma <[email protected]>"] | ||
| version = "6.102.1" | ||
| authors = ["Chris Rackauckas <[email protected]>", "Yingbo Ma <[email protected]>"] | ||
|
|
||
| [deps] | ||
| ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" | ||
|
|
@@ -69,6 +69,8 @@ SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226" | |
| SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7" | ||
| SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a" | ||
| SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
| SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" | ||
| Sparspak = "e56a9233-b9d6-4f03-8d0f-1825330902ac" | ||
| Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" | ||
| StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718" | ||
| StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
|
|
@@ -173,6 +175,8 @@ SciMLOperators = "1.8" | |
| SciMLStructures = "1.7" | ||
| SimpleNonlinearSolve = "2.7" | ||
| SimpleUnPack = "1.1" | ||
| SparseConnectivityTracer = "1.1.1" | ||
| Sparspak = "0.3.14" | ||
| Static = "1.2" | ||
| StaticArrayInterface = "1.8" | ||
| StaticArrays = "1.9.14" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,9 +98,15 @@ function alg_cache(alg::RadauIIA3, u, rate_prototype, ::Type{uEltypeNoUnits}, | |
| recursivefill!(atmp, false) | ||
| jac_config = build_jac_config(alg, f, uf, du1, uprev, u, tmp, dw12) | ||
|
|
||
| J, W1 = build_J_W(alg, u, uprev, p, t, dt, f, jac_config, uEltypeNoUnits, Val(true)) | ||
| W1 = similar(J, Complex{eltype(W1)}) | ||
| recursivefill!(W1, false) | ||
| J, W1_temp = build_J_W(alg, u, uprev, p, t, dt, f, jac_config, uEltypeNoUnits, Val(true)) | ||
| # For sparse matrices, preserve sparsity pattern for KLU compatibility | ||
| if is_sparse(J) | ||
| W1 = similar(J, Complex{eltype(W1_temp)}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is the same between branches. |
||
| fill!(nonzeros(W1), false) | ||
| else | ||
| W1 = similar(J, Complex{eltype(W1_temp)}) | ||
| recursivefill!(W1, false) | ||
| end | ||
|
|
||
| linprob = LinearProblem(W1, _vec(cubuff); u0 = _vec(dw12)) | ||
| linsolve = init( | ||
|
|
@@ -239,8 +245,14 @@ function alg_cache(alg::RadauIIA5, u, rate_prototype, ::Type{uEltypeNoUnits}, | |
| if J isa AbstractSciMLOperator | ||
| error("Non-concrete Jacobian not yet supported by RadauIIA5.") | ||
| end | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| recursivefill!(W2, false) | ||
| # For sparse matrices, preserve sparsity pattern for KLU compatibility | ||
| if is_sparse(J) | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| fill!(nonzeros(W2), false) | ||
| else | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| recursivefill!(W2, false) | ||
| end | ||
|
|
||
| linprob = LinearProblem(W1, _vec(ubuff); u0 = _vec(dw1)) | ||
| linsolve1 = init( | ||
|
|
@@ -429,10 +441,18 @@ function alg_cache(alg::RadauIIA9, u, rate_prototype, ::Type{uEltypeNoUnits}, | |
| if J isa AbstractSciMLOperator | ||
| error("Non-concrete Jacobian not yet supported by RadauIIA5.") | ||
| end | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| W3 = similar(J, Complex{eltype(W1)}) | ||
| recursivefill!(W2, false) | ||
| recursivefill!(W3, false) | ||
| # For sparse matrices, preserve sparsity pattern for KLU compatibility | ||
| if is_sparse(J) | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| W3 = similar(J, Complex{eltype(W1)}) | ||
| fill!(nonzeros(W2), false) | ||
| fill!(nonzeros(W3), false) | ||
| else | ||
| W2 = similar(J, Complex{eltype(W1)}) | ||
| W3 = similar(J, Complex{eltype(W1)}) | ||
| recursivefill!(W2, false) | ||
| recursivefill!(W3, false) | ||
| end | ||
|
|
||
| linprob = LinearProblem(W1, _vec(ubuff); u0 = _vec(dw1)) | ||
| linsolve1 = init( | ||
|
|
@@ -638,8 +658,15 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits} | |
| error("Non-concrete Jacobian not yet supported by AdaptiveRadau.") | ||
| end | ||
|
|
||
| # For sparse matrices, preserve sparsity pattern for KLU compatibility | ||
| W2 = [similar(J, Complex{eltype(W1)}) for _ in 1:((max_stages - 1) ÷ 2)] | ||
| recursivefill!.(W2, false) | ||
| if is_sparse(J) | ||
| for W in W2 | ||
| fill!(nonzeros(W), false) | ||
| end | ||
| else | ||
| recursivefill!.(W2, false) | ||
| end | ||
|
|
||
| linprob = LinearProblem(W1, _vec(ubuff); u0 = _vec(dw1)) | ||
| linsolve1 = init( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using OrdinaryDiffEq | ||
| using OrdinaryDiffEqFIRK | ||
| using ADTypes | ||
| using SparseConnectivityTracer | ||
| using LinearSolve | ||
| using Sparspak | ||
|
|
||
| function test_sparse(ode_solver) | ||
| function f(du, u, p, t) | ||
| du .= [u[1], u[2]] | ||
| end | ||
|
|
||
| u0 = [1.0, 2.0] | ||
| p = () | ||
| du0 = similar(u0) | ||
| jac_prototype = float.(ADTypes.jacobian_sparsity( | ||
| (du, u) -> f(du, u, p, 0.0), | ||
| du0, | ||
| u0, TracerSparsityDetector())) | ||
|
|
||
| ode_fun = ODEFunction(f, jac_prototype=jac_prototype) | ||
| prob = ODEProblem(ode_fun, u0, (0, 10)) | ||
| sol = solve(prob, ode_solver) | ||
| return sol | ||
| end | ||
|
|
||
| println("Testing AdaptiveRadau with LUFactorization...") | ||
| test_sparse(AdaptiveRadau(;linsolve=LUFactorization())) # Success | ||
| println("Success!") | ||
|
|
||
| println("Testing AdaptiveRadau with SparspakFactorization...") | ||
| test_sparse(AdaptiveRadau(;linsolve=SparspakFactorization())) # Success | ||
| println("Success!") | ||
|
|
||
| println("Testing QNDF with KLUFactorization...") | ||
| test_sparse(QNDF(;linsolve=KLUFactorization())) # Success | ||
| println("Success!") | ||
|
|
||
| println("Testing AdaptiveRadau with KLUFactorization...") | ||
| test_sparse(AdaptiveRadau(;linsolve=KLUFactorization())) # Error | ||
| println("Success!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using OrdinaryDiffEq | ||
| using OrdinaryDiffEqFIRK | ||
| using ADTypes | ||
| using SparseConnectivityTracer | ||
| using LinearSolve | ||
|
|
||
| function test_sparse(ode_solver) | ||
| function f(du, u, p, t) | ||
| du .= [u[1], u[2]] | ||
| end | ||
|
|
||
| u0 = [1.0, 2.0] | ||
| p = () | ||
| du0 = similar(u0) | ||
| jac_prototype = float.(ADTypes.jacobian_sparsity( | ||
| (du, u) -> f(du, u, p, 0.0), | ||
| du0, | ||
| u0, TracerSparsityDetector())) | ||
|
|
||
| ode_fun = ODEFunction(f, jac_prototype=jac_prototype) | ||
| prob = ODEProblem(ode_fun, u0, (0, 10)) | ||
| sol = solve(prob, ode_solver) | ||
| return sol | ||
| end | ||
|
|
||
| println("Testing RadauIIA5 with KLUFactorization...") | ||
| test_sparse(RadauIIA5(;linsolve=KLUFactorization())) | ||
| println("Success!") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be in extras.