From 6e8dcc15c1e5e03e65597df7c6a80c223a7a746d Mon Sep 17 00:00:00 2001 From: joaquimg Date: Sun, 22 Feb 2026 16:21:36 -0300 Subject: [PATCH 1/2] Add missing cubic parametric cubic type --- src/MOI_wrapper.jl | 16 +++++++++++++++- test/test_cubic.jl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 0e605104..62c01735 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -1664,7 +1664,9 @@ queried using the [`ParametricObjectiveFunction{P}`](@ref) attribute. The type struct ParametricObjectiveType <: MOI.AbstractModelAttribute end function MOI.get(model::Optimizer{T}, ::ParametricObjectiveType) where {T} - if model.quadratic_objective_cache !== nothing + if model.cubic_objective_cache !== nothing + return ParametricCubicFunction{T} + elseif model.quadratic_objective_cache !== nothing return ParametricQuadraticFunction{T} elseif model.affine_objective_cache !== nothing return ParametricAffineFunction{T} @@ -1704,6 +1706,18 @@ function MOI.get( return model.affine_objective_cache end +function MOI.get( + model::Optimizer{T}, + ::ParametricObjectiveFunction{ParametricCubicFunction{T}}, +) where {T} + if model.cubic_objective_cache === nothing + error(" + There is no parametric cubic objective function in the model. + ") + end + return model.cubic_objective_cache +end + """ ListOfParametricConstraintTypesPresent() diff --git a/test/test_cubic.jl b/test/test_cubic.jl index 4da52914..44652b52 100644 --- a/test/test_cubic.jl +++ b/test/test_cubic.jl @@ -1623,6 +1623,36 @@ function test_jump_cubic_direct_model_ppp() return end +function test_parametric_objective_type_cubic() + model = Model(() -> POI.Optimizer(HiGHS.Optimizer())) + set_silent(model) + @variable(model, x) + @variable(model, p in MOI.Parameter(2.0)) + @variable(model, q in MOI.Parameter(3.0)) + @constraint(model, x >= 1) + @objective(model, Min, x + p * q^2) + optimize!(model) + inner = unsafe_backend(model) + @test MOI.get(inner, POI.ParametricObjectiveType()) == POI.ParametricCubicFunction{Float64} + pf = MOI.get(inner, POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}()) + @test pf isa POI.ParametricCubicFunction{Float64} + return +end + +function test_parametric_objective_type_cubic_error() + model = Model(() -> POI.Optimizer(HiGHS.Optimizer())) + set_silent(model) + @variable(model, x >= 1) + @objective(model, Min, x) + optimize!(model) + inner = unsafe_backend(model) + @test_throws ErrorException MOI.get( + inner, + POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}(), + ) + return +end + end # module TestCubic.runtests() From 0ecfcfb8ffa93509da461fd85f75644f9a4b7fed Mon Sep 17 00:00:00 2001 From: joaquimg Date: Sun, 22 Feb 2026 16:24:55 -0300 Subject: [PATCH 2/2] format --- test/test_cubic.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_cubic.jl b/test/test_cubic.jl index 44652b52..cc3eb9f8 100644 --- a/test/test_cubic.jl +++ b/test/test_cubic.jl @@ -1633,8 +1633,12 @@ function test_parametric_objective_type_cubic() @objective(model, Min, x + p * q^2) optimize!(model) inner = unsafe_backend(model) - @test MOI.get(inner, POI.ParametricObjectiveType()) == POI.ParametricCubicFunction{Float64} - pf = MOI.get(inner, POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}()) + @test MOI.get(inner, POI.ParametricObjectiveType()) == + POI.ParametricCubicFunction{Float64} + pf = MOI.get( + inner, + POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}(), + ) @test pf isa POI.ParametricCubicFunction{Float64} return end