Skip to content

Commit 87b04d0

Browse files
committed
Update to NLPModels 0.14 + Modifiers + Test
1 parent ae088c7 commit 87b04d0

File tree

6 files changed

+35
-38
lines changed

6 files changed

+35
-38
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018-2019: Dominique Orban
1+
Copyright (c) 2018-2021: Dominique Orban
22

33
QuadraticModels.jl is licensed under the [MPL version 2.0](https://www.mozilla.org/MPL/2.0/).
44

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ authors = ["Dominique Orban <[email protected]>"]
44
version = "0.2.0"
55

66
[deps]
7-
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
87
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
98
LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
109
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
10+
NLPModelsModifiers = "e01155f1-5c6f-4375-a9d8-616dd036575f"
1111
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313

1414
[compat]
15-
FastClosures = "0.2.1, 0.3.0"
1615
LinearOperators = "0.7.0, 1"
17-
NLPModels = "0.13"
16+
NLPModels = "0.14"
17+
NLPModelsModifiers = "0.1"
1818
Requires = "0.3, 0.4, 0.5"
1919
julia = "^1.0.0"
2020

2121
[extras]
22+
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
23+
NLPModelsTest = "7998695d-6960-4d3a-85c4-e1bceb8cd856"
2224
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2325
QPSReader = "10f199a5-22af-520b-b891-7ce84a7b1bd0"
2426
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2527

2628
[targets]
27-
test = ["Printf", "Test", "QPSReader"]
29+
test = ["ADNLPModels", "NLPModelsTest", "Printf", "QPSReader", "Test"]

src/QuadraticModels.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module QuadraticModels
44
using LinearAlgebra, SparseArrays
55

66
# our packages
7-
using LinearOperators, NLPModels
7+
using LinearOperators, NLPModels, NLPModelsModifiers
88

99
# auxiliary packages
10-
using FastClosures, Requires
10+
using Requires
1111

1212
import NLPModels:
1313
objgrad, objgrad!, obj, grad, grad!,

src/qpmodel.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ end
184184

185185
function SlackModel!(qp :: AbstractQuadraticModel)
186186
qp.meta.ncon == length(qp.meta.jfix) && return qp
187-
187+
188188
nfix = length(qp.meta.jfix)
189189
ns = qp.meta.ncon - nfix
190190
T = eltype(qp.data.c)
@@ -195,11 +195,11 @@ function SlackModel!(qp :: AbstractQuadraticModel)
195195
append!(qp.data.Avals, (-one(T) for _ = 1 : ns))
196196
append!(qp.data.c, (zero(T) for _ = 1 : ns))
197197

198-
qp.meta = NLPModels.slack_meta(qp.meta, name=qp.meta.name)
198+
qp.meta = NLPModelsModifiers.slack_meta(qp.meta, name=qp.meta.name)
199199
return qp
200200
end
201201

202-
function NLPModels.SlackModel(qp :: AbstractQuadraticModel, name=qp.meta.name * "-slack")
202+
function NLPModelsModifiers.SlackModel(qp :: AbstractQuadraticModel, name=qp.meta.name * "-slack")
203203
qp.meta.ncon == length(qp.meta.jfix) && return qp
204204
nfix = length(qp.meta.jfix)
205205
ns = qp.meta.ncon - nfix
@@ -214,7 +214,7 @@ function NLPModels.SlackModel(qp :: AbstractQuadraticModel, name=qp.meta.name *
214214
[qp.data.Acols; qp.meta.nvar+1:qp.meta.nvar+ns],
215215
[qp.data.Avals; .-ones(T, ns)],
216216
)
217-
meta = NLPModels.slack_meta(qp.meta, name=qp.meta.name)
218-
217+
meta = NLPModelsModifiers.slack_meta(qp.meta, name=qp.meta.name)
218+
219219
return QuadraticModel( meta, Counters(), data)
220220
end

test/runtests.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# stdlib
2-
using Printf, SparseArrays, Test
2+
using LinearAlgebra, Printf, SparseArrays, Test
33

44
# our packages
5-
using LinearAlgebra, LinearOperators, NLPModels, QPSReader, QuadraticModels
6-
7-
nlpmodels_path = joinpath(dirname(pathof(NLPModels)), "..", "test")
8-
nlpmodels_problems_path = joinpath(nlpmodels_path, "problems")
5+
using ADNLPModels, LinearOperators, NLPModels, NLPModelsModifiers, NLPModelsTest, QPSReader, QuadraticModels
96

107
# Definition of quadratic problems
118
qp_problems_Matrix = ["bndqp", "eqconqp"]
@@ -14,7 +11,6 @@ for qp in [qp_problems_Matrix; qp_problems_COO]
1411
include(joinpath("problems", "$qp.jl"))
1512
end
1613

17-
include(joinpath(nlpmodels_path, "consistency.jl"))
1814
include("test_consistency.jl")
1915

2016
function testSM(sm) # test function for a specific problem
@@ -35,7 +31,7 @@ function testSM(sm) # test function for a specific problem
3531
@test all(sparse(sm.data.Arows, sm.data.Acols, sm.data.Avals, 2, 5) .== A_sm_true)
3632
@test all(sparse(sm.data.Hrows, sm.data.Hcols, sm.data.Hvals, 5, 5) .== H_sm_true)
3733
end
38-
34+
3935

4036
@testset "SlackModel" begin
4137
H = [6. 2. 1.
@@ -51,7 +47,7 @@ end
5147
qp = QuadraticModel(c, H, A=A, lcon=[-3; -4], ucon=[-2.; Inf], lvar=l, uvar=u, c0=0., name="QM1")
5248
sm = SlackModel(qp)
5349
testSM(sm)
54-
50+
5551
SlackModel!(qp)
5652
testSM(qp)
5753
end

test/test_consistency.jl

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,23 @@ for problem in qp_problems_COO
5252
@info " Consistency checks ✓"
5353
end
5454

55-
for problem in [:brownden, :hs5, :hs6, :hs10, :hs11, :hs14, :lincon]
56-
@info "Testing consistency of quadratic approximation of problem $problem"
57-
include(joinpath(nlpmodels_problems_path, "$problem.jl"))
58-
problem_s = string(problem)
59-
nlp = eval(Meta.parse("$(problem)_autodiff"))()
60-
x = nlp.meta.x0
55+
for problem in NLPModelsTest.nlp_problems
56+
@testset "Testing consistency of quadratic approximation of problem $problem" begin
57+
nlp = eval(Symbol(problem))()
58+
x = nlp.meta.x0
6159

62-
fx, gx, Hx = obj(nlp, x), grad(nlp, x), Symmetric(hess(nlp, x), :L)
63-
nlp_ad = if nlp.meta.ncon > 0
64-
cx, Ax = cons(nlp, x), jac(nlp, x)
65-
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
66-
nlp.meta.lvar - x, nlp.meta.uvar - x,
67-
s -> Ax * s, nlp.meta.lcon - cx, nlp.meta.ucon - cx)
68-
else
69-
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
70-
nlp.meta.lvar - x, nlp.meta.uvar - x)
60+
fx, gx, Hx = obj(nlp, x), grad(nlp, x), Symmetric(hess(nlp, x), :L)
61+
nlp_ad = if nlp.meta.ncon > 0
62+
cx, Ax = cons(nlp, x), jac(nlp, x)
63+
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
64+
nlp.meta.lvar - x, nlp.meta.uvar - x,
65+
s -> Ax * s, nlp.meta.lcon - cx, nlp.meta.ucon - cx)
66+
else
67+
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
68+
nlp.meta.lvar - x, nlp.meta.uvar - x)
69+
end
70+
nlp_qm = QuadraticModel(nlp, x)
71+
nlps = [nlp_ad, nlp_qm]
72+
consistent_nlps(nlps)
7173
end
72-
nlp_qm = QuadraticModel(nlp, x)
73-
nlps = [nlp_ad, nlp_qm]
74-
consistent_nlps(nlps)
7574
end

0 commit comments

Comments
 (0)