Skip to content

Commit

Permalink
Add Variable bridges to use runtests without unbridged_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 10, 2024
1 parent 5c9d6fb commit be2b6ac
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ MOI.get_fallback(model::MOI.ModelLike, ::ListOfNonstandardBridges) = Type[]

include("precompile.jl")

function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike)
function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike; allow_constraint_function_error::Bool = false)
# Test that the variables are the same. We make the strong assumption that
# the variables are added in the same order to both models.
a_x = MOI.get(a, MOI.ListOfVariableIndices())
Expand Down Expand Up @@ -190,7 +190,15 @@ function _test_structural_identical(a::MOI.ModelLike, b::MOI.ModelLike)
Test.@test MOI.supports_constraint(b, F, S)
# Check that each function in `b` matches a function in `a`
for ci in MOI.get(b, MOI.ListOfConstraintIndices{F,S}())
f_b = MOI.get(b, MOI.ConstraintFunction(), ci)
try
f_b = MOI.get(b, MOI.ConstraintFunction(), ci)
catch err
if allow_constraint_function_error && err isa MOI.GetAttributeNotAllowed{MOI.ConstraintFunction}
continue

Check warning on line 197 in src/Bridges/Bridges.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Bridges.jl#L196-L197

Added lines #L196 - L197 were not covered by tests
else
rethrow(err)

Check warning on line 199 in src/Bridges/Bridges.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Bridges.jl#L199

Added line #L199 was not covered by tests
end
end
f_b = MOI.Utilities.map_indices(x_map, f_b)
s_b = MOI.get(b, MOI.ConstraintSet(), ci)
# We don't care about the order that constraints are added, only
Expand Down Expand Up @@ -253,6 +261,7 @@ function runtests(
constraint_start = 1.2,
eltype = Float64,
print_inner_model::Bool = false,
allow_outer_constraint_function_error::Bool = false,
)
# Load model and bridge it
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
Expand All @@ -267,7 +276,7 @@ function runtests(
# Load a non-bridged input model, and check that getters are the same.
test = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
input_fn(test)
_test_structural_identical(test, model)
_test_structural_identical(test, model; allow_constraint_function_error = allow_outer_constraint_function_error)
# Load a bridged target model, and check that getters are the same.
target = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}())
output_fn(target)
Expand Down

0 comments on commit be2b6ac

Please sign in to comment.