diff --git a/src/Nonlinear/evaluator.jl b/src/Nonlinear/evaluator.jl index c8cdc491cf..cf0e4a922f 100644 --- a/src/Nonlinear/evaluator.jl +++ b/src/Nonlinear/evaluator.jl @@ -74,9 +74,16 @@ function MOI.initialize(evaluator::Evaluator, features::Vector{Symbol}) evaluator.eval_hessian_constraint_timer = 0.0 evaluator.eval_hessian_lagrangian_timer = 0.0 append!(evaluator.ordered_constraints, keys(evaluator.model.constraints)) + # Every backend supports :ExprGraph, so don't forward it. filter!(f -> f != :ExprGraph, features) if evaluator.backend !== nothing MOI.initialize(evaluator.backend, features) + elseif !isempty(features) + @assert evaluator_backend === nothing # ==> ExprGraphOnly used + error( + "Unable to initialize `Nonlinear.Evaluator` because the " * + "following features are not supported: $features", + ) end return end diff --git a/test/Nonlinear/Nonlinear.jl b/test/Nonlinear/Nonlinear.jl index a5f2720817..9fcd1793aa 100644 --- a/test/Nonlinear/Nonlinear.jl +++ b/test/Nonlinear/Nonlinear.jl @@ -1131,8 +1131,24 @@ function test_is_empty() return end +function test_unsupported_features_expr_graph_only() + evaluator = Nonlinear.Evaluator( + Nonlinear.Model(), + Nonlinear.ExprGraphOnly(), + MOI.VariableIndex[], + ) + @test_throws( + ErrorException( + "Unable to initialize `Nonlinear.Evaluator` because the " * + "following features are not supported: $([:Grad])", + ), + MOI.initialize(evaluator, [:ExprGraph, :Grad]), + ) + return end +end # TestNonlinear + TestNonlinear.runtests() include("ReverseAD.jl")