Skip to content

Commit f58c26c

Browse files
committed
Update sparsity detection docs
1 parent bbf480f commit f58c26c

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

docs/Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
23
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
34
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
45
BVProblemLibrary = "ded0fc24-dfea-4565-b1d9-79c027d14d84"
@@ -31,12 +32,13 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
3132
SDEProblemLibrary = "c72e72a9-a271-4b2b-8966-303ed956772e"
3233
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
3334
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
35+
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
3436
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
3537
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
36-
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
3738
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
3839

3940
[compat]
41+
ADTypes = "1.7"
4042
AlgebraicMultigrid = "0.5, 0.6"
4143
BSON = "0.3"
4244
BVProblemLibrary = "0.1.2"
@@ -68,7 +70,7 @@ RecursiveArrayTools = "2, 3"
6870
SDEProblemLibrary = "0.1"
6971
SciMLBase = "2"
7072
SciMLOperators = "0.3"
73+
SparseConnectivityTracer = "0.6"
7174
StaticArrays = "1"
7275
Sundials = "4.11.3"
73-
Symbolics = "4, 5, 6"
7476
Unitful = "1"

docs/src/tutorials/advanced_ode_example.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,30 @@ Note that you should only do this if the sparsity is high, for example, 0.1%
145145
of the matrix is non-zeros, otherwise the overhead of sparse matrices can be higher
146146
than the gains from sparse differentiation!
147147

148-
One of the useful companion tools for DifferentialEquations.jl is
149-
[Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl).
150-
This allows for automatic declaration of Jacobian sparsity types. To see this
151-
in action, we can give an example `du` and `u` and call `jacobian_sparsity`
152-
on our function with the example arguments, and it will kick out a sparse matrix
153-
with our pattern, that we can turn into our `jac_prototype`.
148+
[ADTypes.jl](https://github.com/SciML/ADTypes.jl) provides a [common interface for automatic sparsity detection](https://sciml.github.io/ADTypes.jl/stable/#Sparsity-detector)
149+
via its function `jacobian_sparsity`.
150+
This function can be called using sparsity detectors from [SparseConnectivityTracer.jl](https://github.com/adrhill/SparseConnectivityTracer.jl)
151+
or [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl).
152+
153+
We can give an example `du` and `u` and call `jacobian_sparsity` on our function with the example arguments,
154+
and it will kick out a sparse matrix with our pattern, that we can turn into our `jac_prototype`.
155+
156+
Let's try SparseConnectivityTracer's [`TracerSparsityDetector`](https://adrianhill.de/SparseConnectivityTracer.jl/stable/user/api/#SparseConnectivityTracer.TracerSparsityDetector):
154157

155158
```@example stiff1
156-
using Symbolics
159+
using SparseConnectivityTracer, ADTypes
160+
detector = TracerSparsityDetector()
157161
du0 = copy(u0)
158-
jac_sparsity = Symbolics.jacobian_sparsity((du, u) -> brusselator_2d_loop(du, u, p, 0.0),
159-
du0, u0)
162+
jac_sparsity = ADTypes.jacobian_sparsity(
163+
(du, u) -> brusselator_2d_loop(du, u, p, 0.0), du0, u0, detector)
160164
```
161165

162-
Notice that Julia gives a nice print out of the sparsity pattern. That's neat, and
163-
would be tedious to build by hand! Now we just pass it to the `ODEFunction`
164-
like as before:
166+
Using a different backend for sparsity detection just requires swapping out the detector,
167+
e.g. for Symbolics' [`SymbolicsSparsityDetector`](https://docs.sciml.ai/Symbolics/stable/manual/sparsity_detection/#Symbolics.SymbolicsSparsityDetector).
168+
169+
Notice that Julia gives a nice print out of the sparsity pattern.
170+
That's neat, and would be tedious to build by hand!
171+
Now we just pass it to the `ODEFunction` like as before:
165172

166173
```@example stiff1
167174
f = ODEFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))

0 commit comments

Comments
 (0)