Skip to content

Commit 2f0b8da

Browse files
authored
Merge pull request #26 from Bambade/devel
Add default proximal step sizes
2 parents 3742299 + f7c8638 commit 2f0b8da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+13175
-6914
lines changed

bindings/python/src/expose-settings.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ exposeSettings(pybind11::module_ m)
2828

2929
::pybind11::class_<Settings<T>>(m, "Settings", pybind11::module_local())
3030
.def(::pybind11::init(), "Default constructor.") // constructor
31+
.def_readwrite("default_rho", &Settings<T>::default_rho)
32+
.def_readwrite("default_mu_eq", &Settings<T>::default_mu_eq)
33+
.def_readwrite("default_mu_in", &Settings<T>::default_mu_in)
3134
.def_readwrite("alpha_bcl", &Settings<T>::alpha_bcl)
3235
.def_readwrite("beta_bcl", &Settings<T>::beta_bcl)
3336
.def_readwrite("refactor_dual_feasibility_threshold",

doc/2-PROXQP_API/2-ProxQP_api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ In this table you have on the three columns from left to right: the name of the
302302
| eps_abs | 1.E-3 | Asbolute stopping criterion of the solver.
303303
| eps_rel | 0 | Relative stopping criterion of the solver.
304304
| VERBOSE | False | If set to true, the solver prints information at each loop.
305+
| default_rho | 1.E-6 | Default rho parameter of result class (i.e., for each initial guess, except WARM_START_WITH_PREVIOUS_RESULT, after a new solve or update, the solver initializes rho to this value).
306+
| default_mu_eq | 1.E-3 | Default mu_eq parameter of result class (i.e., for each initial guess, except WARM_START_WITH_PREVIOUS_RESULT, after a new solve or update, the solver initializes mu_eq to this value).
307+
| default_mu_in | 1.E-1 | Default mu_in parameter of result class (i.e., for each initial guess, except WARM_START_WITH_PREVIOUS_RESULT, after a new solve or update, the solver initializes mu_in to this value).
305308
| compute_timings | True | If set to true, timings will be computed by the solver (setup time, solving time, and run time = setup time + solving time).
306309
| max_iter | 1.E4 | Maximal number of authorized outer iterations.
307310
| max_iter_in | 1500 | Maximal number of authorized inner iterations.
@@ -430,6 +433,25 @@ In this table you have on the three columns from left to right: the name of the
430433
| pri_res | 0 | The primal residual.
431434
| dua_res | 0 | The dual residual.
432435

436+
437+
Note finally that when initializing a QP object, by default the proximal step sizes (i.e., rho, mu_eq and mu_in) are set up by the default values defined in the Setting class. Hence, when doing multiple solves, if not specified, their values are re-set respectively to default_rho, default_mu_eq and default_mu_in. A small example is given below in c++ and python.
438+
439+
<table class="manual">
440+
<tr>
441+
<th>examples/cpp/init_with_default_options.cpp</th>
442+
<th>examples/python/init_with_default_options.py</th>
443+
</tr>
444+
<tr>
445+
<td valign="top">
446+
\include init_with_default_options.cpp
447+
</td>
448+
<td valign="top">
449+
\include init_with_default_options.py
450+
</td>
451+
</tr>
452+
</table>
453+
454+
433455
\subsection OverviewSolverStatus The solver's status
434456

435457
The solver has four status:

examples/cpp/init_dense_qp.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -13,9 +13,15 @@ main()
1313
// generate a random qp
1414
T sparsity_factor(0.15);
1515
T strong_convexity_factor(1.e-2);
16-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
16+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1717
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1818

19-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
19+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
20+
qp.init(qp_random.H,
21+
qp_random.g,
22+
qp_random.A,
23+
qp_random.b,
24+
qp_random.C,
25+
qp_random.u,
26+
qp_random.l); // initialize the model
2127
}

examples/cpp/init_dense_qp_with_other_options.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -12,13 +12,21 @@ main()
1212
// generate a random qp
1313
T sparsity_factor(0.15);
1414
T strong_convexity_factor(1.e-2);
15-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1616
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1717

