Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabinsch committed Oct 13, 2023
1 parent 83951fe commit fce0e2f
Show file tree
Hide file tree
Showing 32 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/cpp/benchmark_dense_qp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Setup Time consumption(dense): 0.0592621s
Solve Time consumption(dense): 0.101507s
*/

#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp>
#include <proxsuite/proxqp/utils/random_qp_problems.hpp>

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/estimate_nonconvex_eigenvalue.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/init_dense_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/init_dense_qp_with_box.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/init_dense_qp_with_other_options.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/init_dense_qp_with_timings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/init_with_default_options.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/initializing_with_none.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "proxsuite/proxqp/dense/dense.hpp"
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/initializing_with_none_without_api.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "proxsuite/proxqp/dense/dense.hpp"
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/loading_dense_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "proxsuite/proxqp/dense/dense.hpp"

using namespace proxsuite::proxqp;
Expand Down
1 change: 1 addition & 0 deletions examples/cpp/loading_dense_qp_with_box_ineq.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "proxsuite/proxqp/dense/dense.hpp"

using namespace proxsuite::proxqp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "proxsuite/proxqp/dense/dense.hpp"

using namespace proxsuite::proxqp;
Expand Down
1 change: 1 addition & 0 deletions examples/cpp/overview-simple.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp>
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/solve_dense_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/solve_dense_qp_with_setting.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/update_dense_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions examples/cpp/update_dense_qp_ws_previous_result.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp

Expand Down
1 change: 1 addition & 0 deletions test/src/cvxpy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <proxsuite/proxqp/dense/dense.hpp>
Expand Down
9 changes: 5 additions & 4 deletions test/src/dense_backward.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2023 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <proxsuite/proxqp/dense/dense.hpp>
Expand Down Expand Up @@ -84,7 +85,7 @@ DOCTEST_TEST_CASE("proxqp::dense: test compute backward for b (feasible QP)")
utils::rand::set_seed(1);
dense::isize dim = 10;

dense::isize n_eq(5), n_in(2);
dense::isize n_eq(5), n_in(0);
T strong_convexity_factor(1.e-2);
proxqp::dense::Model<T> random_qp = proxqp::utils::dense_strongly_convex_qp(
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
Expand All @@ -93,9 +94,9 @@ DOCTEST_TEST_CASE("proxqp::dense: test compute backward for b (feasible QP)")
Eigen::Matrix<T, 10, 1> g = random_qp.g;
Eigen::Matrix<T, 5, 10> A = random_qp.A;
Eigen::Matrix<T, 5, 1> b = random_qp.b;
Eigen::Matrix<T, 2, 10> C = random_qp.C;
Eigen::Matrix<T, 2, 1> l = random_qp.l;
Eigen::Matrix<T, 2, 1> u = random_qp.u;
// Eigen::Matrix<T, 2, 10> C = random_qp.C;
// Eigen::Matrix<T, 2, 1> l = random_qp.l;
// Eigen::Matrix<T, 2, 1> u = random_qp.u;

dense::QP<T> qp{ dim, n_eq, n_in }; // creating QP object
qp.settings.eps_abs = eps_abs;
Expand Down
2 changes: 1 addition & 1 deletion test/src/dense_qp_eq.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
#include <proxsuite/proxqp/dense/dense.hpp>
#include <proxsuite/linalg/veg/util/dbg.hpp>
#include <proxsuite/proxqp/utils/random_qp_problems.hpp>
#include <iostream>

using T = double;
using namespace proxsuite;
Expand Down
1 change: 1 addition & 0 deletions test/src/dense_qp_solve.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
2 changes: 1 addition & 1 deletion test/src/dense_qp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_mixed_qp(n, seed=1):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + 1e-02) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
v = np.random.randn(n) # Fictitious solution
Expand Down
1 change: 1 addition & 0 deletions test/src/dense_qp_with_eq_and_in.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
1 change: 1 addition & 0 deletions test/src/dense_qp_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
13 changes: 11 additions & 2 deletions test/src/dense_qp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import scipy.sparse as spa
import unittest

