From 3a7f89189d8e2b6b2e6514b18618245975cd2366 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Sun, 7 Jan 2024 21:37:36 +1300 Subject: [PATCH] Fix map_indices for AbstractAutomaticDifferentiation (#2394) --- src/Nonlinear/types.jl | 7 +++++++ test/Nonlinear/Nonlinear.jl | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Nonlinear/types.jl b/src/Nonlinear/types.jl index ca91a9caeb..2afc67a931 100644 --- a/src/Nonlinear/types.jl +++ b/src/Nonlinear/types.jl @@ -184,6 +184,13 @@ An abstract type for extending [`Evaluator`](@ref). """ abstract type AbstractAutomaticDifferentiation end +function MOI.Utilities.map_indices( + ::F, + backend::AbstractAutomaticDifferentiation, +) where {F<:Function} + return backend +end + """ Evaluator( model::Model, diff --git a/test/Nonlinear/Nonlinear.jl b/test/Nonlinear/Nonlinear.jl index 9fcd1793aa..16b320538c 100644 --- a/test/Nonlinear/Nonlinear.jl +++ b/test/Nonlinear/Nonlinear.jl @@ -1147,6 +1147,22 @@ function test_unsupported_features_expr_graph_only() return end +function test_automatic_differentiation_backend() + inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + model = MOI.Utilities.CachingOptimizer( + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), + MOI.Utilities.MockOptimizer(inner), + ) + MOI.set( + model, + MOI.AutomaticDifferentiationBackend(), + MOI.Nonlinear.ExprGraphOnly(), + ) + @test MOI.get(inner, MOI.AutomaticDifferentiationBackend()) == + MOI.Nonlinear.ExprGraphOnly() + return +end + end # TestNonlinear TestNonlinear.runtests()