Skip to content

Commit 1aea9d6

Browse files
amontoisontmigot
andauthored
[documentation] Give more details on coloring algorithms (#297)
* [documentation] Give more details on coloring algorithms * Apply suggestions from code review Co-authored-by: Tangi Migot <tangi.migot@gmail.com> --------- Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
1 parent c1f5278 commit 1aea9d6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/src/sparse.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ The default detector is `TracerSparsityDetector()` from the package `SparseConne
3838
Prior to version 0.8.0, the default detector was `SymbolicSparsityDetector()` from `Symbolics.jl`.
3939

4040
- A **`coloring_algorithm`** must be of type `SparseMatrixColorings.GreedyColoringAlgorithm`.
41-
The default algorithm is `GreedyColoringAlgorithm{:direct}()` from the package `SparseMatrixColorings.jl`.
41+
The default algorithm is `GreedyColoringAlgorithm{:direct}()` for `SparseADJacobian` and `SparseADHessian`, while it is `GreedyColoringAlgorithm{:substitution}()` for `SparseReverseADHessian`.
42+
These algorithms are available in the package `SparseMatrixColorings.jl`.
43+
44+
The `GreedyColoringAlgorithm{:direct}()` performs column coloring for Jacobians and star coloring for Hessians.
45+
In contrast, `GreedyColoringAlgorithm{:substitution}()` applies acyclic coloring for Hessians.
46+
The `:substitution` coloring mode usually finds fewer colors than the `:direct` mode and thus fewer directional derivatives are needed to recover all non-zeros of the sparse Hessian.
47+
However, it requires storing the compressed sparse Hessian, while `:direct` coloring only stores one column of the compressed Hessian.
48+
49+
The `:direct` coloring mode is numerically more stable and may be preferable for highly ill-conditioned Hessian as it doesn't require solving triangular systems to compute the non-zeros from the compressed Hessian.
4250

4351
If the sparsity pattern of the Jacobian of the constraint or the Hessian of the Lagrangian is available, you can directly provide them.
4452
```@example ex2

src/sparse_hessian.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function SparseReverseADHessian(
131131
ncon,
132132
c!;
133133
x0::AbstractVector = rand(nvar),
134-
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(),
134+
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(),
135135
detector::AbstractSparsityDetector = TracerSparsityDetector(),
136136
kwargs...,
137137
)
@@ -146,7 +146,7 @@ function SparseReverseADHessian(
146146
c!,
147147
H::SparseMatrixCSC{Bool, Int};
148148
x0::AbstractVector{T} = rand(nvar),
149-
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(),
149+
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(),
150150
kwargs...,
151151
) where {T}
152152
problem = ColoringProblem{:symmetric, :column}()

0 commit comments

Comments
 (0)