Skip to content

Commit d1506fd

Browse files
authored
Add allocations tests (#91)
* Add allocations tests * add tests with new QN solvers
1 parent 055cf35 commit d1506fd

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ NLPModels = "0.19"
1717
julia = "^1.6.0"
1818

1919
[extras]
20+
NLPModelsTest = "7998695d-6960-4d3a-85c4-e1bceb8cd856"
2021
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2122

2223
[targets]
23-
test = ["Test"]
24+
test = ["NLPModelsTest", "Test"]

test/allocs_test.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@testset "Check allocations for model modifiers of NLP" begin
2+
map(
3+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
4+
map(x -> LBFGSModel(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
5+
)
6+
map(
7+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
8+
map(x -> LSR1Model(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
9+
)
10+
map(
11+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
12+
map(x -> DiagonalQNModel(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
13+
)
14+
map(
15+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
16+
map(x -> SpectralGradientModel(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
17+
)
18+
map(
19+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
20+
map(x -> SlackModel(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
21+
)
22+
problems = setdiff(NLPModelsTest.nlp_problems, ["BROWNDEN", "HS5"])
23+
map(
24+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess]),
25+
map(x -> FeasibilityResidual(eval(Symbol(x))()), problems),
26+
)
27+
end
28+
29+
@testset "Check allocations for model modifiers of NLS" begin
30+
problems = NLPModelsTest.nls_problems
31+
# `obj` and `grad` of an NLS model allocates a vector of size `nequ`.
32+
map(
33+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [obj, grad, hess]),
34+
map(x -> LBFGSModel(eval(Symbol(x))()), problems),
35+
)
36+
map(
37+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [obj, grad, hess]),
38+
map(x -> LSR1Model(eval(Symbol(x))()), problems),
39+
)
40+
map(
41+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [obj, grad, hess]),
42+
map(x -> SlackModel(eval(Symbol(x))()), NLPModelsTest.nlp_problems),
43+
)
44+
map(
45+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [obj, grad, hess, hess_residual]),
46+
map(x -> FeasibilityResidual(eval(Symbol(x))(), name = x * "feas"), setdiff(problems, ["MGH01"])),
47+
)
48+
# jtprod! https://github.com/JuliaSmoothOptimizers/NLPModelsModifiers.jl/issues/77
49+
map(
50+
nlp -> NLPModelsTest.test_zero_allocations(nlp, linear_api = true, exclude = [hess, jtprod, jac_op]),
51+
map(x -> FeasibilityFormNLS(eval(Symbol(x))()), problems),
52+
)
53+
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ include("nls/feasibility-form-nls.jl")
1010
include("nls/feasibility-residual.jl")
1111
include("nls/slack-model.jl")
1212

13+
using NLPModelsTest
14+
15+
if (v"1.7" <= VERSION)
16+
include("allocs_test.jl")
17+
end
18+
1319
# include("test_feasibility_form_nls.jl")
1420
# include("test_feasibility_nls_model.jl")
1521
# include("test_qn_model.jl")

0 commit comments

Comments
 (0)