Skip to content

Commit d77b744

Browse files
authored
Update to MOI v0.10 (#7)
* Update to MOI v0.10 * Add GH actions * Remove travis * IndexInVector moved * TestConfig -> Config
1 parent 46f7966 commit d77b744

File tree

9 files changed

+108
-37
lines changed

9 files changed

+108
-37
lines changed

.github/workflows/CompatHelper.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CompatHelper
2+
3+
on:
4+
schedule:
5+
- cron: '00 00 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
CompatHelper:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
julia-version: [1.2.0]
14+
julia-arch: [x86]
15+
os: [ubuntu-latest]
16+
steps:
17+
- name: Pkg.add("CompatHelper")
18+
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
19+
- name: CompatHelper.main()
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: julia -e 'using CompatHelper; CompatHelper.main()'

.github/workflows/TagBot.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: TagBot
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
jobs:
8+
TagBot:
9+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: JuliaRegistries/TagBot@v1
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
ssh: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/ci.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
jobs:
8+
test:
9+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- version: '1.0'
16+
os: ubuntu-latest
17+
arch: x64
18+
- version: '1'
19+
os: ubuntu-latest
20+
arch: x64
21+
- version: '1'
22+
os: ubuntu-latest
23+
arch: x86
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: julia-actions/setup-julia@v1
27+
with:
28+
version: ${{ matrix.version }}
29+
arch: ${{ matrix.arch }}
30+
- uses: actions/cache@v1
31+
env:
32+
cache-name: cache-artifacts
33+
with:
34+
path: ~/.julia/artifacts
35+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
36+
restore-keys: |
37+
${{ runner.os }}-test-${{ env.cache-name }}-
38+
${{ runner.os }}-test-
39+
${{ runner.os }}-
40+
- uses: julia-actions/julia-buildpkg@v1
41+
- uses: julia-actions/julia-runtest@v1
42+
with:
43+
depwarn: error
44+
- uses: julia-actions/julia-processcoverage@v1
45+
- uses: codecov/codecov-action@v1
46+
with:
47+
file: lcov.info

.travis.yml

-9
This file was deleted.

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
99
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
1010

1111
[compat]
12-
MathOptInterface = "0.9.18"
13-
MutableArithmetics = "0.2.10"
12+
MathOptInterface = "0.10"
13+
MutableArithmetics = "0.3"
1414
julia = "1"
1515

1616
[extras]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There are two types of complex sets:
1616
For instance, `[x y+zim; y-zim w]` is vectorized as
1717
`[x, y, w, z]`.
1818

19-
Sets with complex entries **should not** be used with `Single` or `VectorOfVariables` constraints
19+
Sets with complex entries **should not** be used with `VariableIndex` or `VectorOfVariables` constraints
2020
as the variables in MathOptInterface are assumed to be real.
2121
Indeed, for instance doing
2222
```julia
@@ -25,7 +25,7 @@ x, cx = MOI.add_constrained_variable(model, MOI.EqualTo(1 + 2im))
2525
fallbacks to
2626
```julia
2727
x = MOI.add_variable(model)
28-
cx = MOI.add_constraint(model, MOI.SingleVariable(x), MOI.EqualTo(1 + 2im))
28+
cx = MOI.add_constraint(model, x, MOI.EqualTo(1 + 2im))
2929
```
3030
In the first line, the solvers create a real variable.
3131
Moreover, in the bridge from `MOI.ScalarAffineFunction{Complex{T}}`-in-`EqualTo{Complex{T}}`

src/Bridges/Variable/psd.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ function MOIB.Variable.bridge_constrained_variable(
5454
k12 = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(n))
5555
k21 = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(2n)) + 1
5656
k22 = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(n))
57-
X11() = MOI.SingleVariable(variables[k11])
58-
X12() = MOI.SingleVariable(variables[k12])
57+
X11() = variables[k11]
58+
X12() = variables[k12]
5959
function X21(i, j)
6060
I = j
6161
J = n + i
6262
k21 = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(J - 1)) + I
63-
return MOI.SingleVariable(variables[k21])
63+
return variables[k21]
6464
end
65-
X22() = MOI.SingleVariable(variables[k22])
65+
X22() = variables[k22]
6666
con_11_22 = EQ{T}[]
6767
con12diag = EQ{T}[]
6868
con_12_21 = EQ{T}[]
@@ -159,7 +159,7 @@ function _matrix_indices(k)
159159
return i, j
160160
end
161161

162-
function _variable_map(idx::MOIB.Variable.IndexInVector, n)
162+
function _variable_map(idx::MOIB.IndexInVector, n)
163163
N = MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(n))
164164
if idx.value <= N
165165
return idx.value
@@ -168,7 +168,7 @@ function _variable_map(idx::MOIB.Variable.IndexInVector, n)
168168
return N + j * n + MOI.dimension(MOI.PositiveSemidefiniteConeTriangle(j)) + i
169169
end
170170
end
171-
function _variable(bridge::HermitianToSymmetricPSDBridge, i::MOIB.Variable.IndexInVector)
171+
function _variable(bridge::HermitianToSymmetricPSDBridge, i::MOIB.IndexInVector)
172172
return bridge.variables[_variable_map(i, length(bridge.con12diag))]
173173
end
174174

@@ -177,7 +177,7 @@ function MOI.get(model::MOI.ModelLike, attr::MOI.ConstraintPrimal,
177177
values = MOI.get(model, attr, bridge.psd_constraint)
178178
M = MOI.dimension(MOI.get(model, MOI.ConstraintSet(), bridge))
179179
n = length(bridge.con12diag)
180-
return [values[_variable_map(MOIB.Variable.IndexInVector(i), n)] for i in 1:M]
180+
return [values[_variable_map(MOIB.IndexInVector(i), n)] for i in 1:M]
181181
end
182182

183183
# See docstring of bridge for why we ignore the dual of the constraints
@@ -217,16 +217,16 @@ function MOI.get(model::MOI.ModelLike, attr::MOI.ConstraintDual,
217217
end
218218

219219
function MOI.get(model::MOI.ModelLike, attr::MOI.VariablePrimal,
220-
bridge::HermitianToSymmetricPSDBridge{T}, i::MOIB.Variable.IndexInVector) where T
220+
bridge::HermitianToSymmetricPSDBridge{T}, i::MOIB.IndexInVector) where T
221221
value = MOI.get(model, attr, _variable(bridge, i))
222222
end
223223

224-
function MOIB.bridged_function(bridge::HermitianToSymmetricPSDBridge{T}, i::MOIB.Variable.IndexInVector) where T
225-
func = MOI.SingleVariable(_variable(bridge, i))
224+
function MOIB.bridged_function(bridge::HermitianToSymmetricPSDBridge{T}, i::MOIB.IndexInVector) where T
225+
func = _variable(bridge, i)
226226
return convert(MOI.ScalarAffineFunction{T}, func)
227227
end
228228
function MOIB.Variable.unbridged_map(bridge::HermitianToSymmetricPSDBridge{T}, vi::MOI.VariableIndex,
229-
i::MOIB.Variable.IndexInVector) where T
230-
func = convert(MOI.ScalarAffineFunction{T}, MOI.SingleVariable(vi))
229+
i::MOIB.IndexInVector) where T
230+
func = convert(MOI.ScalarAffineFunction{T}, vi)
231231
return (_variable(bridge, i) => func,)
232232
end

src/ComplexOptInterface.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function MOI.Utilities.set_dot(x::AbstractVector, y::AbstractVector,
1919
sym = MOI.PositiveSemidefiniteConeTriangle(set.side_dimension)
2020
result = MOI.Utilities.set_dot(x, y, sym)
2121
for k in (MOI.dimension(sym) + 1):MOI.dimension(set)
22-
result = MA.add_mul!(result, 2, x[k], y[k])
22+
result = MA.add_mul!!(result, 2, x[k], y[k])
2323
end
2424
return result
2525
end

test/runtests.jl

+7-11
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ function projection_test(optimizer, config)
3131
MOI.empty!(optimizer)
3232
set = COI.HermitianPositiveSemidefiniteConeTriangle(2)
3333
x, cx = MOI.add_constrained_variables(optimizer, set)
34-
fx = MOI.SingleVariable.(x)
35-
x11 = fx[1:3]
36-
x12 = fx[4]
34+
x11 = x[1:3]
35+
x12 = x[4]
3736
t = MOI.add_variable(optimizer)
3837
ft = MOI.SingleVariable(t)
39-
MOI.add_constraint(optimizer, MOI.Utilities.operate(vcat, Float64, ft, fx[1] - 1.0, 2 * (fx[2] + 1.0), fx[3] + 1.0, 2 * (fx[4] - 1.0)),
38+
MOI.add_constraint(optimizer, MOI.Utilities.operate(vcat, Float64, ft, x[1] - 1.0, 2 * (x[2] + 1.0), x[3] + 1.0, 2 * (x[4] - 1.0)),
4039
MOI.SecondOrderCone(5))
4140
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MIN_SENSE)
4241
MOI.set(optimizer, MOI.ObjectiveFunction{typeof(ft)}(), ft)
@@ -56,8 +55,7 @@ function hermitian_psd_test(optimizer, config)
5655
MOI.empty!(optimizer)
5756
set = COI.HermitianPositiveSemidefiniteConeTriangle(3)
5857
x, cx = MOI.add_constrained_variables(optimizer, set)
59-
fx = MOI.SingleVariable.(x)
60-
MOI.add_constraints(optimizer, fx, MOI.EqualTo.([1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0]))
58+
MOI.add_constraints(optimizer, x, MOI.EqualTo.([1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0]))
6159
MOI.optimize!(optimizer)
6260
primal = [1.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0]
6361
@test MOI.get(optimizer, MOI.VariablePrimal(), x) primal atol=atol rtol=rtol
@@ -71,8 +69,7 @@ function zero_1_test(optimizer, config)
7169

7270
MOI.empty!(optimizer)
7371
x, cx = MOI.add_constrained_variables(optimizer, MOI.Nonnegatives(2))
74-
fx = MOI.SingleVariable.(x)
75-
func = (1.0 + 2.0im) * fx[1] + (1.0 - 1.0im) * fx[2] + (-1.0 + -1.0im)
72+
func = (1.0 + 2.0im) * x[1] + (1.0 - 1.0im) * x[2] + (-1.0 + -1.0im)
7673
c = MOI.add_constraint(
7774
optimizer,
7875
MOI.Utilities.operate(vcat, Complex{Float64}, func),
@@ -93,8 +90,7 @@ function zero_2_test(optimizer, config)
9390

9491
MOI.empty!(optimizer)
9592
x, cx = MOI.add_constrained_variables(optimizer, MOI.Nonnegatives(1))
96-
fx = MOI.SingleVariable.(x)
97-
func = (1.0 + 0.0im) * fx[1] + 1.0im * fx[1] - 2.0im - (1.0 + 0.0im) * fx[1]
93+
func = (1.0 + 0.0im) * x[1] + 1.0im * x[1] - 2.0im - (1.0 + 0.0im) * x[1]
9894
c = MOI.add_constraint(
9995
optimizer,
10096
MOI.Utilities.operate(vcat, Complex{Float64}, func),
@@ -111,7 +107,7 @@ end
111107

112108
import CSDP
113109
@testset "CSDP" begin
114-
config = MOI.Test.TestConfig(atol=1e-4, rtol=1e-4)
110+
config = MOI.Test.Config(atol=1e-4, rtol=1e-4)
115111
bridged = MOI.instantiate(CSDP.Optimizer, with_bridge_type=Float64)
116112
MOI.Bridges.add_bridge(bridged, COI.Bridges.Variable.HermitianToSymmetricPSDBridge{Float64})
117113
projection_test(bridged, config)

0 commit comments

Comments
 (0)