Skip to content

Commit 10f7ed1

Browse files
committed
Add Variable bridges to use runtests without unbridged_variable
1 parent 5a2a107 commit 10f7ed1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Bridges/Bridges.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ MOI.get_fallback(model::MOI.ModelLike, ::ListOfNonstandardBridges) = Type[]
144144

145145
include("precompile.jl")
146146

147-
function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike)
147+
function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike; allow_constraint_function_error::Bool = false)
148148
# Test that the variables are the same. We make the strong assumption that
149149
# the variables are added in the same order to both models.
150150
a_x = MOI.get(a, MOI.ListOfVariableIndices())
@@ -190,7 +190,15 @@ function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike)
190190
Test.@test MOI.supports_constraint(b, F, S)
191191
# Check that each function in `b` matches a function in `a`
192192
for ci in MOI.get(b, MOI.ListOfConstraintIndices{F,S}())
193-
f_b = MOI.get(b, MOI.ConstraintFunction(), ci)
193+
try
194+
f_b = MOI.get(b, MOI.ConstraintFunction(), ci)
195+
catch err
196+
if allow_constraint_function_error && err isa MOI.GetAttributeNotAllowed{MOI.ConstraintFunction}
197+
continue
198+
else
199+
rethrow(err)
200+
end
201+
end
194202
f_b = MOI.Utilities.map_indices(x_map, f_b)
195203
s_b = MOI.get(b, MOI.ConstraintSet(), ci)
196204
# We don't care about the order that constraints are added, only
@@ -253,6 +261,7 @@ function runtests(
253261
constraint_start = 1.2,
254262
eltype = Float64,
255263
print_inner_model::Bool = false,
264+
allow_outer_constraint_function_error::Bool = false,
256265
)
257266
# Load model and bridge it
258267
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
@@ -267,7 +276,7 @@ function runtests(
267276
# Load a non-bridged input model, and check that getters are the same.
268277
test = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
269278
input_fn(test)
270-
_test_structural_identical(test, model)
279+
_test_structural_identical(test, model; allow_constraint_function_error = allow_outer_constraint_function_error)
271280
# Load a bridged target model, and check that getters are the same.
272281
target = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
273282
output_fn(target)

0 commit comments

Comments
 (0)