From 703e0ff55c84a96f543f5adfd61849e60263ed1f Mon Sep 17 00:00:00 2001 From: ArnoStrouwen Date: Sun, 9 Oct 2022 07:18:33 +0200 Subject: [PATCH 1/3] remove deprecated SparsityDetection --- Project.toml | 4 ++-- src/SparseDiffTools.jl | 4 ++++ src/differentiation/sparsity_detection.jl | 8 ++++++++ test/test_integration.jl | 3 +-- test/test_sparse_hessian.jl | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/differentiation/sparsity_detection.jl diff --git a/Project.toml b/Project.toml index d40435b9..bd9e2c21 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Requires = "ae029012-a4dd-5104-9daa-d747884805df" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f" [compat] @@ -41,10 +42,9 @@ IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -SparsityDetection = "684fba80-ace3-11e9-3d08-3bc7ed6f96df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["Test", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices", "BandedMatrices", "BlockBandedMatrices", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Zygote", "SparsityDetection", "StaticArrays"] +test = ["Test", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices", "BandedMatrices", "BlockBandedMatrices", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Zygote", "StaticArrays"] diff --git a/src/SparseDiffTools.jl b/src/SparseDiffTools.jl index 015e79c9..c88fe342 100644 --- a/src/SparseDiffTools.jl +++ b/src/SparseDiffTools.jl @@ -11,6 +11,7 @@ using Adapt using LinearAlgebra using SparseArrays, ArrayInterfaceCore +using Symbolics import StaticArrays, ArrayInterfaceStaticArrays @@ -25,6 +26,8 @@ export contract_color, greedy_star2_coloring, matrix2graph, matrix_colors, + jacobian_sparsity, + hessian_sparsity, forwarddiff_color_jacobian!, forwarddiff_color_jacobian, ForwardColorJacCache, @@ -57,6 +60,7 @@ include("differentiation/compute_jacobian_ad.jl") include("differentiation/compute_hessian_ad.jl") include("differentiation/jaches_products.jl") include("differentiation/vecjac_products.jl") +include("differentiation/sparsity_detection.jl") Base.@pure __parameterless_type(T) = Base.typename(T).wrapper parameterless_type(x) = parameterless_type(typeof(x)) diff --git a/src/differentiation/sparsity_detection.jl b/src/differentiation/sparsity_detection.jl new file mode 100644 index 00000000..b48393fb --- /dev/null +++ b/src/differentiation/sparsity_detection.jl @@ -0,0 +1,8 @@ +function jacobian_sparsity(func::Function, output::AbstractVector{T}, input::AbstractVector{T}; kwargs...) where {T<:Number} + Symbolics.jacobian_sparsity(func,output,input) +end +function hessian_sparsity(func::Function, input::AbstractVector{T}; kwargs...) where {T<:Number} + vars = map(Symbolics.variable, eachindex(input)) + expr = func(vars; kwargs...) + Symbolics.hessian_sparsity(expr, vars) +end diff --git a/test/test_integration.jl b/test/test_integration.jl index 04e40c54..ec04cf9f 100644 --- a/test/test_integration.jl +++ b/test/test_integration.jl @@ -1,6 +1,5 @@ using SparseDiffTools using FiniteDiff: finite_difference_jacobian, finite_difference_jacobian! -using SparsityDetection using LinearAlgebra, SparseArrays, Test @@ -37,7 +36,7 @@ function second_derivative_stencil(N) end output = ones(30); input = ones(30) -sparsity_pattern = sparsity!(f,output,input) +sparsity_pattern = jacobian_sparsity(f,output,input) true_jac = Float64.(sparse(sparsity_pattern)) colors = matrix_colors(true_jac) @test colors == repeat(1:3,10) diff --git a/test/test_sparse_hessian.jl b/test/test_sparse_hessian.jl index 9933990f..477b16d5 100644 --- a/test/test_sparse_hessian.jl +++ b/test/test_sparse_hessian.jl @@ -1,5 +1,5 @@ ## Hessian tests -using SparsityDetection, SparseDiffTools +using SparseDiffTools using ForwardDiff using LinearAlgebra, SparseArrays From 1afad2082209d46394cd6296ab70268063837889 Mon Sep 17 00:00:00 2001 From: ArnoStrouwen Date: Mon, 10 Oct 2022 08:02:22 +0200 Subject: [PATCH 2/3] sparsity detection from Symbolics --- Project.toml | 4 ++-- src/SparseDiffTools.jl | 2 -- src/differentiation/sparsity_detection.jl | 8 -------- test/test_integration.jl | 3 ++- test/test_sparse_hessian.jl | 3 ++- 5 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 src/differentiation/sparsity_detection.jl diff --git a/Project.toml b/Project.toml index bd9e2c21..54cafe8b 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Requires = "ae029012-a4dd-5104-9daa-d747884805df" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" -Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f" [compat] @@ -43,8 +42,9 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [targets] -test = ["Test", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices", "BandedMatrices", "BlockBandedMatrices", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Zygote", "StaticArrays"] +test = ["Test", "ArrayInterfaceBandedMatrices", "ArrayInterfaceBlockBandedMatrices", "BandedMatrices", "BlockBandedMatrices", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays"] diff --git a/src/SparseDiffTools.jl b/src/SparseDiffTools.jl index c88fe342..555c994a 100644 --- a/src/SparseDiffTools.jl +++ b/src/SparseDiffTools.jl @@ -11,7 +11,6 @@ using Adapt using LinearAlgebra using SparseArrays, ArrayInterfaceCore -using Symbolics import StaticArrays, ArrayInterfaceStaticArrays @@ -60,7 +59,6 @@ include("differentiation/compute_jacobian_ad.jl") include("differentiation/compute_hessian_ad.jl") include("differentiation/jaches_products.jl") include("differentiation/vecjac_products.jl") -include("differentiation/sparsity_detection.jl") Base.@pure __parameterless_type(T) = Base.typename(T).wrapper parameterless_type(x) = parameterless_type(typeof(x)) diff --git a/src/differentiation/sparsity_detection.jl b/src/differentiation/sparsity_detection.jl deleted file mode 100644 index b48393fb..00000000 --- a/src/differentiation/sparsity_detection.jl +++ /dev/null @@ -1,8 +0,0 @@ -function jacobian_sparsity(func::Function, output::AbstractVector{T}, input::AbstractVector{T}; kwargs...) where {T<:Number} - Symbolics.jacobian_sparsity(func,output,input) -end -function hessian_sparsity(func::Function, input::AbstractVector{T}; kwargs...) where {T<:Number} - vars = map(Symbolics.variable, eachindex(input)) - expr = func(vars; kwargs...) - Symbolics.hessian_sparsity(expr, vars) -end diff --git a/test/test_integration.jl b/test/test_integration.jl index ec04cf9f..ec9de57c 100644 --- a/test/test_integration.jl +++ b/test/test_integration.jl @@ -1,4 +1,5 @@ using SparseDiffTools +using Symbolics using FiniteDiff: finite_difference_jacobian, finite_difference_jacobian! using LinearAlgebra, SparseArrays, Test @@ -36,7 +37,7 @@ function second_derivative_stencil(N) end output = ones(30); input = ones(30) -sparsity_pattern = jacobian_sparsity(f,output,input) +sparsity_pattern = Symbolics.jacobian_sparsity(f,output,input) true_jac = Float64.(sparse(sparsity_pattern)) colors = matrix_colors(true_jac) @test colors == repeat(1:3,10) diff --git a/test/test_sparse_hessian.jl b/test/test_sparse_hessian.jl index 477b16d5..c950775f 100644 --- a/test/test_sparse_hessian.jl +++ b/test/test_sparse_hessian.jl @@ -1,5 +1,6 @@ ## Hessian tests using SparseDiffTools +using Symbolics using ForwardDiff using LinearAlgebra, SparseArrays @@ -8,7 +9,7 @@ function fscalar(x) end x = randn(5) -sparsity = hessian_sparsity(fscalar, x) +sparsity = Symbolics.hessian_sparsity(fscalar, x) colors = matrix_colors(tril(sparsity)) ncolors = maximum(colors) D = hcat([float.(i .== colors) for i in 1:ncolors]...) From 9b34e50cc00d72540d54f60124c7ac69f6852387 Mon Sep 17 00:00:00 2001 From: ArnoStrouwen Date: Mon, 10 Oct 2022 08:04:14 +0200 Subject: [PATCH 3/3] Remove sparsity detection exports --- src/SparseDiffTools.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SparseDiffTools.jl b/src/SparseDiffTools.jl index 555c994a..015e79c9 100644 --- a/src/SparseDiffTools.jl +++ b/src/SparseDiffTools.jl @@ -25,8 +25,6 @@ export contract_color, greedy_star2_coloring, matrix2graph, matrix_colors, - jacobian_sparsity, - hessian_sparsity, forwarddiff_color_jacobian!, forwarddiff_color_jacobian, ForwardColorJacCache,