Skip to content

Commit

Permalink
Add a test for HSL solvers (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored Dec 3, 2023
1 parent 53897bf commit 04178d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
HSL_jll = "2, 2023"
Ipopt_jll = "=300.1400.400, =300.1400.1303"
MathOptInterface = "1.17"
OpenBLAS32_jll = "0.3.10"
Expand All @@ -19,6 +20,7 @@ julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
HSL_jll = "017b0a0e-03f4-516a-9b91-836bbd1904dd"

[targets]
test = ["Test"]
test = ["Test", "HSL_jll"]
26 changes: 24 additions & 2 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

module TestMOIWrapper

using Ipopt
using Test

import HSL_jll
import Ipopt

const MOI = Ipopt.MOI

function runtests()
Expand Down Expand Up @@ -491,7 +493,9 @@ function test_ListOfSupportedNonlinearOperators()
end

function test_SPRAL()
if VERSION < v"1.9" || !haskey(ENV, "OMP_CANCELLATION")
if VERSION < v"1.9" ||
!haskey(ENV, "OMP_CANCELLATION") ||
!haskey(ENV, "OMP_PROC_BIND")
return
end
model = Ipopt.Optimizer()
Expand All @@ -506,6 +510,24 @@ function test_SPRAL()
return
end

function test_HSL()
if !(@ccall HSL_jll.libhsl.LIBHSL_isfunctional()::Bool)
return
end
for hsl_solver in ("ma27", "ma57", "ma77", "ma86", "ma97")
model = Ipopt.Optimizer()
MOI.set(model, MOI.RawOptimizerAttribute("linear_solver"), hsl_solver)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variable(model)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
f = 1.0 * x * x - 4.0 * x + 4.0
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model)
@test (MOI.get(model, MOI.VariablePrimal(), x), 2.0; atol = 1e-6)
end
return
end

end # module TestMOIWrapper

TestMOIWrapper.runtests()

0 comments on commit 04178d8

Please sign in to comment.