From c94014ff69dc6fa097c22ab526ad41952c6c6214 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 19 Aug 2025 11:29:42 +1200 Subject: [PATCH] Fix MOI.supports for MOI.ConstraintName of quadratic constraints --- src/MOI_wrapper.jl | 13 +++++++++++++ test/moi_tests.jl | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 60406c10..e238d456 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -406,6 +406,19 @@ function MOI.supports( return MOI.supports(model.optimizer, attr, tp) end +function MOI.supports( + model::Optimizer, + attr::MOI.ConstraintName, + ::Type{MOI.ConstraintIndex{F,S}}, +) where {T,F<:MOI.ScalarQuadraticFunction{T},S} + G = MOI.ScalarAffineFunction{T} + # We can't tell at type-time whether the constraints will be quadratic or + # lowered to affine, so we return the conservative choice for supports of + # needing to support names for both quadratic and affine constraints. + return MOI.supports(model.optimizer, attr, MOI.ConstraintIndex{F,S}) && + MOI.supports(model.optimizer, attr, MOI.ConstraintIndex{G,S}) +end + function MOI.set( model::Optimizer, attr::MOI.ConstraintName, diff --git a/test/moi_tests.jl b/test/moi_tests.jl index dd967af0..7d8f9716 100644 --- a/test/moi_tests.jl +++ b/test/moi_tests.jl @@ -1982,3 +1982,26 @@ function test_no_quadratic_terms() @test MOI.get(optimizer, MOI.ConstraintDual(), c) ≈ -1 atol = ATOL return end + +MOI.Utilities.@model( + Model185, + (), + (MOI.EqualTo,), + (), + (), + (), + (MOI.ScalarAffineFunction,), + (), + () +); + +function test_issue_185() + inner = Model185{Float64}() + mock = MOI.Utilities.MockOptimizer(inner; supports_names = false) + model = POI.Optimizer(MOI.Bridges.full_bridge_optimizer(mock, Float64)) + for F in (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction) + C = MOI.ConstraintIndex{F{Float64},MOI.EqualTo{Float64}} + @test !MOI.supports(model, MOI.ConstraintName(), C) + end + return +end