18-
dense::QP<T> Qp(
18+
dense::QP<T> qp(
1919
dim, n_eq, n_in); // create the QP
2020
// initialize the model, along with another rho parameter
21-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l, true, /*rho*/ 1.e-7);
21+
qp.init(qp_random.H,
22+
qp_random.g,
23+
qp_random.A,
24+
qp_random.b,
25+
qp_random.C,
26+
qp_random.u,
27+
qp_random.l,
28+
true,
29+
/*rho*/ 1.e-7);
2230
// in c++ you must follow the order speficied in the API for the parameters
2331
// if you don't want to change one parameter (here compute_preconditioner),
2432
// just let it be std::nullopt
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -12,10 +12,16 @@ main()
1212
// generate a random qp
1313
T sparsity_factor(0.15);
1414
T strong_convexity_factor(1.e-2);
15-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1616
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1717

18-
dense::QP<T> Qp(dim, n_eq, n_in); // create the QP object
19-
Qp.settings.compute_timings = true; // compute all timings
20-
Qp.init(qp.H, qp.g, qp.A, qp.b, qp.C, qp.u, qp.l); // initialize the model
18+
dense::QP<T> qp(dim, n_eq, n_in); // create the QP object
19+
qp.settings.compute_timings = true; // compute all timings
20+
qp.init(qp_random.H,
21+
qp_random.g,
22+
qp_random.A,
23+
qp_random.b,
24+
qp_random.C,
25+
qp_random.u,
26+
qp_random.l); // initialize the model
2127
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <proxsuite/proxqp/dense/dense.hpp> // load the dense solver backend
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
3+
4+
using namespace proxsuite::proxqp;
5+
using T = double;
6+
int
7+
main()
8+
{
9+
isize dim = 10;
10+
isize n_eq(dim / 4);
11+
isize n_in(dim / 4);
12+
// generate a random qp
13+
T sparsity_factor(0.15);
14+
T strong_convexity_factor(1.e-2);
15+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
16+
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
17+
18+
dense::QP<T> qp(
19+
dim, n_eq, n_in); // create the QP
20+
// initialize the model, along with another rho parameter
21+
qp.settings.initial_guess = InitialGuessStatus::NO_INITIAL_GUESS;
22+
qp.init(qp_random.H,
23+
qp_random.g,
24+
qp_random.A,
25+
qp_random.b,
26+
qp_random.C,
27+
qp_random.u,
28+
qp_random.l,
29+
true,
30+
/*rho*/ 1.e-7,
31+
/*mu_eq*/ 1.e-4);
32+
// Initializing rho sets in practive qp.settings.default_rho value,
33+
// hence, after each solve or update method, the qp.results.info.rho value
34+
// will be reset to qp.settings.default_rho value.
35+
qp.solve();
36+
// So if we redo a solve, qp.settings.default_rho value = 1.e-7, hence
37+
// qp.results.info.rho restarts at 1.e-7 The same occurs for mu_eq.
38+
qp.solve();
39+
// There might be a different result with WARM_START_WITH_PREVIOUS_RESULT
40+
// initial guess option, as by construction, it reuses the last proximal step
41+
// sizes of the last solving method.
42+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "proxsuite/proxqp/dense/dense.hpp"
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -9,27 +9,27 @@ main()
99
dense::isize dim = 10;
1010
dense::isize n_eq(0);
1111
dense::isize n_in(0);
12-
dense::QP<T> Qp(dim, n_eq, n_in);
12+
dense::QP<T> qp(dim, n_eq, n_in);
1313
T strong_convexity_factor(0.1);
1414
T sparsity_factor(0.15);
1515
// we generate a qp, so the function used from helpers.hpp is
1616
// in proxqp namespace. The qp is in dense eigen format and
1717
// you can control its sparsity ratio and strong convexity factor.
18-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
18+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1919
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
2020

21-
Qp.init(qp.H,
22-
qp.g,
23-
qp.A,
24-
qp.b,
25-
qp.C,
26-
qp.u,
27-
qp.l); // initialization with zero shape matrices
28-
// it is equivalent to do Qp.init(qp.H, qp.g,
21+
qp.init(qp_random.H,
22+
qp_random.g,
23+
qp_random.A,
24+
qp_random.b,
25+
qp_random.C,
26+
qp_random.u,
27+
qp_random.l); // initialization with zero shape matrices
28+
// it is equivalent to do qp.init(qp_random.H, qp_random.g,
2929
// std::nullopt,std::nullopt,std::nullopt,std::nullopt,std::nullopt);
30-
Qp.solve();
30+
qp.solve();
3131
// print an optimal solution x,y and z
32-
std::cout << "optimal x: " << Qp.results.x << std::endl;
33-
std::cout << "optimal y: " << Qp.results.y << std::endl;
34-
std::cout << "optimal z: " << Qp.results.z << std::endl;
32+
std::cout << "optimal x: " << qp.results.x << std::endl;
33+
std::cout << "optimal y: " << qp.results.y << std::endl;
34+
std::cout << "optimal z: " << qp.results.z << std::endl;
3535
}

