From 3c75a4f9c062df9743bbb5a01fe98c798382cfac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 9 May 2024 20:19:53 +0200 Subject: [PATCH 1/4] Add any function for Bridges.runtest --- src/Bridges/Bridges.jl | 80 ++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index f1943a326c..3636443929 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -220,8 +220,8 @@ end """ runtests( Bridge::Type{<:AbstractBridge}, - input::String, - output::String; + input::Function, + output::Function; variable_start = 1.2, constraint_start = 1.2, eltype = Float64, @@ -229,30 +229,26 @@ end Run a series of tests that check the correctness of `Bridge`. -`input` and `output` are models in the style of -[`MOI.Utilities.loadfromstring!`](@ref). +`input` and `output` are functions such that `input(model)` and `output(model)` +loads the corresponding model into `model`. ## Example ```jldoctest; setup=:(import MathOptInterface as MOI) julia> MOI.Bridges.runtests( MOI.Bridges.Constraint.ZeroOneBridge, - \"\"\" - variables: x - x in ZeroOne() - \"\"\", - \"\"\" - variables: x - x in Integer() - 1.0 * x in Interval(0.0, 1.0) - \"\"\", + model -> MOI.add_constrained_variable(model, MOI.ZeroOne()), + model -> begin + x, _ = MOI.add_constrained_variable(model, MOI.Integer()) + MOI.add_constraint(model, 1.0 * x in MOI.Interval(0.0, 1.0)) + end, ) ``` """ function runtests( Bridge::Type{<:AbstractBridge}, - input::String, - output::String; + input::Function, + output::Function; variable_start = 1.2, constraint_start = 1.2, eltype = Float64, @@ -261,7 +257,7 @@ function runtests( # Load model and bridge it inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) model = _bridged_model(Bridge{eltype}, inner) - MOI.Utilities.loadfromstring!(model, input) + input(model) final_touch(model) # Should be able to call final_touch multiple times. final_touch(model) @@ -270,11 +266,11 @@ function runtests( end # Load a non-bridged input model, and check that getters are the same. test = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) - MOI.Utilities.loadfromstring!(test, input) + input(test) _test_structural_identical(test, model) # Load a bridged target model, and check that getters are the same. target = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) - MOI.Utilities.loadfromstring!(target, output) + output(target) _test_structural_identical(target, inner) # Test VariablePrimalStart attr = MOI.VariablePrimalStart() @@ -318,6 +314,54 @@ function runtests( return end + +""" + runtests( + Bridge::Type{<:AbstractBridge}, + input::String, + output::String; + variable_start = 1.2, + constraint_start = 1.2, + eltype = Float64, + ) + +Run a series of tests that check the correctness of `Bridge`. + +`input` and `output` are models in the style of +[`MOI.Utilities.loadfromstring!`](@ref). + +## Example + +```jldoctest; setup=:(import MathOptInterface as MOI) +julia> MOI.Bridges.runtests( + MOI.Bridges.Constraint.ZeroOneBridge, + \"\"\" + variables: x + x in ZeroOne() + \"\"\", + \"\"\" + variables: x + x in Integer() + 1.0 * x in Interval(0.0, 1.0) + \"\"\", + ) +``` +""" +function runtests( + Bridge::Type{<:AbstractBridge}, + input::String, + output::String; + kws..., +) + runtests( + Bridge, + model -> MOI.Utilities.loadfromstring!(model, input), + model -> MOI.Utilities.loadfromstring!(model, output); + kws..., + ) + return +end + _test_delete(::Type{<:Variable.AbstractBridge}, model, inner) = nothing function _test_delete(Bridge, model, inner) From bb88dac6a3ca55faa18b9e69a5172ab8670c9e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 9 May 2024 20:32:53 +0200 Subject: [PATCH 2/4] Fix format --- src/Bridges/Bridges.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 3636443929..d10720a963 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -314,7 +314,6 @@ function runtests( return end - """ runtests( Bridge::Type{<:AbstractBridge}, From 9c259a63072209952896cf4f37d79fb0ddc90032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 9 May 2024 20:33:40 +0200 Subject: [PATCH 3/4] Fix --- src/Bridges/Bridges.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index d10720a963..146a09c05a 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -240,7 +240,7 @@ julia> MOI.Bridges.runtests( model -> MOI.add_constrained_variable(model, MOI.ZeroOne()), model -> begin x, _ = MOI.add_constrained_variable(model, MOI.Integer()) - MOI.add_constraint(model, 1.0 * x in MOI.Interval(0.0, 1.0)) + MOI.add_constraint(model, 1.0 * x, MOI.Interval(0.0, 1.0)) end, ) ``` From 7bb5361131ba6f59a904afa2806994c526889800 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 10 May 2024 08:09:56 +1200 Subject: [PATCH 4/4] Update Bridges.jl --- src/Bridges/Bridges.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 146a09c05a..821e2f398a 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -220,8 +220,8 @@ end """ runtests( Bridge::Type{<:AbstractBridge}, - input::Function, - output::Function; + input_fn::Function, + output_fn::Function; variable_start = 1.2, constraint_start = 1.2, eltype = Float64, @@ -229,8 +229,8 @@ end Run a series of tests that check the correctness of `Bridge`. -`input` and `output` are functions such that `input(model)` and `output(model)` -loads the corresponding model into `model`. +`input_fn` and `output_fn` are functions such that `input_fn(model)` +and `output_fn(model)` load the corresponding model into `model`. ## Example @@ -247,8 +247,8 @@ julia> MOI.Bridges.runtests( """ function runtests( Bridge::Type{<:AbstractBridge}, - input::Function, - output::Function; + input_fn::Function, + output_fn::Function; variable_start = 1.2, constraint_start = 1.2, eltype = Float64, @@ -257,7 +257,7 @@ function runtests( # Load model and bridge it inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) model = _bridged_model(Bridge{eltype}, inner) - input(model) + input_fn(model) final_touch(model) # Should be able to call final_touch multiple times. final_touch(model) @@ -266,11 +266,11 @@ function runtests( end # Load a non-bridged input model, and check that getters are the same. test = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) - input(test) + input_fn(test) _test_structural_identical(test, model) # Load a bridged target model, and check that getters are the same. target = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{eltype}()) - output(target) + output_fn(target) _test_structural_identical(target, inner) # Test VariablePrimalStart attr = MOI.VariablePrimalStart() @@ -350,13 +350,13 @@ function runtests( Bridge::Type{<:AbstractBridge}, input::String, output::String; - kws..., + kwargs..., ) runtests( Bridge, model -> MOI.Utilities.loadfromstring!(model, input), model -> MOI.Utilities.loadfromstring!(model, output); - kws..., + kwargs..., ) return end