Skip to content

Commit

Permalink
[ci] improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
frapac committed Jul 8, 2022
1 parent 59aa6e5 commit 8def6c4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
20 changes: 20 additions & 0 deletions test/kkt_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using LinearAlgebra

@testset "$KKTVector" for KKTVector in [
MadNLP.ReducedKKTVector,
MadNLP.UnreducedKKTVector,
]
T = Float64
VT = Vector{Float64}
n, m = 10, 20
nlb, nub = 5, 6

rhs = KKTVector{T, VT}(n, m, nlb, nub)
@test length(rhs) == length(MadNLP.full(rhs))
@test MadNLP.number_primal(rhs) == length(MadNLP.primal(rhs)) == n
@test MadNLP.number_dual(rhs) == length(MadNLP.dual(rhs)) == m
@test norm(rhs) == 0

fill!(rhs, one(T))
@test norm(rhs) == sqrt(length(rhs))
end
18 changes: 14 additions & 4 deletions test/madnlp_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ using MadNLPTests
using SparseArrays
using Random

function _compare_dense_with_sparse(kkt_system, n, m, ind_fixed, ind_eq)
function _compare_dense_with_sparse(
kkt_system, n, m, ind_fixed, ind_eq;
inertia=MadNLP.INERTIA_BASED,
)

for (T,tol,atol) in [(Float32,1e-3,1e-1), (Float64,1e-8,1e-6)]

sparse_options = Dict{Symbol, Any}(
:kkt_system=>MadNLP.SPARSE_KKT_SYSTEM,
:inertia_correction_method=>inertia,
:linear_solver=>MadNLP.LapackCPUSolver,
:print_level=>MadNLP.ERROR,
:tol=>tol
)
dense_options = Dict{Symbol, Any}(
:kkt_system=>kkt_system,
:inertia_correction_method=>inertia,
:linear_solver=>MadNLP.LapackCPUSolver,
:print_level=>MadNLP.ERROR,
:tol=>tol
)

nlp = MadNLPTests.DenseDummyQP{T}(; n=n, m=m, fixed_variables=ind_fixed, equality_cons=ind_eq)

ips = MadNLP.InteriorPointSolver(nlp, option_dict=sparse_options)
Expand All @@ -32,6 +37,7 @@ function _compare_dense_with_sparse(kkt_system, n, m, ind_fixed, ind_eq)
MadNLP.optimize!(ipd)

# Check that dense formulation matches exactly sparse formulation
@test ipd.status == MadNLP.SOLVE_SUCCEEDED
@test ips.cnt.k == ipd.cnt.k
@test ips.obj_val ipd.obj_val atol=atol
@test ips.x ipd.x atol=atol
Expand Down Expand Up @@ -101,14 +107,18 @@ end
@testset "MadNLP: option kkt_system=$(kkt_system)" for kkt_system in [MadNLP.DENSE_KKT_SYSTEM, MadNLP.DENSE_CONDENSED_KKT_SYSTEM]
@testset "Size: ($n, $m)" for (n, m) in [(10, 0), (10, 5), (50, 10)]
_compare_dense_with_sparse(kkt_system, n, m, Int[], Int[])
_compare_dense_with_sparse(kkt_system, n, m, Int[], Int[]; inertia=MadNLP.INERTIA_FREE)
end
# Test with non-trivial equality constraints.
@testset "Equality constraints" begin
n, m = 20, 15
_compare_dense_with_sparse(kkt_system, n, m, Int[], Int[1, 8]) # test with non-trivial equality constraints
_compare_dense_with_sparse(kkt_system, n, m, Int[], Int[1, 8])
_compare_dense_with_sparse(kkt_system, n, m, Int[], Int[1, 8]; inertia=MadNLP.INERTIA_FREE)
end
@testset "Fixed variables" begin
n, m = 10, 5
_compare_dense_with_sparse(kkt_system, n, m, Int[1, 2], Int[])
_compare_dense_with_sparse(kkt_system, n, m, Int[1, 2], Int[]; inertia=MadNLP.INERTIA_FREE)
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/madnlp_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ testset = [
"LapackCPU-BUNCHKAUFMAN",
()->MadNLP.Optimizer(
linear_solver=MadNLP.LapackCPUSolver,
lapackcpu_algorithm=MadNLP.BUNCHKAUFMAN,
lapack_algorithm=MadNLP.BUNCHKAUFMAN,
print_level=MadNLP.ERROR),
[]
],
[
"LapackCPU-LU",
()->MadNLP.Optimizer(
linear_solver=MadNLP.LapackCPUSolver,
lapackcpu_algorithm=MadNLP.LU,
lapack_algorithm=MadNLP.LU,
print_level=MadNLP.ERROR),
[]
],
[
"LapackCPU-QR",
()->MadNLP.Optimizer(
linear_solver=MadNLP.LapackCPUSolver,
lapackcpu_algorithm=MadNLP.QR,
lapack_algorithm=MadNLP.QR,
print_level=MadNLP.ERROR),
[]
],
[
"LapackCPU-CHOLESKY",
()->MadNLP.Optimizer(
linear_solver=MadNLP.LapackCPUSolver,
lapackcpu_algorithm=MadNLP.CHOLESKY,
lapack_algorithm=MadNLP.CHOLESKY,
print_level=MadNLP.ERROR),
["infeasible", "lootsma", "eigmina"]
],
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import SparseArrays: sparse
include("matrix_test.jl")
end

@testset "KKTSystem" begin
include("kkt_test.jl")
end

@testset "MOI interface" begin
include("MOI_interface_test.jl")
end
Expand Down

0 comments on commit 8def6c4

Please sign in to comment.