Skip to content

Commit

Permalink
Modifications done during the flight
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed May 19, 2024
1 parent 9b96b98 commit 3beaae8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/sparsity_pattern.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"""
compute_jacobian_sparsity(c, x0)
compute_jacobian_sparsity(c!, cx, x0)
Return a sparse matrix.
"""
function compute_jacobian_sparsity end

function compute_jacobian_sparsity(c, x0)
S = SparseConnectivityTracer.jacobian_pattern(c, x0)
return S
end

function compute_jacobian_sparsity(c!, cx, x0)
S = SparseConnectivityTracer.jacobian_pattern(c!, cx, x0)
return S
Expand All @@ -21,8 +29,10 @@ function compute_hessian_sparsity(f, nvar, c!, ncon)
else
x0 = rand(nvar)
y0 = rand(ncon)
cx = similar(y0)
(x) = f(x) + sum(c!(cx, x)[i] * y0[i] for i = 1:ncon)
function (x)
cx = similar(x, ncon)
return f(x) + sum(c!(cx, x)[i] * y0[i] for i = 1:ncon)
end
S = SparseConnectivityTracer.hessian_pattern(ℓ, x0)
return S
end
Expand Down
11 changes: 4 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ using ADNLPModels:

@testset "Test sparsity pattern of Jacobian and Hessian" begin
f(x) = sum(x)
c!(cx, x) = begin
cx .= 1
return x
end
nvar, ncon = 2, 1
c(x) = x
c!(cx, x) = copyto!(cx, x)
nvar, ncon = 2, 2
x0 = ones(nvar)
cx = rand(ncon)
S = ADNLPModels.compute_jacobian_sparsity(c, x0)
S = ADNLPModels.compute_jacobian_sparsity(c!, cx, x0)
S = ADNLPModels.compute_hessian_sparsity(f, nvar, c!, ncon)
end
Expand Down Expand Up @@ -41,13 +40,11 @@ push!(
ADNLPModels.predefined_backend,
:zygote_backend => Dict(
:gradient_backend => ADNLPModels.ZygoteADGradient,
:hprod_backend => ADNLPModels.SDTForwardDiffADHvprod,
:jprod_backend => ADNLPModels.ZygoteADJprod,
:jtprod_backend => ADNLPModels.ZygoteADJtprod,
:jacobian_backend => ADNLPModels.ZygoteADJacobian,
:hessian_backend => ADNLPModels.ZygoteADHessian,
:ghjvprod_backend => ADNLPModels.ForwardDiffADGHjvprod,
:hprod_residual_backend => ADNLPModels.SDTForwardDiffADHvprod,
:jprod_residual_backend => ADNLPModels.ZygoteADJprod,
:jtprod_residual_backend => ADNLPModels.ZygoteADJtprod,
:jacobian_residual_backend => ADNLPModels.ZygoteADJacobian,
Expand Down

0 comments on commit 3beaae8

Please sign in to comment.