Skip to content

Commit

Permalink
tests updated / ci added
Browse files Browse the repository at this point in the history
  • Loading branch information
sshin23 committed Jul 30, 2023
1 parent 3b55e9b commit 8ac306e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 44 deletions.
79 changes: 37 additions & 42 deletions test/NLPTest/NLPTest.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
module TestNLP
module NLPTest

using SIMDiff, Test, ADNLPModels, NLPModels, NLPModelsIpopt, KernelAbstractions, CUDA

const NLP_TEST_ARGUMENTS = [
(
"luksan_vlcek",
3
),
(
"luksan_vlcek",
20
),
]

const BACKENDS = Any[
nothing,
CPU()
]

if CUDA.has_cuda()
push!(BACKENDS, CUDABackend())
end

include("utils.jl")
include("luksan.jl")

function test_nlp(simdiff_model, adnlp_model, args)
function test_nlp(simdiff_model, adnlp_model, backend, args)

m1 = WrapperNLPModel(simdiff_model(args...))
m2 = WrapperNLPModel(adnlp_model(args...))
m1 = WrapperNLPModel(simdiff_model(backend,args...))
m2 = WrapperNLPModel(adnlp_model(backend,args...))

result1 = ipopt(m1; print_level = 0)
result2 = ipopt(m2; print_level = 0)
Expand All @@ -25,51 +45,26 @@ function test_nlp(simdiff_model, adnlp_model, args)
end
end

const NLP_TEST_ARGUMENTS = [
(
"luksan_vlcek",
(3, nothing)
),
(
"luksan_vlcek",
(20, nothing)
),
(
"luksan_vlcek",
(3, CPU())
),
(
"luksan_vlcek",
(20, CPU())
),
(
"luksan_vlcek",
(3, CUDABackend())
),
(
"luksan_vlcek",
(20, CUDABackend())
),
]
function runtests()
@testset "NLP tests" begin
for (name, args) in NLP_TEST_ARGUMENTS
simdiff_model = getfield(
@__MODULE__,
Symbol(name * "_simdiff_model")
)
adnlp_model = getfield(
@__MODULE__,
Symbol(name * "_adnlp_model")
)
for backend in BACKENDS
simdiff_model = getfield(
@__MODULE__,
Symbol(name * "_simdiff_model")
)
adnlp_model = getfield(
@__MODULE__,
Symbol(name * "_adnlp_model")
)

@testset "$name $args" begin
test_nlp(simdiff_model, adnlp_model, args)
@testset "$name $args $backend" begin
test_nlp(simdiff_model, adnlp_model, backend, args)
end
end
end
end
end

end # TestNLP
end # NLPTest

TestNLP.runtests()
4 changes: 2 additions & 2 deletions test/NLPTest/luksan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function luksan_vlcek_x0(i)
return mod(i,2)==1 ? -1.2 : 1.0
end

function luksan_vlcek_adnlp_model(N, backend)
function luksan_vlcek_adnlp_model(backend, N)
return ADNLPModel(
x->sum(luksan_vlcek_obj(x,i) for i=2:N),
[luksan_vlcek_x0(i) for i=1:N],
Expand All @@ -22,7 +22,7 @@ function luksan_vlcek_adnlp_model(N, backend)
)
end

function luksan_vlcek_simdiff_model(N, backend)
function luksan_vlcek_simdiff_model(backend, N)

c = SIMDiff.Core(backend)
x = SIMDiff.variable(
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Test, SIMDiff

include("NLPTest/NLPTest.jl")

NLPTest.runtests()

0 comments on commit 8ac306e

Please sign in to comment.