Open jewillco opened 1 year ago
Hi!
Indeed, BoxOSQP
formulation does not make sense without equality constraints.
I recall below the formulation solved by OSQP:
$$\min_x \frac{1}{2}x^TQx+c^Tx\text{ s.t }l\leq Ax\leq u.$$
I recall the API:
params_obj
contains either (Q, c)
, either (params_Q,c)
where params_Q
is the parameters of the matvec
, either params_fun
which are the parameters of a function fun
promised to be quadratic.l
and u
, you must specify A
, otherwise the problem doesn't have any sense. Check the docparams_eq
contains either A
, either (params_A)
where params_A
is the parameters of the matvec
I am not sure what was your intent by not specifying A
. Did you expect the identity function? Then use matvec_A=(lambda _, x: x)
and pass params_eq=None
.
I did get confused on the API, but I would not have expected a crash like that. Would a better error message be possible? Also, does the problem formulation with an arbitrary $A$ mean that this can handle an arbitrary set of linear constraints, not just a box?
Also, does the problem formulation with an arbitrary mean that this can handle an arbitrary set of linear constraints, not just a box?
Yes, it is the most general formulation that one can think of. Maybe you are more familiar with:
$$\min_x\frac{1}{2}x^TQx+c^Tx\text{ s.t }Ax=b,Gx\leq h$$
Now, observe that:
$$Ax=b\implies b\leq Ax\leq b$$
and
$$Gx\leq h\implies -\infty\leq Gx\leq h$$
so you can implement it as:
def matvec_A_boxosqp(params_A, x):
A, G = params_A
return A @ x, G @ x
l = (b, jnp.full(shape=h.shape, fill_value=-float('inf')))
u = (b, h)
params_ineq = (l, u)
params_eq = (A, G)
solver = BoxOSQP(matvec_A=matvec_A_boxosqp)
init_params = solver.init_params(init_x=init_x)
solver.run(init_params, params_obj=(Q, c), params_eq=params_eq, params_ineq=params_ineq)
This reduction between problem formulations is performed automatically in OSQP
solver, but its API is higher level so it is less flexible.
Would a better error message be possible?
I agree we should improve the readability of errors messages.
What I was trying to get at is to determine whether that means that arbitrary linear constraints are supported, not just box constraints. Does that mean this class is a full QP solver, and not just for box-constrained problems?
Does that mean this class is a full QP solver, and not just for box-constrained problems?
Yes, it is! Just like the original's one: https://osqp.org/
Trying to run:
produces an error (some parts redacted):