Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mock tests #372

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 7 additions & 41 deletions test/Mock/BPT12e399.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
config = MOI.Test.Config()
function optimize!_max_bridged(mock)
function optimize!_max(mock)
return MOI.Utilities.mock_optimize!(
mock,
[6.0, 9.0, 1.0, -3.0 * √2],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1 / 3, 1, 3]],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => [[3, 1 / 3, √2]],
)
end
function optimize!_min_bridged(mock)
function optimize!_min(mock)
return MOI.Utilities.mock_optimize!(
mock,
[-6.0, 9.0, 1.0, 3.0 * √2],
Expand All @@ -16,60 +16,26 @@ function optimize!_min_bridged(mock)
[[3, 1 / 3, -√2]],
)
end
function optimize!_max_cached(mock)
return MOI.Utilities.mock_optimize!(
mock,
[9.0, 1.0, -3.0 * √2, 6.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1 / 3, 1, 3]],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => [[1 / 3, 3, √2]],
)
end
function optimize!_min_cached(mock)
return MOI.Utilities.mock_optimize!(
mock,
[9.0, 1.0, 3.0 * √2, -6.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1 / 3, -1, 3]],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) =>
[[1 / 3, 3, -√2]],
)
end
for mock in [
bridged_mock(optimize!_max_bridged, optimize!_min_bridged),
cached_mock(optimize!_max_cached, optimize!_min_cached),
]
for mock in mocks(optimize!_max, optimize!_min)
Tests.BPT12e399_rem_test(mock, config)
end
function optimize!_max_bridged(mock)
function optimize!_max(mock)
return MOI.Utilities.mock_optimize!(
mock,
[10.0, 5.0, -5.0, 5.0, 0.0, 0.0, 4.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, 1, 0.0, 1, 0]],
)
end
function optimize!_min_bridged(mock)
function optimize!_min(mock)
return MOI.Utilities.mock_optimize!(
mock,
[-10.0, 5.0, 5.0, 5.0, 0.0, 0.0, 4.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, -1, 0.0, 1, 0]],
)
end
function optimize!_max_cached(mock)
return MOI.Utilities.mock_optimize!(
mock,
[5.0, -5.0, 5.0, 0.0, 0.0, 4.0, 10.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, 1, 0.0, 1, 0]],
)
end
function optimize!_min_cached(mock)
return MOI.Utilities.mock_optimize!(
mock,
[5.0, 5.0, 5.0, 0.0, 0.0, 4.0, -10.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, -1, 0.0, 1, 0]],
)
end
for mock in [
bridged_mock(optimize!_max_bridged, optimize!_min_bridged),
cached_mock(optimize!_max_cached, optimize!_min_cached),
bridged_mock(optimize!_max, optimize!_min),
cached_mock(optimize!_max, optimize!_min),
]
Tests.BPT12e399_maxdegree_test(mock, config)
end
2 changes: 1 addition & 1 deletion test/Mock/chebyshev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ function optimize!(mock)
[[128.0, 1.0, -0.0, -32.0, 0.0, 160.0, -0.0, -256.0, 0.0]; zeros(90)],
)
end
for mock in [bridged_mock(optimize!), cached_mock(optimize!)]
for mock in mocks(optimize!)
Tests.chebyshev_test(mock, config)
end
30 changes: 4 additions & 26 deletions test/Mock/concave_then_convex_cubic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ end
for mock in mocks(optimize!)
Tests.dsos_concave_then_convex_cubic_test(mock, config)
end
function optimize_bridged!(mock)
return MOI.Utilities.mock_optimize!(
mock,
vals,
(MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => zeros(4),
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [zeros(2), zeros(2)],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) =>
[zeros(3) for i in 1:8],
)
end
function optimize_cached!(mock)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
vals,
Expand All @@ -33,22 +23,10 @@ function optimize_cached!(mock)
[zeros(3) for i in 1:8],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in mocks(optimize!)
Tests.sdsos_concave_then_convex_cubic_test(mock, config)
end
function optimize_bridged!(mock)
return MOI.Utilities.mock_optimize!(
mock,
vals,
(MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => zeros(4),
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) =>
[zeros(6), zeros(6)],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [zeros(2), zeros(2)],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) =>
[zeros(3), zeros(3)],
)
end
function optimize_cached!(mock)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
vals,
Expand All @@ -60,6 +38,6 @@ function optimize_cached!(mock)
[zeros(3), zeros(3)],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in mocks(optimize!)
Tests.sos_concave_then_convex_cubic_test(mock, config)
end
30 changes: 15 additions & 15 deletions test/Mock/mock_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ using Test, JuMP
@testset "Term" begin
include("term.jl")
end
#@testset "Term fixed" begin
# include("term_fixed.jl")
#end
#@testset "Quartic constant" begin
# include("quartic_constant.jl")
#end
#@testset "Quadratic" begin
# include("quadratic.jl")
#end
@testset "Term fixed" begin
include("term_fixed.jl")
end
@testset "Quartic constant" begin
include("quartic_constant.jl")
end
@testset "Quadratic" begin
include("quadratic.jl")
end
@testset "Quartic ideal" begin
include("quartic_ideal.jl")
end
Expand Down Expand Up @@ -42,18 +42,18 @@ end
@testset "Motzkin" begin
include("motzkin.jl")
end
#@testset "BPT12e399" begin
# include("BPT12e399.jl")
#end
@testset "BPT12e399" begin
include("BPT12e399.jl")
end
@testset "Max Cut" begin
include("maxcut.jl")
end
@testset "Chebyshev" begin
include("chebyshev.jl")
end
#@testset "Quartic comparison" begin
# include("quartic_comparison.jl")
#end
@testset "Quartic comparison" begin
include("quartic_comparison.jl")
end
@testset "SOSDEMO5" begin
include("sosdemo5.jl")
end
Expand Down
83 changes: 62 additions & 21 deletions test/Mock/quadratic.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
config = MOI.Test.Config()
function optimize_bridged!(mock)
config = MOI.Test.Config(atol = 1e-6)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[2.0, 1.0, 1.0, √2],
Expand All @@ -8,40 +8,40 @@ function optimize_bridged!(mock)
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -1.0, 1.0]],
)
end
function optimize_cached!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[1.0, 1.0, √2, 2.0],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) =>
[[1.0, 1.0, -√2]],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -1.0, 1.0]],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in mocks(optimize!)
Tests.sos_univariate_quadratic_test(mock, config)
Tests.sos_bivariate_quadratic_test(mock, config)
Tests.sdsos_univariate_quadratic_test(mock, config)
Tests.sdsos_bivariate_quadratic_test(mock, config)
Tests.sos_scaled_univariate_quadratic_test(mock, config)
Tests.sos_scaled_bivariate_quadratic_test(mock, config)
Tests.sdsos_scaled_univariate_quadratic_test(mock, config)
Tests.sdsos_scaled_bivariate_quadratic_test(mock, config)
Tests.sos_cheby_univariate_quadratic_test(mock, config)
Tests.sdsos_cheby_univariate_quadratic_test(mock, config)
end
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[2.0, 1.0, 1.0, √2],
(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) =>
[[1.0, 1.0, -√2]],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -√2, 1.0]],
)
end
for mock in mocks(optimize!)
Tests.sos_scaled_bivariate_quadratic_test(mock, config)
Tests.sdsos_scaled_bivariate_quadratic_test(mock, config)
end
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[2.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0],
(
MOI.VectorOfVariables,
MOI.MathOptInterface.PositiveSemidefiniteConeTriangle,
) => [[0.0, 0.0, 1.0, 0.0, -1.0, 1.0]],
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) =>
[[0.0, 0.0, 1.0, 0.0, -1.0, 1.0]],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) =>
[[0.0, 0.0, 0.0, 2.0, -1.0, 2.0]],
)
end
for mock in [bridged_mock(optimize!), cached_mock(optimize!)]
for mock in mocks(optimize!)
Tests.sos_cheby_bivariate_quadratic_test(mock, config)
end
function optimize!(mock)
Expand All @@ -54,7 +54,7 @@ function optimize!(mock)
[[0.0, 0.0, 0.0, 2.0, -1.0, 2.0]],
)
end
for mock in [bridged_mock(optimize!), cached_mock(optimize!)]
for mock in mocks(optimize!)
Tests.sdsos_cheby_bivariate_quadratic_test(mock, config)
end
function optimize!(mock)
Expand All @@ -70,7 +70,48 @@ for mock in mocks(optimize!)
Tests.dsos_univariate_quadratic_test(mock, config)
Tests.dsos_bivariate_quadratic_test(mock, config)
Tests.dsos_scaled_univariate_quadratic_test(mock, config)
Tests.dsos_scaled_bivariate_quadratic_test(mock, config)
Tests.dsos_cheby_univariate_quadratic_test(mock, config)
end
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
(MOI.FEASIBLE_POINT, [2.0, 1.0, 1.0, 1.0, 1.0]),
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) =>
[0.0, 2.0, 1.0, 1.0],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -√2, 1.0]],
)
end
for mock in mocks(optimize!)
Tests.dsos_scaled_bivariate_quadratic_test(mock, config)
end
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
(
MOI.FEASIBLE_POINT,
[2.0, 0.0, 0.0, 1.0, -0.0, 1.0, 1.0, 0.0, 0.0, 1.0],
),
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => [
0.7624324421943409,
0.7624324421943427,
0.7624324421943439,
0.7624324421943471,
0.0,
2.0,
0.5248650317582692,
1.0,
1.0,
],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[
0.5248650317582707,
0.0,
0.0,
1.4751346735031994,
-1.0,
1.4751346735032143,
]],
)
end
for mock in mocks(optimize!)
Tests.dsos_cheby_bivariate_quadratic_test(mock, config)
end
20 changes: 4 additions & 16 deletions test/Mock/quartic_comparison.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
config = MOI.Test.Config()
# The test does not check the solution except the first variable so we just set zeros.
function optimize_bridged!(mock)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[-0.184667; zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1)],
)
end
function optimize_cached!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1); -0.184667],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in [bridged_mock(optimize!)]
Tests.sos_quartic_comparison_test(mock, config)
end
function optimize_bridged!(mock)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[-3.172412; zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1)],
)
end
function optimize_cached!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1); -3.172412],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in mocks(optimize!)
Tests.sdsos_quartic_comparison_test(mock, config)
end
function optimize!(mock)
Expand Down
5 changes: 2 additions & 3 deletions test/Mock/quartic_constant.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
config = MOI.Test.Config()
optimize_bridged!(mock) = MOI.Utilities.mock_optimize!(mock, [4.0, 1.0])
optimize_cached!(mock) = MOI.Utilities.mock_optimize!(mock, [1.0, 4.0])
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
optimize!(mock) = MOI.Utilities.mock_optimize!(mock, [4.0, 1.0])
for mock in mocks(optimize!)
Tests.dsos_quartic_constant_test(mock, config)
Tests.sdsos_quartic_constant_test(mock, config)
Tests.sos_quartic_constant_test(mock, config)
Expand Down
12 changes: 2 additions & 10 deletions test/Mock/term_fixed.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
config = MOI.Test.Config()
function optimize_bridged!(mock)
function optimize!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[1.0, 0.0],
(MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]],
)
end
function optimize_cached!(mock)
return MOI.Utilities.mock_optimize!(
mock,
[0.0, 1.0],
(MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]],
(MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]],
)
end
for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)]
for mock in mocks(optimize!)
Tests.sos_term_fixed_test(mock, config)
Tests.sdsos_term_fixed_test(mock, config)
Tests.dsos_term_fixed_test(mock, config)
Expand Down
Loading
Loading