Skip to content

Commit f4ff437

Browse files
apply test solver function for R2N
1 parent 33d0800 commit f4ff437

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const global λ = norm(grad(bpdn, zeros(bpdn.meta.nvar)), Inf) / 10
2222
include("utils.jl")
2323
include("test-solver.jl")
2424

25+
include("test-R2N.jl")
2526
include("test_AL.jl")
2627

2728
for (mod, mod_name) ((x -> x, "exact"), (LSR1Model, "lsr1"), (LBFGSModel, "lbfgs"))

test/test-R2N.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@testset "R2N" begin
2+
# BASIC TESTS
3+
# Test basic NLP with 2-norm
4+
@testset "BASIC" begin
5+
rosenbrock_nlp = construct_rosenbrock_nlp()
6+
rosenbrock_reg_nlp = RegularizedNLPModel(rosenbrock_nlp, NormL2(0.01))
7+
8+
# Test first order status
9+
first_order_kwargs = (atol = 1e-6, rtol = 1e-6)
10+
test_solver(rosenbrock_reg_nlp,
11+
"R2N",
12+
expected_status = :first_order,
13+
solver_kwargs=first_order_kwargs)
14+
solver, stats = R2NSolver(rosenbrock_reg_nlp), RegularizedExecutionStats(rosenbrock_reg_nlp)
15+
16+
# Test max time status
17+
max_time_kwargs = (x0 = [π, -π], atol = 1e-16, rtol = 1e-16, max_time = 1e-12)
18+
test_solver(rosenbrock_reg_nlp,
19+
"R2N",
20+
expected_status = :max_time,
21+
solver_kwargs=max_time_kwargs)
22+
23+
# Test max iter status
24+
max_iter_kwargs = (x0 = [π, -π], atol = 1e-16, rtol = 1e-16, max_iter = 1)
25+
test_solver(rosenbrock_reg_nlp,
26+
"R2N",
27+
expected_status = :max_iter,
28+
solver_kwargs=max_iter_kwargs)
29+
30+
# Test max eval status
31+
max_eval_kwargs = (x0 = [π, -π], atol = 1e-16, rtol = 1e-16, max_eval = 1)
32+
test_solver(rosenbrock_reg_nlp,
33+
"R2N",
34+
expected_status = :max_eval,
35+
solver_kwargs=max_eval_kwargs)
36+
37+
end
38+
# BPDN TESTS
39+
40+
# Test bpdn with L-BFGS and 1-norm
41+
@testset "BPDN" begin
42+
bpdn_kwargs = (x0 = zeros(bpdn.meta.nvar),σk = 1.0, β = 1e16, atol = 1e-6, rtol = 1e-6)
43+
reg_nlp = RegularizedNLPModel(LBFGSModel(bpdn), NormL1(λ))
44+
test_solver(reg_nlp,
45+
"R2N",
46+
expected_status = :first_order,
47+
solver_kwargs=bpdn_kwargs)
48+
solver, stats = R2NSolver(reg_nlp), RegularizedExecutionStats(reg_nlp)
49+
@test @wrappedallocs(solve!(solver, reg_nlp, stats, σk = 1.0, β = 1e16, atol = 1e-6, rtol = 1e-6)) == 0
50+
51+
#test_solver(reg_nlp, # FIXME
52+
# "R2N",
53+
# expected_status = :first_order,
54+
# solver_kwargs=bpdn_kwargs,
55+
# solver_constructor_kwargs=(subsolver=R2DHSolver,))
56+
57+
# Test bpdn with L-SR1 and 0-norm
58+
reg_nlp = RegularizedNLPModel(LSR1Model(bpdn), NormL0(λ))
59+
test_solver(reg_nlp,
60+
"R2N",
61+
expected_status = :first_order,
62+
solver_kwargs=bpdn_kwargs)
63+
solver, stats = R2NSolver(reg_nlp), RegularizedExecutionStats(reg_nlp)
64+
@test @wrappedallocs(solve!(solver, reg_nlp, stats, σk = 1.0, β = 1e16, atol = 1e-6, rtol = 1e-6)) == 0
65+
66+
test_solver(reg_nlp,
67+
"R2N",
68+
expected_status = :first_order,
69+
solver_kwargs=bpdn_kwargs,
70+
solver_constructor_kwargs=(subsolver=R2DHSolver,))
71+
solver, stats = R2NSolver(reg_nlp, subsolver = R2DHSolver), RegularizedExecutionStats(reg_nlp)
72+
@test @wrappedallocs(solve!(solver, reg_nlp, stats, σk = 1.0, β = 1e16, atol = 1e-6, rtol = 1e-6)) == 0
73+
end
74+
end

0 commit comments

Comments
 (0)