Skip to content

Commit c1218c8

Browse files
authored
Merge pull request #374 from stephane-caron/fix/qplayer_docs
Expose QPFunction in the documentation
2 parents 88aa809 + c4eddae commit c1218c8

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

bindings/python/proxsuite/torch/qplayer.py

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,72 @@ def QPFunction(
1818
omp_parallel=False,
1919
structural_feasibility=True,
2020
):
21-
"""
21+
"""!
2222
Solve a batch of Quadratic Programming (QP) problems.
2323
2424
This function solves QP problems of the form:
25-
min 0.5*z'*Q*z + p'*z
26-
s.t. l <= G*z <= h
27-
A*z = b
25+
26+
$$
27+
\begin{align}
28+
\min_{z} & ~\frac{1}{2}z^{T} Q (\theta) z +p(\theta)^{T}z \\\
29+
\text{s.t.} & ~A(\theta) z = b(\theta) \\\
30+
& ~l(\theta) \leq G(\theta) z \leq u(\theta)
31+
\end{align}
32+
$$
2833
2934
The QP can be infeasible - in this case the solver will return a solution to
3035
the closest feasible QP.
3136
32-
Args:
33-
eps (float, optional): Tolerance for the primal infeasibility. Defaults to 1e-9.
34-
maxIter (int, optional): Maximum number of iterations. Defaults to 1000.
35-
eps_backward (float, optional): Tolerance for the backward pass. Defaults to 1e-4.
36-
rho_backward (float, optional): The new value for the primal proximal parameter. Defaults to 1e-6.
37-
mu_backward (float, optional): The new dual proximal parameter used for both equality and inequality. Defaults to 1e-6.
38-
omp_parallel (bool, optional): Whether to solve the QP in parallel. Requires that proxsuite is compiled with openmp support. Defaults to False.
39-
structural_feasibility (bool, optional): Whether to solve the QP with structural feasibility. Defaults to True.
40-
41-
Returns:
42-
QPFunctionFn or QPFunctionFn_infeas: A callable object that represents the QP problem solver.
37+
\param[in] eps Tolerance for the primal infeasibility. Defaults to 1e-9.
38+
\param[in] maxIter Maximum number of iterations. Defaults to 1000.
39+
\param[in] eps_backward Tolerance for the backward pass. Defaults to 1e-4.
40+
\param[in] rho_backward The new value for the primal proximal parameter. Defaults to 1e-6.
41+
\param[in] mu_backward The new dual proximal parameter used for both equality and inequality. Defaults to 1e-6.
42+
\param[in] omp_parallel Whether to solve the QP in parallel. Requires that proxsuite is compiled with openmp support. Defaults to False.
43+
\param[in] structural_feasibility Whether to solve the QP with structural feasibility. Defaults to True.
44+
45+
\returns QPFunctionFn or QPFunctionFn_infeas: A callable object that represents the QP problem solver.
4346
We disinguish two cases:
4447
1. The QP is feasible. In this case, we solve the QP problem.
4548
2. The QP is infeasible. In this case, we solve the closest feasible QP problem.
4649
4750
The callable object has two main methods:
4851
49-
Forward:
50-
Solve the QP problem.
51-
52-
Args:
53-
Q (torch.Tensor): Batch of quadratic cost matrices of size (nBatch, n, n) or (n, n).
54-
p (torch.Tensor): Batch of linear cost vectors of size (nBatch, n) or (n).
55-
A (torch.Tensor, optional): Batch of eq. constraint matrices of size (nBatch, p, n) or (p, n).
56-
b (torch.Tensor, optional): Batch of eq. constraint vectors of size (nBatch, p) or (p).
57-
G (torch.Tensor): Batch of ineq. constraint matrices of size (nBatch, m, n) or (m, n).
58-
l (torch.Tensor): Batch of ineq. lower bound vectors of size (nBatch, m) or (m).
59-
u (torch.Tensor): Batch of ineq. upper bound vectors of size (nBatch, m) or (m).
60-
61-
Returns:
62-
zhats (torch.Tensor): Batch of optimal primal solutions of size (nBatch, n).
63-
lams (torch.Tensor): Batch of dual variables for eq. constraint of size (nBatch, m).
64-
nus (torch.Tensor): Batch of dual variables for ineq. constraints of size (nBatch, p).
65-
Only for infeasible case:
66-
s_e (torch.Tensor): Batch of slack variables for eq. constraints of size (nBatch, m).
67-
s_i (torch.Tensor): Batch of slack variables for ineq. constraints of size (nBatch, p).
68-
69-
Backward:
70-
Compute the gradients of the QP problem wrt its parameters.
71-
72-
Args:
73-
dl_dzhat (torch.Tensor): Batch of gradients of size (nBatch, n).
74-
dl_dlams (torch.Tensor, optional): Batch of gradients of size (nBatch, p).
75-
dl_dnus (torch.Tensor, optional): Batch of gradients of size (nBatch, m).
76-
Only for infeasible case:
77-
dl_ds_e (torch.Tensor, optional): Batch of gradients of size (nBatch, m).
78-
dl_ds_i (torch.Tensor, optional): Batch of gradients of size (nBatch, m).
79-
80-
Returns:
81-
dQs (torch.Tensor): Batch of gradients of size (nBatch, n, n).
82-
dps (torch.Tensor): Batch of gradients of size (nBatch, n).
83-
dAs (torch.Tensor): Batch of gradients of size (nBatch, p, n).
84-
dbs (torch.Tensor): Batch of gradients of size (nBatch, p).
85-
dGs (torch.Tensor): Batch of gradients of size (nBatch, m, n).
86-
dls (torch.Tensor): Batch of gradients of size (nBatch, m).
87-
dus (torch.Tensor): Batch of gradients of size (nBatch, m).
52+
\section qpfunction-forward Forward method
53+
54+
Solve the QP problem.
55+
56+
\param[in] Q Batch of quadratic cost matrices of size (nBatch, n, n) or (n, n).
57+
\param[in] p Batch of linear cost vectors of size (nBatch, n) or (n).
58+
\param[in] A Optional batch of eq. constraint matrices of size (nBatch, p, n) or (p, n).
59+
\param[in] b Optional batch of eq. constraint vectors of size (nBatch, p) or (p).
60+
\param[in] G Batch of ineq. constraint matrices of size (nBatch, m, n) or (m, n).
61+
\param[in] l Batch of ineq. lower bound vectors of size (nBatch, m) or (m).
62+
\param[in] u Batch of ineq. upper bound vectors of size (nBatch, m) or (m).
63+
64+
\returns \p zhats Batch of optimal primal solutions of size (nBatch, n).
65+
\returns \p lams Batch of dual variables for eq. constraint of size (nBatch, m).
66+
\returns \p nus Batch of dual variables for ineq. constraints of size (nBatch, p).
67+
\returns \p s_e Only returned in the infeasible case: batch of slack variables for eq. constraints of size (nBatch, m).
68+
\returns \p s_i Only returned in the infeasible case: batch of slack variables for ineq. constraints of size (nBatch, p).
69+
70+
\section qpfunction-backward Backward method
71+
72+
Compute the gradients of the QP problem with respect to its parameters.
73+
74+
\param[in] dl_dzhat Batch of gradients of size (nBatch, n).
75+
\param[in] dl_dlams Optional batch of gradients of size (nBatch, p).
76+
\param[in] dl_dnus Optional batch of gradients of size (nBatch, m).
77+
\param[in] dl_ds_e Only applicable in the infeasible case: optional batch of gradients of size (nBatch, m).
78+
\param[in] dl_ds_i Only applicable in the infeasible case: optional batch of gradients of size (nBatch, m).
79+
80+
\returns \p dQs Batch of gradients of size (nBatch, n, n).
81+
\returns \p dps Batch of gradients of size (nBatch, n).
82+
\returns \p dAs Batch of gradients of size (nBatch, p, n).
83+
\returns \p dbs Batch of gradients of size (nBatch, p).
84+
\returns \p dGs Batch of gradients of size (nBatch, m, n).
85+
\returns \p dls Batch of gradients of size (nBatch, m).
86+
\returns \p dus Batch of gradients of size (nBatch, m).
8887
"""
8988
global proxqp_parallel
9089
proxqp_parallel = omp_parallel

doc/4-qplayer.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
$$
66
\begin{align}
7-
\min_{x} & ~\frac{1}{2}x^{T}H(\theta)x+g(\theta)^{T}x \\
8-
\text{s.t.} & ~A(\theta) x = b(\theta) \\
7+
\min_{x} & ~\frac{1}{2}x^{T}H(\theta)x+g(\theta)^{T}x \\\
8+
\text{s.t.} & ~A(\theta) x = b(\theta) \\\
99
& ~l(\theta) \leq C(\theta) x \leq u(\theta)
1010
\end{align}
1111
$$
1212

1313
where \f$x \in \mathbb{R}^n\f$ is the optimization variable. The objective function is defined by a positive semidefinite matrix \f$H(\theta) \in \mathcal{S}^n_+\f$ and a vector \f$g(\theta) \in \mathbb{R}^n\f$. The linear constraints are defined by the equality-contraint matrix \f$A(\theta) \in \mathbb{R}^{n_\text{eq} \times n}\f$ and the inequality-constraint matrix \f$C(\theta) \in \mathbb{R}^{n_\text{in} \times n}\f$ and the vectors \f$b \in \mathbb{R}^{n_\text{eq}}\f$, \f$l(\theta) \in \mathbb{R}^{n_\text{in}}\f$ and \f$u(\theta) \in \mathbb{R}^{n_\text{in}}\f$ so that \f$b_i \in \mathbb{R},~ \forall i = 1,...,n_\text{eq}\f$ and \f$l_i \in \mathbb{R} \cup \{ -\infty \}\f$ and \f$u_i \in \mathbb{R} \cup \{ +\infty \}, ~\forall i = 1,...,n_\text{in}\f$.
1414

15-
We provide in the file qplayer_sudoku.py an example which enables training LP layer in two different settings: (i) either we learn only the equality constraint matrix \f$A\f$, or (ii) we learn on the same time \f$A\f$ and \f$b\f$, such that \f$b\f$ is structurally in the range space of \f$A\f$. The procedure (i) is harder since a priori the fixed right hand side does not ensure the QP to be feasible. Yet, this learning procedure is more structured, and for some problem can produce better prediction quicker (i.e., in fewer epochs).
15+
We provide in the file `qplayer_sudoku.py` an example which enables training LP layer in two different settings: (i) either we learn only the equality constraint matrix \f$A\f$, or (ii) we learn on the same time \f$A\f$ and \f$b\f$, such that \f$b\f$ is structurally in the range space of \f$A\f$. The procedure (i) is harder since a priori the fixed right hand side does not ensure the QP to be feasible. Yet, this learning procedure is more structured, and for some problem can produce better prediction quicker (i.e., in fewer epochs).
16+
17+
The differentiable QP layer is implemented in \ref proxsuite.torch.qplayer.QPFunction.
1618

1719
\section QPLayerCite How to cite QPLayer ?
1820

@@ -32,4 +34,4 @@ If you are using QPLayer for your work, we encourage you to cite the related pap
3234
}
3335
\endcode
3436

35-
The paper is publicly available in HAL ([ref 04133055](https://inria.hal.science/hal-04133055/file/QPLayer_Preprint.pdf)).
37+
The paper is publicly available in HAL ([ref 04133055](https://inria.hal.science/hal-04133055/file/QPLayer_Preprint.pdf)).

doc/Doxyfile.extra.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
INPUT = @PROJECT_SOURCE_DIR@/doc \
22
@PROJECT_SOURCE_DIR@/include \
3+
@PROJECT_SOURCE_DIR@/bindings/python/proxsuite \
34

45
RECURSIVE = YES
56

0 commit comments

Comments
 (0)