np.printoptions(precision=16)


def normInf(x):
if x.shape[0] == 0:
Expand Down Expand Up @@ -33,7 +35,7 @@ def generate_mixed_qp(n, seed=1, reg=0.01):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + reg) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
v = np.random.randn(n) # Fictitious solution
Expand Down Expand Up @@ -63,7 +65,7 @@ def generate_mixed_qp_with_box(n, seed=1):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + 1e-02) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
v = np.random.randn(n) # Fictitious solution
Expand Down Expand Up @@ -126,6 +128,13 @@ def test_case_deterministic_behavior(self):
u=np.asfortranarray(u),
)
qp.solve()
print(f"{normInf(x_prev - qp.results.x)=}")
print(f"{normInf(y_prev - qp.results.y)=}")
print(f"{normInf(z_prev - qp.results.z)=}")

print(f"{y_prev=}")
print(f"{qp.results.y=}")

assert normInf(x_prev - qp.results.x) <= 1e-15
assert normInf(y_prev - qp.results.y) <= 1e-15
assert normInf(z_prev - qp.results.z) <= 1e-15
Expand Down
12 changes: 8 additions & 4 deletions test/src/dense_ruiz_equilibration.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//
// Copyright (c) 2022-2023 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand All @@ -13,12 +17,12 @@ DOCTEST_TEST_CASE("ruiz preconditioner")
int dim = 5;
int n_eq = 6;
int n_in = 0;
// auto sym = proxqp::Symmetry::general; // 0 : upper triangular (by default),
auto sym = proxqp::Symmetry::general; // 0 : upper triangular (by default),
// 1:
auto sym = proxqp::Symmetry::lower; // 0 : upper triangular (by default), 1:
// lower triangular ; else full matrix
// auto sym = proxqp::Symmetry::lower; // 0 : upper triangular (by default),
// 1: lower triangular ; else full matrix

Scalar sparsity_factor(0.15);
Scalar sparsity_factor(0.75);
Scalar strong_convexity_factor(0.01);
proxqp::dense::Model<Scalar> qp_random =
proxqp::utils::dense_strongly_convex_qp(
Expand Down
1 change: 1 addition & 0 deletions test/src/dense_unconstrained_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <Eigen/Core>
#include <Eigen/Cholesky>
Expand Down
1 change: 1 addition & 0 deletions test/src/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (c) 2022 INRIA
//
#include <iostream>
#include <doctest.hpp>
#include <proxsuite/proxqp/dense/dense.hpp>
#include <proxsuite/proxqp/utils/random_qp_problems.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/src/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_mixed_qp(n, seed=1):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + 1e-02) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc").toarray()
v = np.random.randn(n) # Fictitious solution
Expand Down
1 change: 1 addition & 0 deletions test/src/sparse_maros_meszaros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2022-2023 INRIA
//

#include <iostream>
#include <doctest.hpp>
#include <maros_meszaros.hpp>
#include <proxsuite/proxqp/sparse/wrapper.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/src/sparse_qp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def generate_mixed_qp(n, seed=1):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + 1e-02) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc")
v = np.random.randn(n) # Fictitious solution
Expand Down
2 changes: 1 addition & 1 deletion test/src/sparse_qp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def generate_mixed_qp(n, seed=1, reg=0.01):
s = max(np.absolute(np.linalg.eigvals(P)))
P += (abs(s) + reg) * spa.eye(n)
P = spa.coo_matrix(P)
print("sparsity of P : {}".format((P.nnz) / (n**2)))
# print("sparsity of P : {}".format((P.nnz) / (n**2)))
q = np.random.randn(n)
A = spa.random(m, n, density=0.15, data_rvs=np.random.randn, format="csc")
v = np.random.randn(n) # Fictitious solution
Expand Down

0 comments on commit fce0e2f

Please sign in to comment.