@@ -161,22 +161,23 @@ is non-zeros, otherwise the overhead of sparse matrices can be higher than the g
161161sparse differentiation!
162162
163163One of the useful companion tools for NonlinearSolve.jl is
164- [ Symbolics.jl] ( https://github.com/JuliaSymbolics/Symbolics.jl ) . This allows for automatic
164+ [ ADTypes.jl] ( https://github.com/SciML/ADTypes.jl ) that specifies the interface for sparsity
165+ detection via [ ` jacobian_sparsity ` ] (@extref ADTypes). This allows for automatic
165166declaration of Jacobian sparsity types. To see this in action, we can give an example ` du `
166167and ` u ` and call ` jacobian_sparsity ` on our function with the example arguments, and it will
167168kick out a sparse matrix with our pattern, that we can turn into our ` jac_prototype ` .
168169
169170!!! tip
170171
171- Alternatively you can use the ` SparseConnectivityTracer.jl ` package to automatically
172- generate a sparse Jacobian .
172+ External packages like ` SparseConnectivityTracer.jl ` and ` Symbolics.jl ` provide the
173+ actual implementation of sparsity detection .
173174
174175``` @example ill_conditioned_nlprob
175- using Symbolics
176+ using SparseConnectivityTracer, ADTypes
176177
177- du0 = copy(u0 )
178- jac_sparsity = Symbolics.jacobian_sparsity(
179- (du, u) -> brusselator_2d_loop(du, u, p), du0, u0 )
178+ f! = (du, u) -> brusselator_2d_loop(du, u, p )
179+ du0 = similar(u0)
180+ jac_sparsity = ADTypes.jacobian_sparsity(f!, du0, u0, TracerSparsityDetector() )
180181```
181182
182183Notice that Julia gives a nice print out of the sparsity pattern. That's neat, and would be
@@ -322,9 +323,6 @@ sparsity detection. Let's compare the two by setting the sparsity detection algo
322323``` @example ill_conditioned_nlprob
323324using DifferentiationInterface, SparseConnectivityTracer
324325
325- prob_brusselator_2d_exact_symbolics = NonlinearProblem(
326- NonlinearFunction(brusselator_2d_loop; sparsity = SymbolicsSparsityDetector()),
327- u0, p; abstol = 1e-10, reltol = 1e-10)
328326prob_brusselator_2d_exact_tracer = NonlinearProblem(
329327 NonlinearFunction(brusselator_2d_loop; sparsity = TracerSparsityDetector()),
330328 u0, p; abstol = 1e-10, reltol = 1e-10)
@@ -333,7 +331,6 @@ prob_brusselator_2d_approx_di = NonlinearProblem(
333331 sparsity = DenseSparsityDetector(AutoForwardDiff(); atol = 1e-4)),
334332 u0, p; abstol = 1e-10, reltol = 1e-10)
335333
336- @btime solve(prob_brusselator_2d_exact_symbolics, NewtonRaphson());
337334@btime solve(prob_brusselator_2d_exact_tracer, NewtonRaphson());
338335@btime solve(prob_brusselator_2d_approx_di, NewtonRaphson());
339336nothing # hide
0 commit comments