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
Copy file name to clipboardExpand all lines: DifferentiationInterface/docs/src/explanation/advanced.md
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,17 +37,18 @@ DifferentiationInterface does this automatically if you pass a backend of type [
37
37
38
38
### `AutoSparse` object
39
39
40
+
`AutoSparse` backends only support [`jacobian`](@ref) and [`hessian`](@ref) (as well as their variants), because other operators do not output matrices.
40
41
An `AutoSparse` backend must be constructed from three ingredients:
41
42
42
-
1. An underlying (dense) backend
43
+
1. An underlying (dense) backend, which can be [`SecondOrder`](@ref) or anything from [ADTypes.jl](https://github.com/SciML/ADTypes.jl)
43
44
2. A sparsity pattern detector like:
44
45
-[`TracerSparsityDetector`](@extref SparseConnectivityTracer.TracerSparsityDetector) from [SparseConnectivityTracer.jl](https://github.com/adrhill/SparseConnectivityTracer.jl)
45
46
-[`SymbolicsSparsityDetector`](@extref Symbolics.SymbolicsSparsityDetector) from [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl)
46
47
-[`DenseSparsityDetector`](@ref) from DifferentiationInterface.jl (beware that this detector only gives a locally valid pattern)
47
-
3. A coloring algorithm:[`GreedyColoringAlgorithm`](@extrefSparseMatrixColorings.GreedyColoringAlgorithm) from [SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl)is the only one we support. As a result, sparse AD is now located in a package extension which depends on SparseMatrixColorings.jl.
48
-
49
-
`AutoSparse` backends only support[`jacobian`](@ref) and [`hessian`](@ref) (as well as their variants), because other operators do not output matrices.
50
-
To obtain sparse Hessians, you need to put the `SecondOrder` backend inside `AutoSparse`, and not the other way around.
48
+
-[`KnownJacobianSparsityDetector`](@extrefADTypes.KnownJacobianSparsityDetector) or [`KnownHessianSparsityDetector`](@extref ADTypes.KnownHessianSparsityDetector) from [ADTypes.jl](https://github.com/SciML/ADTypes.jl)(if you already know the pattern)
49
+
3. A coloring algorithm from [SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl), such as:
-[`ConstantColoringAlgorithm`](@extref SparseMatrixColorings.ConstantColoringAlgorithm) (if you have already computed the optimal coloring and always want to return it)
51
52
52
53
!!! note
53
54
Symbolic backends have built-in sparsity handling, so `AutoSparse(AutoSymbolics())` and `AutoSparse(AutoFastDifferentiation())` do not need additional configuration for pattern detection or coloring.
@@ -59,3 +60,10 @@ But after preparation, the more zeros are present in the matrix, the greater the
59
60
60
61
!!! danger
61
62
The result of preparation for an `AutoSparse` backend cannot be reused if the sparsity pattern changes.
63
+
64
+
### Tuning the coloring algorithm
65
+
66
+
The complexity of sparse Jacobians or Hessians grows with the number of distinct colors in a coloring of the sparsity pattern.
67
+
To reduce this number of colors, [`GreedyColoringAlgorithm`](@ref) has two main settings: the order used for vertices and the decompression method.
68
+
Depending on your use case, you may want to modify either of these options to increase performance.
69
+
See the documentation of [SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl) for details.
Sparse preparation is more costly than dense preparation, but it is even more essential.
118
118
Indeed, once preparation is done, sparse differentiation is much faster than dense differentiation, because it makes fewer calls to the underlying function.
119
-
The speedup becomes very visible in large dimensions.
119
+
120
+
Some result analysis functions from [SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl) can help you figure out what the preparation contains.
121
+
First, it records the sparsity pattern itself (the one returned by the detector).
Copy file name to clipboardExpand all lines: DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/DifferentiationInterfaceSparseMatrixColoringsExt.jl
0 commit comments