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

Add an option to provide the sparsity pattern of jacobians and hessians #284

Merged
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
34 changes: 30 additions & 4 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ function SparseADHessian(
f,
ncon,
c!;
x0::S = rand(nvar),
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)
SparseADHessian(nvar, f, ncon, c!, H; x0, coloring, kwargs...)
end

function SparseADHessian(
nvar,
f,
ncon,
c!,
H::SparseMatrixCSC{Bool,Int64};
x0::S = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
kwargs...,
) where {S}
T = eltype(S)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)

colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)
Expand Down Expand Up @@ -111,12 +124,25 @@ function SparseReverseADHessian(
f,
ncon,
c!;
x0::AbstractVector{T} = rand(nvar),
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
) where {T}
)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)
SparseReverseADHessian(nvar, f, ncon, c!, H; x0, coloring, kwargs...)
end

function SparseReverseADHessian(
nvar,
f,
ncon,
c!,
H::SparseMatrixCSC{Bool,Int64};
x0::AbstractVector{T} = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
kwargs...,
) where {T}

colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)
Expand Down
16 changes: 14 additions & 2 deletions src/sparse_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@ function SparseADJacobian(
f,
ncon,
c!;
x0::AbstractVector{T} = rand(nvar),
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
) where {T}
)
output = similar(x0, ncon)
J = compute_jacobian_sparsity(c!, output, x0, detector = detector)
SparseADJacobian(nvar, f, ncon, c!, J; x0, coloring, kwargs...)
end

function SparseADJacobian(
nvar,
f,
ncon,
c!,
J::SparseMatrixCSC{Bool,Int64};
x0::AbstractVector{T} = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
kwargs...,
) where {T}
# TODO: use ADTypes.row_coloring instead if you have the right decompression and some heuristic recommends it
colors = ADTypes.column_coloring(J, coloring)
ncolors = maximum(colors)
Expand Down
Loading