@@ -147,7 +147,7 @@ include("precompile.jl")
147
147
function _test_structural_identical (
148
148
a:: MOI.ModelLike ,
149
149
b:: MOI.ModelLike ;
150
- allow_constraint_function_error :: Bool = false ,
150
+ cannot_unbridge :: Bool = false ,
151
151
)
152
152
# Test that the variables are the same. We make the strong assumption that
153
153
# the variables are added in the same order to both models.
@@ -194,10 +194,10 @@ function _test_structural_identical(
194
194
Test. @test MOI. supports_constraint (b, F, S)
195
195
# Check that each function in `b` matches a function in `a`
196
196
for ci in MOI. get (b, MOI. ListOfConstraintIndices {F,S} ())
197
- try
198
- f_b = MOI. get (b, MOI. ConstraintFunction (), ci)
197
+ f_b = try
198
+ MOI. get (b, MOI. ConstraintFunction (), ci)
199
199
catch err
200
- if allow_constraint_function_error &&
200
+ if cannot_unbridge &&
201
201
err isa MOI. GetAttributeNotAllowed{MOI. ConstraintFunction}
202
202
continue
203
203
else
@@ -238,13 +238,18 @@ end
238
238
variable_start = 1.2,
239
239
constraint_start = 1.2,
240
240
eltype = Float64,
241
+ cannot_unbridge::Bool = false,
241
242
)
242
243
243
244
Run a series of tests that check the correctness of `Bridge`.
244
245
245
246
`input_fn` and `output_fn` are functions such that `input_fn(model)`
246
247
and `output_fn(model)` load the corresponding model into `model`.
247
248
249
+ Set `cannot_unbridge` to `true` if the bridge is a variable bridge
250
+ that does not supports [`Variables.unbridged_func`](@ref) so that
251
+ the tests allow errors that can be raised due to this.
252
+
248
253
## Example
249
254
250
255
```jldoctest; setup=:(import MathOptInterface as MOI)
@@ -266,7 +271,7 @@ function runtests(
266
271
constraint_start = 1.2 ,
267
272
eltype = Float64,
268
273
print_inner_model:: Bool = false ,
269
- allow_outer_constraint_function_error :: Bool = false ,
274
+ cannot_unbridge :: Bool = false ,
270
275
)
271
276
# Load model and bridge it
272
277
inner = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
@@ -284,7 +289,7 @@ function runtests(
284
289
_test_structural_identical (
285
290
test,
286
291
model;
287
- allow_constraint_function_error = allow_outer_constraint_function_error ,
292
+ cannot_unbridge = cannot_unbridge ,
288
293
)
289
294
# Load a bridged target model, and check that getters are the same.
290
295
target = MOI. Utilities. UniversalFallback (MOI. Utilities. Model {eltype} ())
@@ -309,7 +314,17 @@ function runtests(
309
314
# Test ConstraintPrimalStart and ConstraintDualStart
310
315
for (F, S) in MOI. get (model, MOI. ListOfConstraintTypesPresent ())
311
316
for ci in MOI. get (model, MOI. ListOfConstraintIndices {F,S} ())
312
- set = MOI. get (model, MOI. ConstraintSet (), ci)
317
+ set = try
318
+ MOI. get (model, MOI. ConstraintSet (), ci)
319
+ catch err
320
+ # Could be thrown by `unbridged_function`
321
+ if cannot_unbridge &&
322
+ err isa MOI. GetAttributeNotAllowed{MOI. ConstraintFunction}
323
+ continue
324
+ else
325
+ rethrow (err)
326
+ end
327
+ end
313
328
for attr in (MOI. ConstraintPrimalStart (), MOI. ConstraintDualStart ())
314
329
if MOI. supports (model, attr, MOI. ConstraintIndex{F,S})
315
330
MOI. set (model, attr, ci, nothing )
0 commit comments