Skip to content

Commit fc9cf88

Browse files
committed
fix type of MOI evaluator in MathOptNLPModel
1 parent 5abe6b5 commit fc9cf88

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/moi_nlp_model.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export MathOptNLPModel
22

33
mutable struct MathOptNLPModel <: AbstractNLPModel{Float64, Vector{Float64}}
44
meta::NLPModelMeta{Float64, Vector{Float64}}
5-
eval::MOI.Nonlinear.Evaluator
5+
eval::MOI.AbstractNLPEvaluator
66
lincon::LinearConstraints
77
quadcon::QuadraticConstraints
88
nlcon::NonLinearStructure
@@ -74,6 +74,7 @@ function nlp_model(moimodel::MOI.ModelLike; hessian::Bool = true, name::String =
7474
hess_available = hessian && oracles.hessian_oracles_supported,
7575
)
7676

77+
7778
return MathOptNLPModel(
7879
meta,
7980
nlp_data.evaluator,

src/utils.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,15 +600,28 @@ function parser_NL(nlp_data; hessian::Bool = true)
600600
nl_ucon = Float64[bounds.upper for bounds in nlp_data.constraint_bounds]
601601

602602
eval = nlp_data.evaluator
603-
MOI.initialize(eval, hessian ? [:Grad, :Jac, :JacVec, :Hess, :HessVec] : [:Grad, :Jac, :JacVec])
603+
has_hessian = hessian && :Hess in MOI.features_available(eval)
604+
# Check features available in model
605+
init_feat = [:Grad, :Jac]
606+
if has_hessian
607+
push!(init_feat, :Hess)
608+
end
609+
if :JacVec in MOI.features_available(eval)
610+
push!(init_feat, :JacVec)
611+
end
612+
if :HessVec in MOI.features_available(eval)
613+
push!(init_feat, :HessVec)
614+
end
615+
616+
MOI.initialize(eval, init_feat)
604617

605618
jac = MOI.jacobian_structure(eval)
606619
jac_rows, jac_cols = getindex.(jac, 1), getindex.(jac, 2)
607620
nnzj = length(jac)
608621

609-
hess = hessian ? MOI.hessian_lagrangian_structure(eval) : Tuple{Int, Int}[]
610-
hess_rows = hessian ? getindex.(hess, 1) : Int[]
611-
hess_cols = hessian ? getindex.(hess, 2) : Int[]
622+
hess = has_hessian ? MOI.hessian_lagrangian_structure(eval) : Tuple{Int, Int}[]
623+
hess_rows = has_hessian ? getindex.(hess, 1) : Int[]
624+
hess_cols = has_hessian ? getindex.(hess, 2) : Int[]
612625
nnzh = length(hess)
613626
nlcon =
614627
NonLinearStructure(nnln, nl_lcon, nl_ucon, jac_rows, jac_cols, nnzj, hess_rows, hess_cols, nnzh)

test/MOI_wrapper.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function test_runtests()
4040
r"test_nonlinear_without_objective$",
4141
r"test_nonlinear_hs071_NLPBlockDual$",
4242
r"test_nonlinear_hs071_no_hessian$",
43-
r"test_nonlinear_hs071_hessian_vector_product$",
4443
r"test_nonlinear_hs071$",
4544
# Require hessian = false in the constructor of MathOptNLPModel
4645
r"test_nonlinear_expression_multivariate_function$",
@@ -64,20 +63,7 @@ function test_runtests()
6463
r"test_modification_coef_scalaraffine_lessthan$",
6564
r"test_modification_const_scalar_objective$",
6665
r"test_modification_const_vectoraffine_nonpos$",
67-
r"test_conic_NormInfinityCone_3$",
68-
r"test_conic_NormInfinityCone_INFEASIBLE$",
69-
r"test_conic_NormInfinityCone_VectorAffineFunction$",
70-
r"test_conic_NormInfinityCone_VectorOfVariables$",
71-
r"test_conic_NormOneCone$",
72-
r"test_conic_NormOneCone_INFEASIBLE$",
73-
r"test_conic_NormOneCone_VectorAffineFunction$",
74-
r"test_conic_NormOneCone_VectorOfVariables$",
75-
r"test_conic_linear_INFEASIBLE$",
76-
r"test_conic_linear_INFEASIBLE_2$",
77-
r"test_conic_linear_VectorAffineFunction$",
78-
r"test_conic_linear_VectorAffineFunction_2$",
79-
r"test_conic_linear_VectorOfVariables$",
80-
r"test_conic_linear_VectorOfVariables_2$",
66+
r"test_conic*",
8167
r"test_constraint_ScalarAffineFunction_Interval$",
8268
r"test_constraint_ScalarAffineFunction_LessThan$",
8369
r"test_constraint_ScalarAffineFunction_duplicate$",

0 commit comments

Comments
 (0)