You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.
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)
160
164
```
161
165
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:
165
172
166
173
```@example stiff1
167
174
f = ODEFunction(brusselator_2d_loop; jac_prototype = float.(jac_sparsity))
0 commit comments