Skip to content

Commit

Permalink
fix for empty hessian/jacobian
Browse files Browse the repository at this point in the history
  • Loading branch information
sshin23 committed Apr 12, 2024
1 parent 40cced2 commit 3182a07
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
26 changes: 17 additions & 9 deletions lib/MadNLPGPU/src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ function MadNLP.mul!(
MadNLP.mul!(wx, kkt.hess_com , xx, alpha, beta)
MadNLP.mul!(wx, kkt.hess_com', xx, alpha, one(T))
MadNLP.mul!(wx, kkt.jt_csc, xz, alpha, beta)
diag_operation(CUDABackend())(
wx, kkt.hess_com.nzVal, xx, alpha,
kkt.ext.diag_map_to,
kkt.ext.diag_map_fr;
ndrange = length(kkt.ext.diag_map_to)
)
synchronize(CUDABackend())
if !isempty(kkt.ext.diag_map_to)
diag_operation(CUDABackend())(
wx, kkt.hess_com.nzVal, xx, alpha,
kkt.ext.diag_map_to,
kkt.ext.diag_map_fr;
ndrange = length(kkt.ext.diag_map_to)
)
synchronize(CUDABackend())
end

MadNLP.mul!(wz, kkt.jt_csc', xx, alpha, one(T))
MadNLP.axpy!(-alpha, xz, ws)
Expand Down Expand Up @@ -190,7 +192,11 @@ function get_diagonal_mapping(colptr, rowval)
inds1 = findall(map((x,y)-> ((x <= nnz) && (x != y)), @view(colptr[1:end-1]), @view(colptr[2:end])))
ptrs = colptr[inds1]
rows = rowval[ptrs]
inds2 = findall(inds1 .== rows)
inds2 = if isempty(rows)
similar(rowval,0)
else
findall(inds1 .== rows)
end

return rows[inds2], ptrs[inds2]
end
Expand Down Expand Up @@ -311,7 +317,9 @@ end


function MadNLP.force_lower_triangular!(I::CuVector{T},J) where T
_force_lower_triangular!(CUDABackend())(I,J; ndrange=length(I))
if !isempty(I)
_force_lower_triangular!(CUDABackend())(I,J; ndrange=length(I))
end
end

@kernel function _set_colptr_kernel!(colptr, @Const(sym2), @Const(ptr2), @Const(guide))
Expand Down
23 changes: 22 additions & 1 deletion lib/MadNLPTests/src/MadNLPTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ end

function test_madnlp(name,optimizer_constructor::Function,exclude; Arr = Array)
@testset "$name" begin
for f in [infeasible,unbounded,lootsma,eigmina]
for f in [infeasible,unbounded,lootsma,eigmina,lp]
!(string(f) in exclude) && f(optimizer_constructor; Arr = Arr)
end
end
Expand Down Expand Up @@ -331,6 +331,27 @@ function eigmina(optimizer_constructor::Function; Arr = Array)
end
end

function lp(optimizer_constructor::Function; Arr = Array)
@testset "lp" begin

model = Model()
@variable(model, x >= 0)
@variable(model, 0 <= y <= 3)
@objective(model, Min, 12x + 20y)
@constraint(model, c1, 6x + 8y >= 100)
@constraint(model, c2, 7x + 12y >= 120)

nlp = SparseWrapperModel(
Arr,
NLPModelsJuMP.MathOptNLPModel(m)
)
optimizer = optimizer_constructor()
result = MadNLP.madnlp(nlp; optimizer.options...)

@test result.status == MadNLP.SOLVE_SUCCEEDED
end
end

include("Instances/dummy_qp.jl")
include("Instances/hs15.jl")
include("Instances/nls.jl")
Expand Down

0 comments on commit 3182a07

Please sign in to comment.