Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic sparsity detector #238

Closed
Closed
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions src/ADNLPModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module ADNLPModels
# stdlib
using LinearAlgebra, SparseArrays
# external
using ADTypes: ADTypes
using ColPack, ForwardDiff, ReverseDiff
# JSO
using NLPModels
Expand Down
18 changes: 8 additions & 10 deletions src/sparse_sym.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Loading