Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[documentation] Give more details on coloring algorithms #297

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/src/sparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ 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.
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.
However, it requires storing the compressed sparse Hessian, while `:direct` coloring only stores one column of the compressed Hessian.

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.

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
Loading