Created
April 21, 2019 00:35
-
-
Save angeris/e2d766e44ba8081b200dea4cf085fbcf to your computer and use it in GitHub Desktop.
Naïve translation of `cvxpy/tests/test_benchmarks.py` to JuMP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using JuMP | |
using LinearAlgebra | |
using BenchmarkTools | |
using ProgressMeter | |
import Random | |
import SCS | |
Random.seed!(1234) | |
function randn_symm(n) | |
A = randn(n, n) | |
return (A + A')/2 | |
end | |
function randn_psd(n) | |
A = randn(n,n) | |
return A * A' | |
end | |
function test_diffcp_sdp_example() | |
n = 300 | |
p = 100 | |
C = randn_psd(n) | |
As = [randn_symm(n) for _ ∈ 1:p] | |
Bs = randn(p) | |
m = Model(with_optimizer(MOIU.MockOptimizer, JuMP._MOIModel{Float64}())) | |
@variable(m, X[1:n,1:n]) | |
@constraint(m, X ∈ PSDCone()) | |
@showprogress for i ∈ 1:p | |
@constraint(m, tr(As[i]*X) == Bs[i]) | |
end | |
@objective(m, Min, tr(C*X)) | |
optimize!(m) | |
end | |
@btime test_diffcp_sdp_example() | |
# Output: ~13mins, on average. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment