diff --git a/Project.toml b/Project.toml index 4364b41c..8a337614 100644 --- a/Project.toml +++ b/Project.toml @@ -3,6 +3,7 @@ uuid = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" version = "0.7.2" [deps] +ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" ColPack = "ffa27691-3a59-46ab-a8d4-551f45b8d401" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -12,6 +13,7 @@ ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] +ADTypes = "1.2.1" ColPack = "0.4" ForwardDiff = "0.9.0, 0.10.0" NLPModels = "0.18, 0.19, 0.20, 0.21" diff --git a/docs/Project.toml b/docs/Project.toml index c8657e93..51be8073 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -25,5 +25,5 @@ Percival = "0.7" Plots = "1" SolverBenchmark = "0.5" SymbolicUtils = "=1.5.1" -Symbolics = "5.3" +Symbolics = "5.29" Zygote = "0.6.62" diff --git a/src/ADNLPModels.jl b/src/ADNLPModels.jl index 481724bb..d3f846b4 100644 --- a/src/ADNLPModels.jl +++ b/src/ADNLPModels.jl @@ -3,6 +3,7 @@ module ADNLPModels # stdlib using LinearAlgebra, SparseArrays # external +using ADTypes: ADTypes using ColPack, ForwardDiff, ReverseDiff # JSO using NLPModels diff --git a/src/sparse_sym.jl b/src/sparse_sym.jl index e90c5514..1c04aa00 100644 --- a/src/sparse_sym.jl +++ b/src/sparse_sym.jl @@ -1,19 +1,17 @@ function compute_hessian_sparsity(f, nvar, c!, ncon) - Symbolics.@variables xs[1:nvar] - xsi = Symbolics.scalarize(xs) - fun = f(xsi) - if ncon > 0 - Symbolics.@variables ys[1:ncon] - ysi = Symbolics.scalarize(ys) - cx = similar(ysi) - fun = fun + dot(c!(cx, xsi), ysi) + detector = Symbolics.SymbolicsSparsityDetector() # replaceable + function lagrangian(x) + cx = zeros(eltype(x), ncon) + c!(cx, x) + return f(x) + dot(rand(ncon), cx) end - S = Symbolics.hessian_sparsity(fun, ncon == 0 ? xsi : [xsi; ysi]) # , full = false + S = ADTypes.hessian_sparsity(lagrangian, rand(nvar), detector) # , full = false return S end function compute_jacobian_sparsity(c!, cx, x0) - S = Symbolics.jacobian_sparsity(c!, cx, x0) + detector = Symbolics.SymbolicsSparsityDetector() # replaceable + S = ADTypes.jacobian_sparsity(c!, cx, x0, detector) return S end diff --git a/test/Project.toml b/test/Project.toml index 0f94a872..1f344a0e 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,7 +10,6 @@ NLPModelsTest = "7998695d-6960-4d3a-85c4-e1bceb8cd856" ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804" -SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" @@ -25,6 +24,5 @@ NLPModelsModifiers = "0.7" NLPModelsTest = "0.10" ReverseDiff = "1" SparseDiffTools = "2.3" -Symbolics = "5.3" -SymbolicUtils = "=1.5.1" +Symbolics = "5.29" Zygote = "0.6"