Skip to content

Commit

Permalink
Update to MOI v1.0 (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Feb 23, 2022
1 parent 3898d6c commit 1f48d1f
Show file tree
Hide file tree
Showing 37 changed files with 123 additions and 129 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ on:
- 'Project.toml'
jobs:
test:
name: Julia ${{ matrix.version }} - MOI ${{ matrix.moi-version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
moi-version:
- '0.9'
- '0.10'
version:
- '1'
- '1.0'
- '1.6'
os:
- ubuntu-latest
- macOS-latest
Expand All @@ -40,11 +37,6 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- name: "Install MOI version"
shell: julia --color=yes --project=. {0}
run: |
using Pkg
Pkg.add(Pkg.PackageSpec(; name="MathOptInterface", version="${{ matrix.moi-version }}"))
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
# Build documentation on Julia 1.0
version: '1.0'
# Build documentation on Julia LTS
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
17 changes: 9 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Convex"
uuid = "f65535da-76fb-5f13-bab9-19810c17039a"
version = "0.14.18"
version = "0.15.0-DEV"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -14,20 +14,21 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
AbstractTrees = "0.2, 0.3"
BenchmarkTools = "^0.4, 0.5, 0.6, 0.7, 1.0"
BenchmarkTools = "1"
ECOS = "1"
GLPK = "1"
LDLFactorizations = "0.8.1"
MathOptInterface = "0.9, 0.10"
OrderedCollections = "^1.0"
julia = "^1.0"
MathOptInterface = "1"
OrderedCollections = "1"
SCS = "1"
julia = "1.6"

[extras]
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ECOS", "GLPK", "LinearAlgebra", "Random", "SCS", "Statistics", "Test"]
test = ["ECOS", "GLPK", "Random", "SCS", "Statistics"]
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Documenter = "0.27"
MathOptInterface = "0.10"
MathOptInterface = "1"
2 changes: 1 addition & 1 deletion docs/examples_literate/general_examples/basic_usage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

using SCS
## passing in verbose=0 to hide output from SCS
solver = () -> SCS.Optimizer(verbose=0)
solver = MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0)

# ### Linear program
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ p.constraints += a1' * x_c + r * norm(a1, 2) <= b[1];
p.constraints += a2' * x_c + r * norm(a2, 2) <= b[2];
p.constraints += a3' * x_c + r * norm(a3, 2) <= b[3];
p.constraints += a4' * x_c + r * norm(a4, 2) <= b[4];
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
p.optval

# Generate the figure
Expand Down
4 changes: 2 additions & 2 deletions docs/examples_literate/general_examples/control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ push!(constraints, velocity[:, T] == 0)

## Solve the problem
problem = minimize(sumsquares(force), constraints)
solve!(problem, () -> SCS.Optimizer(verbose=0))
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))

# We can plot the trajectory taken by the object.

pos = evaluate(position)
plot([pos[1, 1]], [pos[2, 1]], st=:scatter, label="initial point")
plot!([pos[1, T]], [pos[2, T]], st=:scatter, label="final point")
plot!(pos[1, :], pos[2, :], label="trajectory")
plot!(pos[1, :], pos[2, :], label="trajectory")

# We can also see how the magnitude of the force changes over time.

Expand Down
12 changes: 6 additions & 6 deletions docs/examples_literate/general_examples/huber_regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ for i=1:length(p_vals)
## Generate the sign changes.
factor = 2 * rand(Binomial(1, 1-p), number_samples) .- 1;
Y = factor .* X' * beta_true + v;

## Form and solve a standard regression problem.
beta = Variable(n);
fit = norm(beta - beta_true) / norm(beta_true);
cost = norm(X' * beta - Y);
prob = minimize(cost);
solve!(prob, () -> SCS.Optimizer(verbose=0));
solve!(prob, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0));
lsq_data[i] = evaluate(fit);

