diff --git a/src/enzyme.jl b/src/enzyme.jl index 74769504..ec674f61 100644 --- a/src/enzyme.jl +++ b/src/enzyme.jl @@ -110,7 +110,7 @@ function SparseEnzymeADJacobian( ncon, c!; x0::AbstractVector = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(postprocessing=true), detector::AbstractSparsityDetector = TracerSparsityDetector(), show_time::Bool = false, kwargs..., @@ -130,7 +130,7 @@ function SparseEnzymeADJacobian( c!, J::SparseMatrixCSC{Bool, Int}; x0::AbstractVector{T} = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(postprocessing=true), show_time::Bool = false, kwargs..., ) where {T} @@ -187,7 +187,7 @@ function SparseEnzymeADHessian( ncon, c!; x0::AbstractVector = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(postprocessing=true), detector::AbstractSparsityDetector = TracerSparsityDetector(), show_time::Bool = false, kwargs..., @@ -206,7 +206,7 @@ function SparseEnzymeADHessian( c!, H::SparseMatrixCSC{Bool, Int}; x0::AbstractVector{T} = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(postprocessing=true), show_time::Bool = false, kwargs..., ) where {T} diff --git a/src/sparse_hessian.jl b/src/sparse_hessian.jl index f226ae0d..fa0be00d 100644 --- a/src/sparse_hessian.jl +++ b/src/sparse_hessian.jl @@ -22,7 +22,7 @@ function SparseADHessian( ncon, c!; x0::AbstractVector = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(postprocessing=true), detector::AbstractSparsityDetector = TracerSparsityDetector(), show_time::Bool = false, kwargs..., @@ -41,7 +41,7 @@ function SparseADHessian( c!, H::SparseMatrixCSC{Bool, Int64}; x0::S = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:direct}(postprocessing=true), show_time::Bool = false, kwargs..., ) where {S} @@ -143,7 +143,7 @@ function SparseReverseADHessian( ncon, c!; x0::AbstractVector = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(postprocessing=true), detector::AbstractSparsityDetector = TracerSparsityDetector(), show_time::Bool = false, kwargs..., @@ -162,7 +162,7 @@ function SparseReverseADHessian( c!, H::SparseMatrixCSC{Bool, Int}; x0::AbstractVector{T} = rand(nvar), - coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(), + coloring_algorithm::AbstractColoringAlgorithm = GreedyColoringAlgorithm{:substitution}(postprocessing=true), show_time::Bool = false, kwargs..., ) where {T} diff --git a/test/runtests.jl b/test/runtests.jl index 44ccce21..89f97396 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,26 +39,54 @@ list_sparse_jac_backend = end list_sparse_hess_backend = ( - (ADNLPModels.SparseADHessian, Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}())), + (ADNLPModels.SparseADHessian, + "star coloring with postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing=true)), + ), + (ADNLPModels.SparseADHessian, + "star coloring without postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing=false)), + ), + ( + ADNLPModels.SparseADHessian, + "acyclic coloring with postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing=true)), + ), ( ADNLPModels.SparseADHessian, - Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}()), + "acyclic coloring without postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing=false)), + ), + ( + ADNLPModels.SparseReverseADHessian, + "star coloring with postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing=true)), + ), + ( + ADNLPModels.SparseReverseADHessian, + "star coloring without postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}(postprocessing=false)), ), ( ADNLPModels.SparseReverseADHessian, - Dict(:coloring_algorithm => GreedyColoringAlgorithm{:direct}()), + "acyclic coloring with postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing=true)), ), ( ADNLPModels.SparseReverseADHessian, - Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}()), + "acyclic coloring without postprocessing", + Dict(:coloring_algorithm => GreedyColoringAlgorithm{:substitution}(postprocessing=false)), + ), + (ADNLPModels.ForwardDiffADHessian, + "default", + Dict(), ), - (ADNLPModels.ForwardDiffADHessian, Dict()), ) @testset "Sparse Hessian" begin - for (backend, kw) in list_sparse_hess_backend - sparse_hessian(backend, kw) - sparse_hessian_nls(backend, kw) + for (backend, info, kw) in list_sparse_hess_backend + sparse_hessian(backend, info, kw) + sparse_hessian_nls(backend, info, kw) end end diff --git a/test/sparse_hessian.jl b/test/sparse_hessian.jl index ca130989..14c469e0 100644 --- a/test/sparse_hessian.jl +++ b/test/sparse_hessian.jl @@ -1,5 +1,5 @@ -function sparse_hessian(backend, kw) - @testset "Basic Hessian derivative with backend=$(backend) and T=$(T)" for T in (Float32, Float64) +function sparse_hessian(backend, info, kw) + @testset "Basic Hessian derivative with backend=$(backend) -- $info -- T=$(T)" for T in (Float32, Float64) c!(cx, x) = begin cx[1] = x[1] - 1 cx[2] = 10 * (x[2] - x[1]^2) diff --git a/test/sparse_hessian_nls.jl b/test/sparse_hessian_nls.jl index 2369fdd1..796e6567 100644 --- a/test/sparse_hessian_nls.jl +++ b/test/sparse_hessian_nls.jl @@ -1,5 +1,5 @@ -function sparse_hessian_nls(backend, kw) - @testset "Basic Hessian of residual derivative with backend=$(backend) and T=$(T)" for T in ( +function sparse_hessian_nls(backend, info, kw) + @testset "Basic Hessian of residual derivative with backend=$(backend) -- $info -- T=$(T)" for T in ( Float32, Float64, )