Skip to content

Commit dcd07ca

Browse files
committed
Update
1 parent 2cfe536 commit dcd07ca

10 files changed

Lines changed: 188 additions & 127 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ permissions:
1717
contents: read
1818
jobs:
1919
test:
20-
name: Julia ${{ matrix.machine.version }} - ${{ matrix.machine.os }}-${{ matrix.machine.arch }}
20+
name: Julia ${{ matrix.machine.version }} - ${{ matrix.machine.os }}-${{ matrix.machine.arch }} - ${{ matrix.moi_test_modules }}
2121
runs-on: ${{ matrix.machine.os }}
2222
strategy:
2323
fail-fast: false
2424
matrix:
25+
moi_test_modules:
26+
- 'General;Benchmarks;FileFormats;Nonlinear'
27+
- 'Bridges/General'
28+
- 'Bridges/Constraint;Bridges/Objective;Bridges/Variable'
29+
- 'Test'
30+
- 'Utilities'
2531
machine:
2632
- version: 'nightly'
2733
os: ubuntu-latest
@@ -61,7 +67,7 @@ jobs:
6167
allow_reresolve: ${{ !matrix.machine.downgrade }}
6268
force_latest_compatible_version: ${{ !matrix.machine.downgrade }}
6369
env:
64-
JULIA_CPU_THREADS: 8
70+
MOI_TEST_MODULES: ${{ matrix.moi_test_modules }}
6571
- uses: julia-actions/julia-processcoverage@v1
6672
- uses: codecov/codecov-action@v4
6773
with:

test/Bridges/test_bridge_optimizer.jl renamed to test/Bridges/General/test_bridge_optimizer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function runtests()
2121
return
2222
end
2323

24-
include("utilities.jl")
24+
include("../utilities.jl")
2525

2626
struct DummyModelAttribute <: MOI.AbstractModelAttribute end
2727

test/Bridges/test_lazy_bridge_optimizer.jl renamed to test/Bridges/General/test_lazy_bridge_optimizer.jl

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,117 @@ function runtests()
2121
return
2222
end
2323

24-
include("utilities.jl")
25-
include("sdpa_models.jl")
24+
include("../utilities.jl")
25+
26+
# This block implements models similar to the SDPA format. It gives a good
27+
# example because it does not support a lot of functions, hence the need for
28+
# a lot of bridges.
29+
30+
MOI.Utilities.@model(
31+
StandardSDPAModel,
32+
(),
33+
(MOI.EqualTo,),
34+
(MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
35+
(),
36+
(),
37+
(MOI.ScalarAffineFunction,),
38+
(MOI.VectorOfVariables,),
39+
()
40+
)
41+
42+
function MOI.supports_constraint(
43+
::StandardSDPAModel{T},
44+
::Type{MOI.VariableIndex},
45+
::Type{
46+
<:Union{
47+
MOI.GreaterThan{T},
48+
MOI.LessThan{T},
49+
MOI.EqualTo{T},
50+
MOI.Interval{T},
51+
MOI.ZeroOne,
52+
MOI.Integer,
53+
},
54+
},
55+
) where {T}
56+
return false
57+
end
58+
59+
function MOI.supports_constraint(
60+
::StandardSDPAModel{T},
61+
::Type{MOI.VectorOfVariables},
62+
::Type{MOI.Reals},
63+
) where {T}
64+
return false
65+
end
66+
67+
function MOI.supports_add_constrained_variables(
68+
::StandardSDPAModel,
69+
::Type{<:Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle}},
70+
)
71+
return true
72+
end
73+
74+
function MOI.supports_add_constrained_variables(
75+
::StandardSDPAModel,
76+
::Type{MOI.Reals},
77+
)
78+
return false
79+
end
80+
81+
function MOI.supports(
82+
::StandardSDPAModel{T},
83+
::MOI.ObjectiveFunction{
84+
<:Union{
85+
MOI.VariableIndex,
86+
MOI.ScalarQuadraticFunction{T},
87+
MOI.ScalarNonlinearFunction,
88+
MOI.VectorOfVariables,
89+
MOI.VectorAffineFunction{T},
90+
MOI.VectorQuadraticFunction{T},
91+
MOI.VectorNonlinearFunction,
92+
},
93+
},
94+
) where {T}
95+
return false
96+
end
97+
98+
MOI.Utilities.@model(
99+
GeometricSDPAModel,
100+
(),
101+
(),
102+
(MOI.Zeros, MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
103+
(),
104+
(),
105+
(),
106+
(),
107+
(MOI.VectorAffineFunction,)
108+
)
109+
110+
function MOI.supports_constraint(
111+
::GeometricSDPAModel{T},
112+
::Type{MOI.VariableIndex},
113+
::Type{
114+
<:Union{
115+
MOI.GreaterThan{T},
116+
MOI.LessThan{T},
117+
MOI.EqualTo{T},
118+
MOI.Interval{T},
119+
MOI.ZeroOne,
120+
MOI.Integer,
121+
},
122+
},
123+
) where {T}
124+
return false
125+
end
126+
127+
function MOI.supports(
128+
::GeometricSDPAModel{T},
129+
::MOI.ObjectiveFunction{
130+
<:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}},
131+
},
132+
) where {T}
133+
return false
134+
end
26135

