Skip to content

Commit

Permalink
Upgrade ADNLPModels.jl for SparseMatrixColoring.jl v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Aug 13, 2024
1 parent 725413c commit 13a399d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ NLPModels = "0.18, 0.19, 0.20, 0.21"
Requires = "1"
ReverseDiff = "1"
SparseConnectivityTracer = "0.6"
SparseMatrixColorings = "0.3.5"
SparseMatrixColorings = "0.4.0"
julia = "^1.6"
24 changes: 16 additions & 8 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function SparseADHessian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
)
Expand All @@ -36,13 +36,17 @@ function SparseADHessian(
c!,
H::SparseMatrixCSC{Bool, Int64};
x0::S = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
kwargs...,
) where {S}
T = eltype(S)

colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)
problem = ColoringProblem(; structure=:symmetric, partition=:column)
result = coloring(H, problem, coloring, decompression_eltype=T)
colors = column_colors(result)
groups = column_groups(result)
ncolors = length(groups)
star_set = result.star_set

d = BitVector(undef, nvar)

Expand Down Expand Up @@ -125,7 +129,7 @@ function SparseReverseADHessian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
)
Expand All @@ -140,11 +144,15 @@ function SparseReverseADHessian(
c!,
H::SparseMatrixCSC{Bool, Int64};
x0::AbstractVector{T} = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
kwargs...,
) where {T}
colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)
problem = ColoringProblem(; structure=:symmetric, partition=:column)
result = coloring(H, problem, coloring, decompression_eltype=T)
colors = column_colors(result)
groups = column_groups(result)
ncolors = length(groups)
star_set = result.star_set

d = BitVector(undef, nvar)

Expand Down
11 changes: 7 additions & 4 deletions src/sparse_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function SparseADJacobian(
ncon,
c!;
x0::AbstractVector = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
)
Expand All @@ -32,12 +32,15 @@ function SparseADJacobian(
c!,
J::SparseMatrixCSC{Bool, Int64};
x0::AbstractVector{T} = rand(nvar),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(),
coloring::AbstractColoringAlgorithm = GreedyColoringAlgorithm(decompression=:direct),
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)
problem = ColoringProblem(; structure=:nonsymmetric, partition=:column)
result = coloring(J, problem, coloring, decompression_eltype=T)
colors = column_colors(result)
groups = column_groups(result)
ncolors = length(groups)

d = BitVector(undef, nvar)

Expand Down

0 comments on commit 13a399d

Please sign in to comment.