Skip to content

Commit

Permalink
[Nonlinear] fix initialize for ExprGraphOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 4, 2024
1 parent 64f1bd8 commit 18c065b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Nonlinear/evaluator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 83 in src/Nonlinear/evaluator.jl

View check run for this annotation

Codecov / codecov/patch

src/Nonlinear/evaluator.jl#L81-L83

Added lines #L81 - L83 were not covered by tests
"Unable to initialize `Nonlinear.Evaluator` because the " *
"following features are not supported: $features",
)
end
return
end
Expand Down
16 changes: 16 additions & 0 deletions test/Nonlinear/Nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 18c065b

Please sign in to comment.