Skip to content

Commit

Permalink
Merge pull request #128 from jump-dev/jg/moi1
Browse files Browse the repository at this point in the history
MOI 1.0 and JuMP 0.23
  • Loading branch information
joaquimg authored Mar 2, 2022
2 parents 5866bbf + 3c341b3 commit 5cd58bc
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- version: '1'
os: ubuntu-latest
arch: x64
- version: '1.0'
- version: '1.6'
os: ubuntu-latest
arch: x64
- version: '1.0'
- version: '1.6'
os: ubuntu-latest
arch: x86
steps:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ jobs:
- uses: julia-actions/setup-julia@latest
with:
# Build documentation on Julia 1.0
version: '1.0'
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
18 changes: 4 additions & 14 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
name = "Dualization"
uuid = "191a621a-6537-11e9-281d-650236a99e60"
authors = ["guilhermebodin <[email protected]>"]
version = "0.4.0"
version = "0.5.0"

[deps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
JuMP = "0.22"
MathOptInterface = "0.10"
julia = "1"

[extras]
CSDP = "0a46da34-8e4b-519e-b418-48813639ff34"
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "GLPK", "ECOS", "CSDP", "SCS"]
JuMP = "0.23"
MathOptInterface = "1"
julia = "1.6"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Dualization.jl has two main features.
dual_model = dualize(model)
```

* The `DualOptimizer` that will pass the dual representation of the model to the solver of your choice.
* The `DualOptimizer` that will pass the dual representation of the model to the `SOLVER` of your choice.

```julia
model = Model(dual_optimizer(SOLVER.Optimizer))
Expand Down
6 changes: 3 additions & 3 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ The user can define the model providing the `DualOptimizer` and the solver of it
Example:
```julia
julia> using Dualization, JuMP, GLPK
julia> using Dualization, JuMP, HiGHS
julia> model = Model(dual_optimizer(GLPK.Optimizer))
julia> model = Model(dual_optimizer(HiGHS.Optimizer))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Dual model with GLPK attached
Solver name: Dual model with HiGHS attached
```
"""
function DualOptimizer(dual_optimizer::OT) where {OT<:MOI.ModelLike}
Expand Down
12 changes: 12 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[deps]
CSDP = "0a46da34-8e4b-519e-b418-48813639ff34"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CSDP = "1.0.0"
HiGHS = "1.1.0"
SCS = "1.0.1"
28 changes: 0 additions & 28 deletions test/Solvers/ecos_test.jl

This file was deleted.

30 changes: 0 additions & 30 deletions test/Solvers/glpk_test.jl

This file was deleted.

35 changes: 35 additions & 0 deletions test/Solvers/highs_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HiGHS
const HiGHS_PRIMAL_FACTORY =
MOI.OptimizerWithAttributes(HiGHS.Optimizer, MOI.Silent() => true)
const HiGHS_DUAL_FACTORY = dual_optimizer(HiGHS_PRIMAL_FACTORY)
const HiGHS_PRIMAL_OPT = MOI.instantiate(HiGHS_PRIMAL_FACTORY)
const HiGHS_DUAL_OPT = MOI.instantiate(HiGHS_DUAL_FACTORY)

push!(primal_linear_factory, HiGHS_PRIMAL_FACTORY)
push!(dual_linear_factory, HiGHS_DUAL_FACTORY)
push!(dual_linear_optimizer, HiGHS_DUAL_OPT)
push!(primal_linear_optimizer, HiGHS_PRIMAL_OPT)

@testset "HiGHS Linear Problems" begin
list_of_linear_problems = [
lp1_test,
lp2_test,
lp3_test,
lp4_test,
lp5_test,
lp6_test,
lp7_test,
# lp8_test, Int64 problem, does not work
# lp9_test, Interval is not implemented
lp10_test,
# lp11_test, Feasibility not supported
lp12_test,
lp13_test,
]
test_strong_duality(list_of_linear_problems, HiGHS_PRIMAL_FACTORY)
end

@testset "HiGHS Quadratic Problems" begin
list_of_quad_problems = [qp1_test, qp2_test]
test_strong_duality(list_of_quad_problems, HiGHS_PRIMAL_FACTORY)
end
37 changes: 36 additions & 1 deletion test/Solvers/scs_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,42 @@ push!(dual_power_cone_factory, SCS_DUAL_FACTORY)
push!(dual_power_cone_optimizer, SCS_DUAL_OPT)
push!(primal_power_cone_optimizer, SCS_PRIMAL_OPT)

@testset "SCS Exponential Cone Problems" begin
@testset "SCS Exponential Cone problems" begin
list_of_exp_problems = [exp1_test, exp2_test]
test_strong_duality(list_of_exp_problems, SCS_PRIMAL_FACTORY)
end

@testset "SCS SOC problems" begin
list_of_soc_problems = [soc3_test, soc4_test, soc5_test, soc6_test]
test_strong_duality(list_of_soc_problems, SCS_PRIMAL_FACTORY)
list_of_soc_problems = [soc1_test, soc2_test]
test_strong_duality(
list_of_soc_problems,
SCS_PRIMAL_FACTORY,
atol = 1e-3,
rtol = 1e-3,
)
end

@testset "SCS RotatedSOC problems" begin
list_of_rsoc_problems = [rsoc1_test, rsoc2_test, rsoc3_test]
test_strong_duality(list_of_rsoc_problems, SCS_PRIMAL_FACTORY)
list_of_rsoc_problems = [rsoc4_test]
test_strong_duality(
list_of_rsoc_problems,
SCS_PRIMAL_FACTORY,
atol = 1e-3,
rtol = 1e-3,
)
end

@testset "SCS SDP triangle problems" begin
list_of_sdp_triang_problems =
[sdpt1_test, sdpt2_test, sdpt3_test, sdpt4_test]
test_strong_duality(list_of_sdp_triang_problems, SCS_PRIMAL_FACTORY)
end

@testset "SCS Power Cone problems" begin
list_of_pow_problems = [pow1_test, pow2_test]
test_strong_duality(list_of_pow_problems, SCS_PRIMAL_FACTORY)
end
2 changes: 1 addition & 1 deletion test/Tests/test_JuMP_dualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
dual_JuMP_model = dualize(JuMP_model, primal_linear_factory[i])
@test backend(dual_JuMP_model).state == MOIU.EMPTY_OPTIMIZER
@test MOI.get(backend(dual_JuMP_model), MOI.SolverName()) ==
MOI.get(primal_linear_optimizer[i], MOI.SolverName())#"GLPK"
MOI.get(primal_linear_optimizer[i], MOI.SolverName())
end
end
@testset "set_dot on different sets" begin
Expand Down
3 changes: 1 addition & 2 deletions test/Tests/test_dualize_linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@
@test obj_type == SAF{Float64}
obj = MOI.get(dual_model, MOI.ObjectiveFunction{obj_type}())
@test MOI.constant(obj) == -1.0
@test MOI.coefficient.(obj.terms) ==
(Sys.WORD_SIZE == 32 ? [1.0, 3.0, 3.0] : [3.0; 1.0; 3.0])
@test Set(MOI.coefficient.(obj.terms)) == Set([3.0; 1.0; 3.0])
end

@testset "lp10_test" begin
Expand Down
4 changes: 2 additions & 2 deletions test/Tests/test_modify.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "modify" begin
model = Model(GLPK_DUAL_FACTORY)
model = Model(HiGHS_DUAL_FACTORY)
@variable(model, x[1:2] >= 0)
@constraint(model, 2x[1] + x[2] <= 4)
@constraint(model, x[1] + 2x[2] <= 4)
Expand All @@ -10,7 +10,7 @@
optimize!(model)
@test objective_value(model) 10.6666666666

model = Model(GLPK_DUAL_FACTORY)
model = Model(HiGHS_DUAL_FACTORY)
@variable(model, x[1:2] >= 0)
@constraint(model, 2x[1] + x[2] <= 4)
@constraint(model, x[1] + 2x[2] <= 4)
Expand Down
10 changes: 8 additions & 2 deletions test/optimize_abstract_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function solve_abstract_model(
set_optimizer(JuMP_model, optimizer_constructor)
optimize!(JuMP_model)
termination_status = JuMP.termination_status(JuMP_model)
obj_val = JuMP.objective_value(JuMP_model)
obj_val = try
JuMP.objective_value(JuMP_model)
catch
NaN
end
return termination_status, obj_val
end

Expand Down Expand Up @@ -45,11 +49,13 @@ function test_strong_duality(
(dual_term_status == MOI.DUAL_INFEASIBLE)
return true
end
@show primal_term_status, primal_obj_val
@show dual_term_status, dual_obj_val
return false # In case strong duality doesn't hold
end

function test_strong_duality(
primal_problems::Array{Function},
primal_problems::Vector,
optimizer_constructor;
atol = 1e-6,
rtol = 1e-4,
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ primal_power_cone_optimizer = []

# Load & Test strong duality in linear/conic problems
# Comment the solver that are not available for development
include("Solvers/glpk_test.jl")
include("Solvers/ecos_test.jl")
include("Solvers/highs_test.jl")
include("Solvers/csdp_test.jl")
include("Solvers/scs_test.jl")

Expand Down

2 comments on commit 5cd58bc

@joaquimg
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/55833

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 5cd58bc03081a3232ca234119fa5553cff3e8a85
git push origin v0.5.0

Please sign in to comment.