Skip to content

Commit

Permalink
[documentation] Give more details on coloring algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Aug 17, 2024
1 parent c1f5278 commit 8d33aeb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion docs/src/sparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ The default detector is `TracerSparsityDetector()` from the package `SparseConne
Prior to version 0.8.0, the default detector was `SymbolicSparsityDetector()` from `Symbolics.jl`.

- A **`coloring_algorithm`** must be of type `SparseMatrixColorings.GreedyColoringAlgorithm`.
The default algorithm is `GreedyColoringAlgorithm{:direct}()` from the package `SparseMatrixColorings.jl`.
The default algorithm is `GreedyColoringAlgorithm{:direct}()` for `SparseADJacobian` and `SparseADHessian`, while it is `GreedyColoringAlgorithm{:substitution}()` for `SparseReverseADHessian`.
These algorithms are available in the package `SparseMatrixColorings.jl`.

The `GreedyColoringAlgorithm{:direct}()` performs column coloring for Jacobians and star coloring for Hessians.
In contrast, `GreedyColoringAlgorithm{:substitution}()` applies acyclic coloring for Hessians.
Substitution coloring results in fewer colors and thus requires fewer directional derivatives to recover all non-zeros of the sparse Hessian.
However, it necessitates storing the entire compressed sparse Hessian.
On the other hand, direct coloring only requires storing one column of the compressed Hessian at a time.

If the Hessian is highly ill-conditioned, direct coloring can be preferable because it avoids the need for triangular solves to recover the non-zeros from the compressed Hessian.

If the sparsity pattern of the Jacobian of the constraint or the Hessian of the Lagrangian is available, you can directly provide them.
```@example ex2
Expand Down
4 changes: 2 additions & 2 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function SparseReverseADHessian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
)
Expand All @@ -146,7 +146,7 @@ function SparseReverseADHessian(
c!,
H::SparseMatrixCSC{Bool, Int};
x0::AbstractVector{T} = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(),
kwargs...,
) where {T}
problem = ColoringProblem{:symmetric, :column}()
Expand Down

0 comments on commit 8d33aeb

Please sign in to comment.