From db09805150bde77a497f1964d633fb99a54b36df Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 16 Aug 2025 13:38:28 -0400 Subject: [PATCH 1/6] fix VariablePrimalStart --- test/jump_tests.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 807ca42a..17a59cfa 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -427,10 +427,10 @@ function test_jump_set_variable_start_value() @variable(model, p in MOI.Parameter(0.0)) set_start_value(x, 1.0) @test start_value(x) == 1 - err = ErrorException( - "MathOptInterface.VariablePrimalStart() is not supported for parameters", - ) - @test_throws err set_start_value(p, 1.0) + @test_throws ErrorException( + "The parameter $(index(p)) value is 0.0, but trying to set VariablePrimalStart 1.0", + ) set_start_value(p, 1.0) + err = ErrorException("MathOptInterface.VariablePrimalStart() is not supported for parameters") @test_throws err start_value(p) return end From 61bee1ca7a7e9a89c3e26e4e2c868d483d216ca7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 17 Aug 2025 18:17:57 -0400 Subject: [PATCH 2/6] add get VariablePrimalStart --- src/MOI_wrapper.jl | 16 ++++++++++++++++ test/jump_tests.jl | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index b5302628..f98c98ba 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -323,6 +323,22 @@ function MOI.supports( return MOI.supports(model.optimizer, attr, tp) end +function MOI.get( + model::Optimizer, + attr::MOI.VariablePrimalStart, + v::MOI.VariableIndex, +) + if _variable_in_model(model, v) + return MOI.get(model.optimizer, attr, v) + elseif _parameter_in_model(model, v) + # this is effectivelly a no-op, but we do validation + _val = model.parameters[p_idx(v)] + return _val + else + error("Variable not in the model") + end +end + function MOI.set( model::Optimizer, attr::MOI.VariablePrimalStart, diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 17a59cfa..9859c9dc 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -430,8 +430,7 @@ function test_jump_set_variable_start_value() @test_throws ErrorException( "The parameter $(index(p)) value is 0.0, but trying to set VariablePrimalStart 1.0", ) set_start_value(p, 1.0) - err = ErrorException("MathOptInterface.VariablePrimalStart() is not supported for parameters") - @test_throws err start_value(p) + @test start_value(p) == 0.0 return end From c53dbee0f2fde6765b76ecd22d5de6ad404b4807 Mon Sep 17 00:00:00 2001 From: joaquimg Date: Sun, 17 Aug 2025 22:45:09 -0300 Subject: [PATCH 3/6] fix "is_valid" --- src/MOI_wrapper.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index f98c98ba..b1786063 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -439,7 +439,18 @@ end function MOI.is_valid( model::Optimizer, c::MOI.ConstraintIndex{F,S}, -) where {F<:MOI.ScalarAffineFunction,S<:MOI.AbstractSet} +) where { + F<:Union{ + MOI.ScalarAffineFunction, + MOI.ScalarQuadraticFunction, + MOI.VectorAffineFunction, + MOI.VectorQuadraticFunction, + }, + S<:MOI.AbstractSet, +} + if haskey(model.constraint_outer_to_inner, c) + return true + end return MOI.is_valid(model.optimizer, c) end From ad1a9f2a6cf1f3f522d896acfee63aecebe0f77f Mon Sep 17 00:00:00 2001 From: joaquimg Date: Sun, 17 Aug 2025 22:59:51 -0300 Subject: [PATCH 4/6] fix ambiguity --- src/MOI_wrapper.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index b1786063..404a8a9b 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -430,7 +430,7 @@ function MOI.is_valid( model::Optimizer, c::MOI.ConstraintIndex{F,S}, ) where { - F<:Union{MOI.VariableIndex,MOI.VectorOfVariables,MOI.VectorAffineFunction}, + F<:Union{MOI.VariableIndex,MOI.VectorOfVariables}, S<:MOI.AbstractSet, } return MOI.is_valid(model.optimizer, c) From 1ed7d79238514d947d3fbee2f03435b448844c72 Mon Sep 17 00:00:00 2001 From: joaquimg Date: Mon, 18 Aug 2025 00:59:33 -0300 Subject: [PATCH 5/6] format --- src/MOI_wrapper.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 404a8a9b..a3c8aa63 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -429,10 +429,7 @@ end function MOI.is_valid( model::Optimizer, c::MOI.ConstraintIndex{F,S}, -) where { - F<:Union{MOI.VariableIndex,MOI.VectorOfVariables}, - S<:MOI.AbstractSet, -} +) where {F<:Union{MOI.VariableIndex,MOI.VectorOfVariables},S<:MOI.AbstractSet} return MOI.is_valid(model.optimizer, c) end From 962103053b7c07ef3b352d29807ca2ab87e0ae53 Mon Sep 17 00:00:00 2001 From: joaquimg Date: Mon, 18 Aug 2025 02:14:08 -0300 Subject: [PATCH 6/6] add more vector tests --- test/jump_tests.jl | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/jump_tests.jl b/test/jump_tests.jl index 9859c9dc..7a370a2a 100644 --- a/test/jump_tests.jl +++ b/test/jump_tests.jl @@ -1274,14 +1274,51 @@ function test_parameter_Cannot_be_inf_2() return end -function test_jump_psd_cone_with_parameter() +function test_jump_psd_cone_with_parameter_pv() model = Model(SCS.Optimizer) @variable(model, x) @variable(model, p in MOI.Parameter(1.0)) - @constraint(model, [[0 (p * x + -1)]; [(p * x + -1) 0]] in JuMP.PSDCone()) + @constraint( + model, + con, + [[0 (p * x - 1)]; [(p * x - 1) 0]] in JuMP.PSDCone() + ) + # the above constraint is equivalent to + # - (p * x -1)^2 >=0 -> (p * x -1)^2 <= 0 -> (p * x -1) == 0 -> p*x == 1 + @test is_valid(model, con) optimize!(model) @test value(x) ≈ 1.0 atol = 1e-5 set_parameter_value(p, 3.0) optimize!(model) @test value(x) ≈ 1 / 3 atol = 1e-5 end + +function test_jump_psd_cone_with_parameter_pp() + model = Model(SCS.Optimizer) + @variable(model, x) + @variable(model, p in MOI.Parameter(1.0)) + @constraint( + model, + con, + [[0 (x - p * p)]; [(x - p * p) 0]] in JuMP.PSDCone() + ) + @test is_valid(model, con) + optimize!(model) + @test value(x) ≈ 1.0 atol = 1e-5 + set_parameter_value(p, 3.0) + optimize!(model) + @test value(x) ≈ 9.0 atol = 1e-5 +end + +function test_jump_psd_cone_with_parameter_p() + model = Model(SCS.Optimizer) + @variable(model, x) + @variable(model, p in MOI.Parameter(1.0)) + @constraint(model, con, [[0 (x - p)]; [(x - p) 0]] in JuMP.PSDCone()) + @test is_valid(model, con) + optimize!(model) + @test value(x) ≈ 1.0 atol = 1e-5 + set_parameter_value(p, 3.0) + optimize!(model) + @test value(x) ≈ 3.0 atol = 1e-5 +end