Skip to content
Draft
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
8 changes: 6 additions & 2 deletions src/enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function SparseEnzymeADJacobian(
c!;
x0::AbstractVector = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(
decompression_uplo = :L,
postprocessing = true,
),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
Expand All @@ -133,6 +134,7 @@ function SparseEnzymeADJacobian(
J::SparseMatrixCSC{Bool, Int};
x0::AbstractVector{T} = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(
decompression_uplo = :L,
postprocessing = true,
),
show_time::Bool = false,
Expand Down Expand Up @@ -192,6 +194,7 @@ function SparseEnzymeADHessian(
c!;
x0::AbstractVector = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(
decompression_uplo = :L,
postprocessing = true,
),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
Expand All @@ -213,6 +216,7 @@ function SparseEnzymeADHessian(
H::SparseMatrixCSC{Bool, Int};
x0::AbstractVector{T} = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(
decompression_uplo = :L,
postprocessing = true,
),
show_time::Bool = false,
Expand Down Expand Up @@ -533,14 +537,14 @@ end

if b.coloring_mode == :direct
# Update the coefficients of the lower triangular part of the Hessian that are related to the color `icol`
decompress_single_color!(A, b.compressed_hessian_icol, icol, b.result_coloring, :L)
decompress_single_color!(A, b.compressed_hessian_icol, icol, b.result_coloring)
end
if b.coloring_mode == :substitution
view(b.compressed_hessian, :, icol) .= b.compressed_hessian_icol
end
end
if b.coloring_mode == :substitution
decompress!(A, b.compressed_hessian, b.result_coloring, :L)
decompress!(A, b.compressed_hessian, b.result_coloring)
end
vals .= b.nzval
return vals
Expand Down
24 changes: 8 additions & 16 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ function SparseADHessian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(
postprocessing = true,
),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=true),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
show_time::Bool = false,
kwargs...,
Expand All @@ -43,9 +41,7 @@ function SparseADHessian(
c!,
H::SparseMatrixCSC{Bool, Int64};
x0::S = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(
postprocessing = true,
),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=true),
show_time::Bool = false,
kwargs...,
) where {S}
Expand Down Expand Up @@ -147,9 +143,7 @@ function SparseReverseADHessian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(
postprocessing = true,
),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=true),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
show_time::Bool = false,
kwargs...,
Expand All @@ -168,9 +162,7 @@ function SparseReverseADHessian(
c!,
H::SparseMatrixCSC{Bool, Int};
x0::AbstractVector{T} = rand(nvar),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(
postprocessing = true,
),
coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=true),
show_time::Bool = false,
kwargs...,
) where {T}
Expand Down Expand Up @@ -315,11 +307,11 @@ function sparse_hess_coord!(
compressed_hessian_icol .= view(b.Hvp, (ncon + 1):(ncon + b.nvar))
if b.coloring_mode == :direct
# Update the coefficients of the lower triangular part of the Hessian that are related to the color `icol`
decompress_single_color!(A, compressed_hessian_icol, icol, b.result_coloring, :L)
decompress_single_color!(A, compressed_hessian_icol, icol, b.result_coloring)
end
end
if b.coloring_mode == :substitution
decompress!(A, b.compressed_hessian, b.result_coloring, :L)
decompress!(A, b.compressed_hessian, b.result_coloring)
end
vals .= b.nzval
return vals
Expand Down Expand Up @@ -362,11 +354,11 @@ function sparse_hess_coord!(

if b.coloring_mode == :direct
# Update the coefficients of the lower triangular part of the Hessian that are related to the color `icol`
decompress_single_color!(A, compressed_hessian_icol, icol, b.result_coloring, :L)
decompress_single_color!(A, compressed_hessian_icol, icol, b.result_coloring)
end
end
if b.coloring_mode == :substitution
decompress!(A, b.compressed_hessian, b.result_coloring, :L)
decompress!(A, b.compressed_hessian, b.result_coloring)
end
vals .= b.nzval
return vals
Expand Down
27 changes: 14 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,48 @@ list_sparse_jac_backend =
end

list_sparse_hess_backend = (
(
ADNLPModels.SparseADHessian,
(ADNLPModels.SparseADHessian,
"star coloring with postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing = true)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=true)),
),
(
ADNLPModels.SparseADHessian,
(ADNLPModels.SparseADHessian,
"star coloring without postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing = false)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=false)),
),
(
ADNLPModels.SparseADHessian,
"acyclic coloring with postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing = true)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=true)),
),
(
ADNLPModels.SparseADHessian,
"acyclic coloring without postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing = false)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=false)),
),
(
ADNLPModels.SparseReverseADHessian,
"star coloring with postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing = true)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=true)),
),
(
ADNLPModels.SparseReverseADHessian,
"star coloring without postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing = false)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(decompression_uplo=:L, postprocessing=false)),
),
(
ADNLPModels.SparseReverseADHessian,
"acyclic coloring with postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing = true)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=true)),
),
(
ADNLPModels.SparseReverseADHessian,
"acyclic coloring without postprocessing",
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing = false)),
Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(decompression_uplo=:L, postprocessing=false)),
),
(ADNLPModels.ForwardDiffADHessian,
"default",
Dict(),
),
(ADNLPModels.ForwardDiffADHessian, "default", Dict()),
)

@testset "Sparse Hessian" begin
Expand Down
Loading