27136
function test_add_remove_has_bridges()
28137
T = Int

test/Bridges/sdpa_models.jl

Lines changed: 0 additions & 115 deletions
This file was deleted.

test/General/test_errors.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ function runtests()
2121
end
2222
end
2323

24+
function test_method_ambiguities()
25+
@test isempty(Test.detect_ambiguities(MOI; recursive = true))
26+
return
27+
end
28+
2429
function test_errors_fallback_AddVariableNotAllowed()
2530
model = DummyModel()
2631
@test_throws MOI.AddVariableNotAllowed MOI.add_variable(model)

test/runtests.jl

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,73 @@
44
# Use of this source code is governed by an MIT-style license that can be found
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

7+
# To try and speed up the tests, MOI uses a `MOI_TEST_MODULES` environment
8+
# variable. This environment variable may be missing, or it may be a subset of
9+
# the following, concatenated with `;` as a separator:
10+
#
11+
# * General
12+
# * Benchmarks
13+
# * Bridges/General
14+
# * Bridges/Constraint
15+
# * Bridges/Objective
16+
# * Bridges/Variable
17+
# * FileFormats
18+
# * Nonlinear
19+
# * Test
20+
# * Utilities
21+
#
22+
# If present, the tests run only those submodules defined above. `General` is
23+
# not a submodule, but it runs all of the top-level tests in MOI.
24+
725
# This file gets called first. If it doesn't crash, all is well.
826
include("issue980.jl")
927

10-
# Test hygiene of @model macro before calling `import MathOptInterface`
11-
include("hygiene.jl")
28+
MODULES_TO_TEST = get(
29+
ENV,
30+
"MOI_TEST_MODULES",
31+
"General;Benchmarks;Bridges/General;Bridges/Constraint;Bridges/Objective;Bridges/Variable;FileFormats;Nonlinear;Test;Utilities",
32+
)
33+
34+
"""
35+
include_with_method_redefinition_check(jl_filename)
36+
37+
This function runs `include(jl_filename)` with an additional check that there
38+
are no `WARNING: Method definition foo in module Foo overwritten` warnings.
39+
40+
It does this by piping `stderr` to a file, and then parsing the file.
41+
42+
One consequence is that `stderr` is not printed until the _end_ of this
43+
function. Thus, some warnings may appear in the wrong place.
44+
45+
This function requires Julia to be started with `--warn-overwrite=true`.
46+
"""
47+
const init_code = quote
48+
function include_with_method_redefinition_check(jl_filename)
49+
stderr_filename = tempname()
50+
open(stderr_filename, "w") do io
51+
return redirect_stderr(() -> include(jl_filename), io)
52+
end
53+
contents = read(stderr_filename, String)
54+
print(stderr, contents)
55+
regex =
56+
r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n"
57+
if match(regex, contents) !== nothing
58+
error("Found overwritten method in $jl_filename")
59+
end
60+
return
61+
end
62+
end
1263

1364
import MathOptInterface
1465
import ParallelTestRunner
1566

16-
testsuite = ParallelTestRunner.find_tests(@__DIR__)
17-
filter!(testsuite) do (k, v)
18-
return startswith(last(splitpath(k)), "test_")
19-
end
20-
ParallelTestRunner.runtests(MathOptInterface, ARGS; testsuite)
67+
is_test_file(f) = startswith(f, "test_") && endswith(f, ".jl")
68+
69+
testsuite = Dict{String,Expr}(
70+
file => :(include_with_method_redefinition_check($file)) for
71+
submodule in split(MODULES_TO_TEST, ";") for
72+
(root, dirs, files) in walkdir(submodule) for
73+
file in joinpath.(root, filter(is_test_file, files))
74+
)
75+
76+
ParallelTestRunner.runtests(MathOptInterface, ARGS; testsuite, init_code)

0 commit comments

Comments
 (0)