Skip to content

Commit 084a899

Browse files
authored
[Nonlinear] fix initialize for ExprGraphOnly (#2387)
1 parent 64f1bd8 commit 084a899

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Nonlinear/evaluator.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ function MOI.initialize(evaluator::Evaluator, features::Vector{Symbol})
7474
evaluator.eval_hessian_constraint_timer = 0.0
7575
evaluator.eval_hessian_lagrangian_timer = 0.0
7676
append!(evaluator.ordered_constraints, keys(evaluator.model.constraints))
77+
# Every backend supports :ExprGraph, so don't forward it.
7778
filter!(f -> f != :ExprGraph, features)
7879
if evaluator.backend !== nothing
7980
MOI.initialize(evaluator.backend, features)
81+
elseif !isempty(features)
82+
@assert evaluator.backend === nothing # ==> ExprGraphOnly used
83+
error(
84+
"Unable to initialize `Nonlinear.Evaluator` because the " *
85+
"following features are not supported: $features",
86+
)
8087
end
8188
return
8289
end

test/Nonlinear/Nonlinear.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,24 @@ function test_is_empty()
11311131
return
11321132
end
11331133

1134+
function test_unsupported_features_expr_graph_only()
1135+
evaluator = Nonlinear.Evaluator(
1136+
Nonlinear.Model(),
1137+
Nonlinear.ExprGraphOnly(),
1138+
MOI.VariableIndex[],
1139+
)
1140+
@test_throws(
1141+
ErrorException(
1142+
"Unable to initialize `Nonlinear.Evaluator` because the " *
1143+
"following features are not supported: $([:Grad])",
1144+
),
1145+
MOI.initialize(evaluator, [:ExprGraph, :Grad]),
1146+
)
1147+
return
11341148
end
11351149

1150+
end # TestNonlinear
1151+
11361152
TestNonlinear.runtests()
11371153

11381154
include("ReverseAD.jl")

0 commit comments

Comments
 (0)