Skip to content

Commit d12a510

Browse files
authored
Merge pull request #1032 from JuliaOpt/bl/test_template
Update test template with instantiate
2 parents 56fa57e + 2eb0d31 commit d12a510

2 files changed

Lines changed: 23 additions & 26 deletions

File tree

docs/src/apimanual.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,66 +1310,63 @@ const MOIU = MOI.Utilities
13101310
const MOIB = MOI.Bridges
13111311

13121312
import FooBar
1313-
const optimizer = FooBar.Optimizer()
1314-
MOI.set(optimizer, MOI.Silent(), true)
1313+
const OPTIMIZER_CONSTRUCTOR = MOI.OptimizerWithAttributes(FooBar.Optimizer, MOI.Silent() => true)
1314+
const OPTIMIZER = MOI.instantiate(OPTIMIZER_CONSTRUCTOR)
13151315

13161316
@testset "SolverName" begin
1317-
@test MOI.get(optimizer, MOI.SolverName()) == "FooBar"
1317+
@test MOI.get(OPTIMIZER, MOI.SolverName()) == "FooBar"
13181318
end
13191319

13201320
@testset "supports_default_copy_to" begin
1321-
@test MOIU.supports_default_copy_to(optimizer, false)
1321+
@test MOIU.supports_default_copy_to(OPTIMIZER, false)
13221322
# Use `@test !...` if names are not supported
1323-
@test MOIU.supports_default_copy_to(optimizer, true)
1323+
@test MOIU.supports_default_copy_to(OPTIMIZER, true)
13241324
end
13251325

1326-
const bridged = MOIB.full_bridge_optimizer(optimizer, Float64)
1327-
const config = MOIT.TestConfig(atol=1e-6, rtol=1e-6)
1326+
const BRIDGED = MOI.instantiate(OPTIMIZER_CONSTRUCTOR, with_bridge_type = Float64)
1327+
const CONFIG = MOIT.TestConfig(atol=1e-6, rtol=1e-6)
13281328

13291329
@testset "Unit" begin
1330-
MOIT.unittest(bridged, config)
1330+
MOIT.unittest(BRIDGED, CONFIG)
13311331
end
13321332

13331333
@testset "Modification" begin
1334-
MOIT.modificationtest(bridged, config)
1334+
MOIT.modificationtest(BRIDGED, CONFIG)
13351335
end
13361336

13371337
@testset "Continuous Linear" begin
1338-
MOIT.contlineartest(bridged, config)
1338+
MOIT.contlineartest(BRIDGED, CONFIG)
13391339
end
13401340

13411341
@testset "Continuous Conic" begin
1342-
MOIT.contlineartest(bridged, config)
1342+
MOIT.contlineartest(BRIDGED, CONFIG)
13431343
end
13441344

13451345
@testset "Integer Conic" begin
1346-
MOIT.intconictest(bridged, config)
1346+
MOIT.intconictest(BRIDGED, CONFIG)
13471347
end
13481348
```
1349-
The optimizer `bridged` constructed with [`Bridges.full_bridge_optimizer`](@ref)
1350-
automatically bridges constraints that are not supported by `optimizer`
1349+
The optimizer `BRIDGED` constructed with [`instantiate`](@ref)
1350+
automatically bridges constraints that are not supported by `OPTIMIZER`
13511351
using the bridges listed in [Bridges](@ref). It is recommended for an
13521352
implementation of MOI to only support constraints that are natively supported
13531353
by the solver and let bridges transform the constraint to the appropriate form.
1354-
For this reason it is expected that tests may not pass if `optimizer` is used
1355-
instead of `bridged`.
1354+
For this reason it is expected that tests may not pass if `OPTIMIZER` is used
1355+
instead of `BRIDGED`.
13561356

13571357
To test that a specific problem can be solved without bridges, a specific test can
1358-
be run with `optimizer` instead of `bridged`. For instance
1358+
be run with `OPTIMIZER` instead of `BRIDGED`. For instance
13591359
```julia
13601360
@testset "Interval constraints" begin
1361-
MOIT.linear10test(optimizer, config)
1361+
MOIT.linear10test(OPTIMIZER, CONFIG)
13621362
end
13631363
```
1364-
checks that `optimizer` implements support for
1364+
checks that `OPTIMIZER` implements support for
13651365
[`ScalarAffineFunction`](@ref)-in-[`Interval`](@ref).
13661366

1367-
If the wrapper does not support building the model incrementally (i.e. with `add_variable` and `add_constraint`), then `supports_default_copy_to` can be replaced by `supports_allocate_load` if appropriate (see [Implementing copy](@ref)) and the line `const bridged = ...` can be replaced with
1368-
```julia
1369-
const cache = MOIU.UniversalFallback(MOIU.Model{Float64}())
1370-
const cached = MOIU.CachingOptimizer(cache, optimizer)
1371-
const bridged = MOIB.full_bridge_optimizer(cached, Float64)
1372-
```
1367+
If the wrapper does not support building the model incrementally (i.e. with `add_variable` and `add_constraint`),
1368+
then `supports_default_copy_to` can be replaced by `supports_allocate_load` if
1369+
appropriate (see [Implementing copy](@ref)).
13731370

13741371
### Benchmarking
13751372

src/instantiate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ problem incrementally or does not support names and `with_names` is `true` (see
9999
[`Utilities.supports_default_copy_to`](@ref)) then a
100100
[`Utilities.CachingOptimizer`](@ref) is added to store a cache of the bridged
101101
model.
102-
Hence set `with_names` to `true` if names might be set.
102+
Hence set `with_names` to `true` if names might be set.
103103
"""
104104
function instantiate(
105105
optimizer_constructor; with_bridge_type::Union{Nothing, Type}=nothing,

0 commit comments

Comments
 (0)