From 18c065b4233bb79cd54909bcbc0163be91152254 Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 4 Jan 2024 13:23:04 +1300 Subject: [PATCH 1/2] [Nonlinear] fix initialize for ExprGraphOnly --- src/Nonlinear/evaluator.jl | 7 +++++++ test/Nonlinear/Nonlinear.jl | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) 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") From 612877a7661af00a1e7ef5b96b04174307732612 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Thu, 4 Jan 2024 13:31:23 +1300 Subject: [PATCH 2/2] Update src/Nonlinear/evaluator.jl --- src/Nonlinear/evaluator.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nonlinear/evaluator.jl b/src/Nonlinear/evaluator.jl index cf0e4a922f..a7c022b9fa 100644 --- a/src/Nonlinear/evaluator.jl +++ b/src/Nonlinear/evaluator.jl @@ -79,7 +79,7 @@ function MOI.initialize(evaluator::Evaluator, features::Vector{Symbol}) if evaluator.backend !== nothing MOI.initialize(evaluator.backend, features) elseif !isempty(features) - @assert evaluator_backend === nothing # ==> ExprGraphOnly used + @assert evaluator.backend === nothing # ==> ExprGraphOnly used error( "Unable to initialize `Nonlinear.Evaluator` because the " * "following features are not supported: $features",