examples/cpp/initializing_with_none_without_api.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "proxsuite/proxqp/dense/dense.hpp"
2-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
2+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
33

44
using namespace proxsuite::proxqp;
55
using T = double;
@@ -14,18 +14,18 @@ main()
1414
// we generate a qp, so the function used from helpers.hpp is
1515
// in proxqp namespace. The qp is in dense eigen format and
1616
// you can control its sparsity ratio and strong convexity factor.
17-
dense::Model<T> qp = utils::dense_strongly_convex_qp(
17+
dense::Model<T> qp_random = utils::dense_strongly_convex_qp(
1818
dim, n_eq, n_in, sparsity_factor, strong_convexity_factor);
1919

2020
Results<T> results =
21-
dense::solve<T>(qp.H,
22-
qp.g,
23-
qp.A,
24-
qp.b,
25-
qp.C,
26-
qp.u,
27-
qp.l); // initialization with zero shape matrices
28-
// it is equivalent to do dense::solve<T>(qp.H, qp.g,
21+
dense::solve<T>(qp_random.H,
22+
qp_random.g,
23+
qp_random.A,
24+
qp_random.b,
25+
qp_random.C,
26+
qp_random.u,
27+
qp_random.l); // initialization with zero shape matrices
28+
// it is equivalent to do dense::solve<T>(qp_random.H, qp_random.g,
2929
// std::nullopt,std::nullopt,std::nullopt,std::nullopt,std::nullopt);
3030
// print an optimal solution x,y and z
3131
std::cout << "optimal x: " << results.x << std::endl;

examples/cpp/loading_dense_qp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ main()
88
dense::isize dim = 10;
99
dense::isize n_eq(dim / 4);
1010
dense::isize n_in(dim / 4);
11-
dense::QP<T> Qp(dim, n_eq, n_in);
11+
dense::QP<T> qp(dim, n_eq, n_in);
1212
}

examples/cpp/loading_sparse_qp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#include <iostream>
22
#include <proxsuite/proxqp/sparse/sparse.hpp> // get the sparse API of ProxQP
3-
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex Qp
3+
#include <proxsuite/proxqp/utils/random_qp_problems.hpp> // used for generating a random convex qp
44

55
using namespace proxsuite::proxqp;
66
using T = double;
77

88
int
99
main()
1010
{
11-
// design a Qp object using QP problem dimensions
11+
// design a qp object using QP problem dimensions
1212
isize n = 10;
1313
isize n_eq(n / 4);
1414
isize n_in(n / 4);
15-
sparse::QP<T, isize> Qp(n, n_eq, n_in);
15+
sparse::QP<T, isize> qp(n, n_eq, n_in);
1616

1717
// assume you generate these matrices H, A and C for your QP problem
1818

@@ -24,7 +24,7 @@ main()
2424
auto A = ::proxsuite::proxqp::utils::rand::sparse_matrix_rand<T>(n_eq, n, p);
2525
auto C = ::proxsuite::proxqp::utils::rand::sparse_matrix_rand<T>(n_in, n, p);
2626

27-
// design a Qp2 object using sparsity masks of H, A and C
28-
proxsuite::proxqp::sparse::QP<T, isize> Qp2(
27+
// design a qp2 object using sparsity masks of H, A and C
28+
proxsuite::proxqp::sparse::QP<T, isize> qp2(
2929
H.cast<bool>(), A.cast<bool>(), C.cast<bool>());
3030
}

0 commit comments

Comments
 (0)