Skip to content

Commit b5bcb7b

Browse files
authored
Merge pull request #132 from JuliaOpt/bl/attr_functionize
Fix getting attributes with Functionize bridge
2 parents 328f30a + af38789 commit b5bcb7b

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1818
[compat]
1919
DynamicPolynomials = "≥ 0.1.3"
2020
JuMP = "0.20"
21-
MathOptInterface = "~0.9.2"
21+
MathOptInterface = "~0.9.7"
2222
MultivariateMoments = "≥ 0.2.1"
2323
MultivariatePolynomials = "~0.3"
2424
PolyJuMP = "0.3.3"

src/attributes.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ end
5757
# If a variable is bridged, the `VectorOfVariables`-in-`SOSPolynomialSet` is
5858
# bridged by `MOI.Bridges.Constraint.VectorFunctionizeBridge` and it has
5959
# to pass the constraint to the SOS bridge.
60-
function MOI.get(model::MOI.ModelLike,
61-
attr::Union{CertificateMonomials, GramMatrixAttribute,
62-
MomentMatrixAttribute, LagrangianMultipliers,
63-
PolyJuMP.MomentsAttribute},
64-
bridge::MOI.Bridges.Constraint.VectorFunctionizeBridge)
65-
return MOI.get(model, attr, bridge.constraint)
60+
function MOI.Bridges.Constraint.invariant_under_function_conversion(::Union{
61+
CertificateMonomials, GramMatrixAttribute,
62+
MomentMatrixAttribute, LagrangianMultipliers})
63+
return true
6664
end
6765

6866
# This is type piracy but we tolerate it.

test/Mock/term.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
config = MOI.Test.TestConfig()
2-
optimize!(mock) = MOIU.mock_optimize!(mock, [0.0, 0.0],
3-
(MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]],
4-
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]])
5-
for mock in mocks(optimize!)
6-
Tests.sos_term_test(mock, config)
7-
Tests.sdsos_term_test(mock, config)
8-
Tests.dsos_term_test(mock, config)
2+
3+
@testset "Model" begin
4+
optimize!(mock) = MOIU.mock_optimize!(mock, [0.0, 0.0],
5+
(MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]],
6+
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]])
7+
for mock in mocks(optimize!)
8+
Tests.sos_term_test(mock, config)
9+
Tests.sdsos_term_test(mock, config)
10+
Tests.dsos_term_test(mock, config)
11+
end
12+
end
13+
14+
# The VectorOfVariables-in-SOSPolynomialSet is bridged by VectorFunctionizeBridge
15+
# since the free variable is bridged. This tests that the GramMatrixAttribute, ...
16+
# are passed by the VectorFunctionizeBridge.
17+
@testset "NoFreeVariable" begin
18+
optimize!(mock) = MOIU.mock_optimize!(mock, [0.0, 0.0, 0.0],
19+
(MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]],
20+
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]])
21+
nofree_mock = bridged_mock(optimize!, model = NoFreeVariable{Float64}())
22+
for mock in mocks(optimize!)
23+
Tests.sos_term_test(nofree_mock, config)
24+
Tests.sdsos_term_test(nofree_mock, config)
25+
Tests.dsos_term_test(nofree_mock, config)
26+
end
927
end

test/Mock/utilities.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
using JuMP
22
const MOIT = MOI.Test
33

4+
MOIU.@model(NoFreeVariable,
5+
(), (MOI.EqualTo, MOI.LessThan, MOI.GreaterThan), (MOI.Nonnegatives, MOI.Nonpositives, MOI.Zeros, MOI.RotatedSecondOrderCone, MOI.PositiveSemidefiniteConeTriangle), (),
6+
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), (MOI.VectorAffineFunction,))
7+
# No free variables to make sure variable bridges are used to increase coverage
8+
MOI.supports_constraint(::NoFreeVariable, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Reals}) = false
9+
410
function bridged_mock(mock_optimize!::Function...;
511
model = MOI.Utilities.Model{Float64}())
612
mock = MOI.Utilities.MockOptimizer(model)

0 commit comments

Comments
 (0)