Skip to content

Commit

Permalink
Fix NLPBlockDualStart and tidy MOI tests (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 6, 2023
1 parent 149c8b6 commit 33db39c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
9 changes: 6 additions & 3 deletions src/MOI_wrapper/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ end

MOI.supports(::Optimizer, ::MOI.NLPBlockDualStart) = true

# TODO: FIXME
function MOI.set(model::Optimizer, ::MOI.NLPBlockDualStart, values)
# @assert length(values) == length(model.nlp_index_cons)
KN_set_con_dual_init_values(model.inner, Cint[0], values)
KN_set_con_dual_init_values(
model.inner,
length(model.nlp_index_cons),
model.nlp_index_cons,
values,
)
return
end
53 changes: 20 additions & 33 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
module TestMOIWrapper

using Test
using KNITRO

const MOI = KNITRO.MOI
import KNITRO
import MathOptInterface as MOI

function runtests()
for name in names(@__MODULE__; all=true)
Expand Down Expand Up @@ -38,25 +38,22 @@ function test_MOI_Test_cached()
"test_conic_SecondOrderCone_out_of_order",
"test_constraint_PrimalStart_DualStart_SecondOrderCone",
]
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
MOI.instantiate(KNITRO.Optimizer; with_bridge_type=Float64),
)
model =
MOI.instantiate(KNITRO.Optimizer; with_bridge_type=Float64, with_cache_type=Float64)
MOI.set(model, MOI.Silent(), true)
config = MOI.Test.Config(
atol=1e-3,
rtol=1e-3,
optimal_status=MOI.LOCALLY_SOLVED,
infeasible_status=MOI.LOCALLY_INFEASIBLE,
exclude=Any[MOI.VariableBasisStatus, MOI.ConstraintBasisStatus],
)
MOI.Test.runtests(
model,
MOI.Test.Config(
atol=1e-4,
rtol=1e-4,
optimal_status=MOI.LOCALLY_SOLVED,
infeasible_status=MOI.LOCALLY_INFEASIBLE,
exclude=Any[
MOI.ConstraintBasisStatus,
MOI.VariableBasisStatus,
MOI.DualObjectiveValue,
],
);
config;
exclude=String[
# TODO(odow): this test is flakey.
"test_cpsat_ReifiedAllDifferent",
# Returns OTHER_ERROR, which is also reasonable.
"test_conic_empty_matrix",
# Uses the ZerosBridge and ConstraintDual
Expand All @@ -67,25 +64,15 @@ function test_MOI_Test_cached()
"test_solve_ObjectiveBound_MAX_SENSE_LP",
# KNITRO doesn't support INFEASIBILITY_CERTIFICATE results.
"test_solve_DualStatus_INFEASIBILITY_CERTIFICATE_",
# ConstraintDual not supported for SecondOrderCone
second_order_exclude...,
],
)
MOI.Test.runtests(
model,
MOI.Test.Config(
atol=1e-3,
rtol=1e-3,
optimal_status=MOI.LOCALLY_SOLVED,
infeasible_status=MOI.LOCALLY_INFEASIBLE,
exclude=Any[
MOI.ConstraintBasisStatus,
MOI.VariableBasisStatus,
MOI.DualObjectiveValue,
MOI.ConstraintDual,
],
);
include=second_order_exclude,
)
# Run the tests for second_order_exclude, this time excluding
# `MOI.ConstraintDual` and `MOI.DualObjectiveValue`.
push!(config.exclude, MOI.ConstraintDual)
push!(config.exclude, MOI.DualObjectiveValue)
MOI.Test.runtests(model, config; include=second_order_exclude)
return
end

Expand Down

0 comments on commit 33db39c

Please sign in to comment.