## Form and solve a prescient regression problem,
## i.e., where the sign changes are known.
cost = norm(factor .* (X'*beta) - Y);
solve!(minimize(cost), () -> SCS.Optimizer(verbose=0))
solve!(minimize(cost), MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
prescient_data[i] = evaluate(fit);

## Form and solve the Huber regression problem.
cost = sum(huber(X' * beta - Y, 1));
solve!(minimize(cost), () -> SCS.Optimizer(verbose=0))
solve!(minimize(cost), MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
huber_data[i] = evaluate(fit);
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function LassoEN(Y,X,γ,λ=0.0)
L4 = sumsquares(b) #sum(b^2)

Sol = minimize(L1-2*L2+γ*L3+λ*L4) #u'u + γ*sum(|b|) + λsum(b^2), where u = Y-Xb
solve!(Sol,()->SCS.Optimizer(verbose = false))
solve!(Sol, SCS.Optimizer)
Sol.status == MOI.OPTIMAL ? b_i = vec(evaluate(b)) : b_i = NaN

return b_i, b_ls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ X = hcat(ones(size(iris, 1)), iris.SepalLength, iris.SepalWidth, iris.PetalLengt
n, p = size(X)
beta = Variable(p)
problem = minimize(logisticloss(-Y.*(X*beta)))
solve!(problem, () -> SCS.Optimizer(verbose=false))
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))

# Let's see how well the model fits.
using Plots
Expand Down
6 changes: 3 additions & 3 deletions docs/examples_literate/general_examples/max_entropy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ using Convex, SCS

n = 25;
m = 15;
A = randn(m, n);
b = rand(m, 1);
A = randn(m, n);
b = rand(m, 1);

x = Variable(n);
problem = maximize(entropy(x), sum(x) == 1, A * x <= b)
solve!(problem, () -> SCS.Optimizer(verbose=false))
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
problem.optval

#-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ SCALE = 10000;
B = rand(LogNormal(8), m) .+ 10000;
B = round.(B, digits=3); # Budget

P_ad = rand(m);
P_time = rand(1,n);
P_ad = rand(m);
P_time = rand(1,n);
P = P_ad * P_time;

T = sin.(range(-2*pi/2, stop=2*pi-2*pi/2, length=n)) * SCALE;
Expand All @@ -46,7 +46,7 @@ D = Variable(m, n);
Si = [min(R[i]*dot(P[i,:], D[i,:]'), B[i]) for i=1:m];
problem = maximize(sum(Si),
[D >= 0, sum(D, dims=1)' <= T, sum(D, dims=2) >= c]);
solve!(problem, () -> SCS.Optimizer(verbose=0));
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0));

#-

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ x = Variable(n)

# Case 1: Nominal optimal solution
p = minimize(norm(A * x - b, 2))
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
x_nom = evaluate(x)

# Case 2: Stochastic robust approximation
P = 1 / 3 * B' * B;
p = minimize(square(pos(norm(A * x - b))) + quadform(x, Symmetric(P)))
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
x_stoch = evaluate(x)

# Case 3: Worst-case robust approximation
p = minimize(max(norm((A - B) * x - b), norm((A + B) * x - b)))
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
x_wc = evaluate(x)

# Plot residuals:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples_literate/general_examples/svm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ neg_data = rand(MvNormal([-1.0, 2.0], 1.0), M);

#-

function svm(pos_data, neg_data, solver=() -> SCS.Optimizer(verbose=0))
function svm(pos_data, neg_data, solver=MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
## Create variables for the separating hyperplane w'*x = b.
w = Variable(n)
b = Variable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ beta_vals = zeros(length(beta), TRIALS);
for i = 1:TRIALS
lambda = lambda_vals[i];
problem = minimize(loss/m + lambda*reg);
solve!(problem, () -> ECOS.Optimizer(verbose=0));
## solve!(problem, SCS.Optimizer(verbose=0,linear_solver=SCS.Direct, eps=1e-3))
solve!(problem, MOI.OptimizerWIthAttributes(ECOS.Optimizer, "verbose" => 0));
train_error[i] = sum(float(sign.(X*beta_true .+ offset) .!= sign.(evaluate(X*beta - v))))/m;
test_error[i] = sum(float(sign.(X_test*beta_true .+ offset) .!= sign.(evaluate(X_test*beta - v))))/TEST;
beta_vals[:, i] = evaluate(beta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ x = Variable(n);
for i=1:length(gammas)
cost = sumsquares(A*x - b) + gammas[i]*norm(x,1);
problem = minimize(cost, [norm(x, Inf) <= 1]);
solve!(problem, () -> SCS.Optimizer(verbose=0));
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0));
x_values[:,i] = evaluate(x);
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ w = Variable(n);
ret = dot(r, w);
risk = sum(quadform(w, Sigma_nom));
problem = minimize(risk, [sum(w) == 1, ret >= 0.1, norm(w, 1) <= 2])
solve!(problem, () -> SCS.Optimizer(verbose=0));
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0));
wval = vec(evaluate(w))

#-
Expand All @@ -31,7 +31,7 @@ problem = maximize(risk, [Sigma == Sigma_nom + Delta,
diag(Delta) == 0,
abs(Delta) <= 0.2,
Delta == Delta']);
solve!(problem, () -> SCS.Optimizer(verbose=0));
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0));
println("standard deviation = ", round(sqrt(wval' * Sigma_nom * wval), sigdigits=2));
println("worst-case standard deviation = ", round(sqrt(evaluate(risk)), sigdigits=2));
println("worst-case Delta = ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Z = ComplexVariable(n,n)
objective = 0.5*real(tr(Z+Z'))
constraint = [P Z;Z' Q] 0
problem = maximize(objective,constraint)
solve!(problem, () -> SCS.Optimizer(verbose=0))
solve!(problem, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
computed_fidelity = evaluate(objective)

#-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # Phase recovery using MaxCut
#
#
# In this example, we relax the phase retrieval problem similar to the classical
# [MaxCut](http://www-math.mit.edu/~goemans/PAPERS/maxcut-jacm.pdf) semidefinite
# program and recover the phase of the signal given the magnitude of the linear
Expand Down Expand Up @@ -29,7 +29,7 @@
# Given a linear operator $A$ and a vector $b= |Ax|$ of measured amplitudes,
# in the noiseless case, we can write $Ax = \text{diag}(b)u$ where
# $u \in \mathbb{C}^n$ is a phase vector, satisfying
# $|\mathbb{u}_i| = 1$ for $i = 1,\ldots, n$.
# $|\mathbb{u}_i| = 1$ for $i = 1,\ldots, n$.
#
# We relax this problem as Complex Semidefinite Programming.
#
Expand Down Expand Up @@ -66,10 +66,10 @@ b = abs.(A*x) + rand(n)
M = diagm(b)*(I(n)-A*A')*diagm(b)
U = ComplexVariable(n,n)
objective = inner_product(U,M)
c1 = diag(U) == 1
c1 = diag(U) == 1
c2 = U in :SDP
p = minimize(objective,c1,c2)
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
evaluate(U)


Expand All @@ -79,7 +79,7 @@ evaluate(U)
B, C = eigen(evaluate(U));
length([e for e in B if(abs(real(e))>1e-4)])

#-
#-

# Decompose $U = uu^*$ where $u$ is the phase of $Ax$
u = C[:,1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if VERSION < v"1.2.0-DEV.0"
LinearAlgebra.diagm(v::AbstractVector) = diagm(0 => v)
end

# For the qubit case, a four outcome qubit POVM $\mathbf{M} \in\mathcal{P}(2,4)$ is simulable if and only if
# For the qubit case, a four outcome qubit POVM $\mathbf{M} \in\mathcal{P}(2,4)$ is simulable if and only if
#
# $M_{1}=N_{12}^{+}+N_{13}^{+}+N_{14}^{+},$
#
Expand Down Expand Up @@ -55,7 +55,7 @@ function get_visibility(K)
constraints += t*K[3] + (1-t)*noise[3] == P[2][2] + P[4][2] + P[6][1]
constraints += t*K[4] + (1-t)*noise[4] == P[3][2] + P[5][2] + P[6][2]
p = maximize(t, constraints)
solve!(p, () -> SCS.Optimizer(verbose=0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
return p.optval
end

Expand All @@ -64,9 +64,9 @@ end
function dp(v)
I(2) + v[1]*[0 1; 1 0] + v[2]*[0 -im; im 0] + v[3]*[1 0; 0 -1]
end
b = [ 1 1 1;
-1 -1 1;
-1 1 -1;
b = [ 1 1 1;
-1 -1 1;
-1 1 -1;
1 -1 -1]/sqrt(3)
M = [dp(b[i, :]) for i=1:size(b,1)]/4;
get_visibility(M)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # Power flow optimization
# The data for example is taken from [MATPOWER](http://www.pserc.cornell.edu/matpower/) website. MATPOWER is Matlab package for solving power flow and optimal power flow problems.
# The data for example is taken from [MATPOWER](http://www.pserc.cornell.edu/matpower/) website. MATPOWER is Matlab package for solving power flow and optimal power flow problems.

using Convex, SCS
using Test
Expand All @@ -25,7 +25,7 @@ c3 = real(W[1,1]) == 1.06^2;
push!(c1, c2)
push!(c1, c3)
p = maximize(objective, c1);
solve!(p, () -> SCS.Optimizer(verbose = 0))
solve!(p, MOI.OptimizerWithAttributes(SCS.Optimizer, "verbose" => 0))
p.optval
#15.125857662600703
evaluate(objective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using Convex, SCS
34 64 4;
58 4 100]/100^2

n = length(μ) #number of assets
n = length(μ) #number of assets

R_target = 0.1
w_lower = 0
Expand All @@ -50,13 +50,13 @@ w = Variable(n)
ret = dot(w,μ)
risk = quadform(w,Σ)

p = minimize( risk,
ret >= R_target,
sum(w) == 1,
w_lower <= w,
p = minimize( risk,
ret >= R_target,
sum(w) == 1,
w_lower <= w,
w <= w_upper )

solve!(p, () -> SCS.Optimizer()) #use SCS.Optimizer(verbose = false) to suppress printing
solve!(p, SCS.Optimizer)

#-

Expand Down

0 comments on commit 1f48d1f

Please sign in to comment.