Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Fix polishing unit test #78

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ julia = "1"

[extras]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"

Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Compat", "Random"]
test = ["Test", "Compat", "Random", "FileIO", "JLD2"]
45 changes: 6 additions & 39 deletions test/polishing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,20 @@ tol = 1e-3
@test results.info.status_polish == 1
end


@testset "polish_random" begin
seed!(1)

n = 30
m = 50
Pt = sprandn(n, n, 0.5)
P = Pt * Pt'
q = randn(n)
A = sprandn(m, n, 0.5)
l = -3 .+ randn(m)
u = 3 .+ randn(m)

# Solve problem
# load randomly generated problem with known accurate solution from Mosek
problem_data = FileIO.load("./problem_data/random_polish_qp.jld2");
P = problem_data["P"]; q = problem_data["q"]; A = problem_data["A"]; u = problem_data["u"]; l = problem_data["l"];
options = setup_polishing()
model = OSQP.Model()
OSQP.setup!(model; P=P, q=q, A=A, l=l, u=u, options...)
results = OSQP.solve!(model)


# # Solve with Gurobi
# using Gurobi
# env = Gurobi.Env()
# setparam!(env, "OutputFlag", 1)
# model = Gurobi.Model(env, "model")
# add_cvars!(model, q); update_model!(model)
# add_constrs!(model, A, repmat(['<'], m), u); update_model!(model)
# add_constrs!(model, A, repmat(['>'], m), l); update_model!(model)
# add_qpterms!(model, P); update_model!(model)
# optimize(model)
# x_test = get_solution(model)
# obj_test= get_objval(model)
# y_test = -Gurobi.get_dblattrarray(model, "Pi", 1, 2 * m)
# y_test = y_test[m+1:end] + y_test[1:m]
#
# println(x_test)
# println(y_test)
# println(obj_test)

x_test = [0.369834, -0.0209277, 0.068939, -0.604151, 0.60773, -0.715965, -0.128837, -0.593642, 0.928932, 0.678794, 0.194334, 0.228124, 0.188779, 0.607246, 0.479752, 0.0878951, 0.275489, 0.761593, 0.0600479, -0.950663, -0.191354, 1.12286, -0.593261, -0.0932879, 0.0286826, -0.0257784, 0.358456, -0.0693514, -0.00358498, -0.0270959]
y_test = [4.88779e-14, 0.441478, 5.89704e-14, 1.76439e-13, 8.10529e-15, 4.9186e-14, 5.00637e-14, 2.00889e-14, 5.39402e-13, -1.9796e-14, 1.52041e-13, 0.149979, 8.97844e-12, 5.93941e-14, -4.11719e-14, -2.38358e-13, 0.226114, -1.8933e-14, 1.54839e-13, 2.99422e-14, 7.16687e-15, -5.32536e-14, 0.116129, -2.53245e-14, 1.21586e-14, -1.66761e-13, 3.04905e-14, 7.35909e-14, 3.84878e-12, -3.09855e-15, 4.30889e-9, 4.09921e-14, -2.4863e-14, -2.46841e-14, 4.37156e-15, 0.219029, -5.14155e-14, 8.31705e-14, 4.51252e-15, -7.90941e-14, 0.206435, -0.196264, 1.06762e-14, 0.338783, 7.58781e-10, -0.105739, 3.30014e-13, -4.05467e-14, 3.3212e-14, -0.161755]

obj_test = -6.021607803961248

@test isapprox(results.x, x_test, atol=tol)
@test isapprox(results.y, y_test, atol=tol)
@test isapprox(results.info.obj_val, obj_test, atol=tol)
@test isapprox(results.x, problem_data["x_test"], atol=tol)
@test isapprox(results.y, problem_data["y_test"], atol=tol)
@test isapprox(results.info.obj_val, problem_data["obj_test"], atol=tol)
@test results.info.status_polish == 1

end
Expand Down
Binary file added test/problem_data/random_polish_qp.jld2
Binary file not shown.
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using OSQP
using Test, SparseArrays, LinearAlgebra
using Random: seed!

using FileIO
tests = [
"basic.jl",
"dual_infeasibility.jl",
Expand Down
Loading