Skip to content

Commit

Permalink
Add a test for HSL solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 30, 2023
1 parent 53897bf commit cab4fb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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"]
20 changes: 19 additions & 1 deletion test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module TestMOIWrapper

using Ipopt
using Test
using HSL_jll

const MOI = Ipopt.MOI

Expand Down Expand Up @@ -491,7 +492,7 @@ 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 +507,23 @@ function test_SPRAL()
return
end

function test_HSL()
bool = @ccall libhsl.LIBHSL_isfunctional()::Bool
!bool && return
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 cab4fb4

Please sign in to comment.