Skip to content

Commit 5dbd9d5

Browse files
abelsiqueiradpo
authored andcommitted
Add more tests
1 parent 68287ff commit 5dbd9d5

File tree

9 files changed

+99
-35
lines changed

9 files changed

+99
-35
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2323
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2424

2525
[targets]
26-
test = ["Printf","Test"]
26+
test = ["Printf", "Test"]

src/qpmodel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function QuadraticModel(c :: AbstractVector,
2323
Hrows :: AbstractVector{<: Integer}, Hcols :: AbstractVector{<: Integer}, Hvals :: AbstractVector;
2424
Arows :: AbstractVector{<: Integer} = Int[], Acols :: AbstractVector{<: Integer} = Int[], Avals :: AbstractVector = Float64[],
2525
lcon :: AbstractVector = Float64[], ucon :: AbstractVector = Float64[],
26-
lvar :: AbstractVector = fill(-Inf, length(c)), uvar :: AbstractVector = fill(Int, length(c)),
26+
lvar :: AbstractVector = fill(-Inf, length(c)), uvar :: AbstractVector = fill(Inf, length(c)),
2727
c0 :: Float64=0.0, kwargs...)
2828
nnzh = length(Hvals)
2929
if !(nnzh == length(Hrows) == length(Hcols))

test/problems/bndqp.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
function bndqp_autodiff()
3+
4+
x0 = [0.5; 0.5]
5+
f(x) = -x[1]^2 + 2x[2]^2 + 3x[1] * x[2] + x[1] + x[2]
6+
uvar = [1.0; 1.0]
7+
lvar = [0.0; 0.0]
8+
9+
return ADNLPModel(f, x0, lvar=lvar, uvar=uvar, name="bndqp_autodiff")
10+
end
11+
12+
function bndqp_QP()
13+
c = [1.0; 1.0]
14+
H = [-2.0 0.0; 3.0 4.0]
15+
uvar = [1.0; 1.0]
16+
lvar = [0.0; 0.0]
17+
x0 = [0.5; 0.5]
18+
19+
return QuadraticModel(c, H, lvar=lvar, uvar=uvar, x0=x0, name="bndqp_QP")
20+
end

test/problems/eqconqp.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
function eqconqp_autodiff()
3+
4+
n = 50
5+
x0 = zeros(n)
6+
f(x) = sum(i * x[i]^2 for i = 1:n) / 2
7+
c(x) = [sum(x) - 1.0]
8+
lcon = [0.0]
9+
ucon = [0.0]
10+
11+
return ADNLPModel(f, x0, c=c, lcon=lcon, ucon=ucon, name="eqconqp_autodiff")
12+
end
13+
14+
function eqconqp_QP()
15+
n = 50
16+
c = zeros(n)
17+
H = spdiagm(0 => 1:n)
18+
A = ones(1, n)
19+
lcon = [1.0]
20+
ucon = [1.0]
21+
22+
return QuadraticModel(c, H, A=A, lcon=lcon, ucon=ucon, name="eqconqp_QP")
23+
end

test/problems/ineqconqp.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
function ineqconqp_autodiff()
3+
4+
x0 = ones(2)
5+
f(x) = (x[1] - 1)^2 / 2 + (x[2] - 1)^2 / 2
6+
c(x) = [x[1] - x[2]; x[2] - x[1]; x[1] + x[2]]
7+
lcon = [0.0; -Inf; -1.0]
8+
ucon = [Inf; 0.0; 1.0]
9+
10+
return ADNLPModel(f, x0, c=c, lcon=lcon, ucon=ucon, name="ineqconqp_autodiff")
11+
end
12+
13+
function ineqconqp_QP()
14+
c = -ones(2)
15+
Hrows = [1, 2]
16+
Hcols = [1, 2]
17+
Hvals = ones(2)
18+
Arows = [1, 1, 2, 2, 3, 3]
19+
Acols = [1, 2, 1, 2, 1, 2]
20+
Avals = [1.0; -1.0; -1.0; 1.0; 1.0; 1.0]
21+
c0 = 1.0
22+
lcon = [0.0; -Inf; -1.0]
23+
ucon = [Inf; 0.0; 1.0]
24+
x0 = ones(2)
25+
26+
return QuadraticModel(c, Hrows, Hcols, Hvals, Arows=Arows, Acols=Acols, Avals=Avals, lcon=lcon, ucon=ucon, c0=c0, x0=x0, name="ineqconqp_QP")
27+
end

test/problems/uncqp.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
function uncqp_autodiff()
3+
4+
x0 = [-1.2; 1.0]
5+
f(x) = 4*x[1]^2 + 5*x[2]^2 - x[1]*x[2] + 3.0*x[1] - 2*x[2] + 1.0
6+
7+
return ADNLPModel(f, x0, name="uncqp_autodiff")
8+
end
9+
10+
function uncqp_QP()
11+
c = [3.0; -2.0]
12+
Hrows = [1, 2, 2]
13+
Hcols = [1, 1, 2]
14+
Hvals = [8.0; -1.0; 10.0]
15+
c0 = 1.0
16+
x0 = [-1.2; 1.0]
17+
18+
return QuadraticModel(c, Hrows, Hcols, Hvals, c0=c0, x0=x0, name="uncqp_QP")
19+
end

test/runtests.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ using LinearAlgebra, LinearOperators, NLPModels, QuadraticModels
77
nlpmodels_path = joinpath(dirname(pathof(NLPModels)), "..", "test")
88
nlpmodels_problems_path = joinpath(nlpmodels_path, "problems")
99

10-
# Definition of the quadratic problem in ADNLPModel
11-
include("simpleqp.jl")
10+
# Definition of quadratic problems
11+
qp_problems = ["uncqp", "bndqp", "eqconqp", "ineqconqp"]
12+
for qp in qp_problems
13+
include(joinpath("problems", "$qp.jl"))
14+
end
1215

1316
include(joinpath(nlpmodels_path, "consistency.jl"))
1417
include("test_consistency.jl")

test/simpleqp.jl

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/test_consistency.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ function check_quadratic_model(model, quadraticmodel)
3030
reset!(quadraticmodel)
3131
end
3232

33-
for problem in ["simpleqp"]
34-
@info "Testing consistency of problem $problem"
33+
for problem in qp_problems
34+
@info "Checking consistency of problem $problem"
3535
nlp_ad = eval(Symbol(problem * "_autodiff"))()
3636
nlp_qm = eval(Symbol(problem * "_QP"))()
3737
nlps = [nlp_ad, nlp_qm]
38-
# Excluding hprod until we change to coordinate format for H because
39-
# hess_op uses opH, which doesn't increment the counters.
4038
consistent_nlps(nlps)
39+
@info " Consistency checks ✓"
4140
end
4241

4342
for problem in [:brownden, :hs5, :hs6, :hs10, :hs11, :hs14, :lincon]

0 commit comments

Comments
 (0)