You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
update atom documentation - state required cone types #574
Clearly, we could equivalently formulate the problem as a QP
import numpy as np
prob2 = cv.Problem(cv.Minimize(cv.quad_form(u, np.eye(2))), constr)
Right now if a user tries to call prob1.solve(solver='OSQP'), they will get a solver error.
This is okay from a correctness standpoint, since an SOCP and a QP are different mathematical objects from a duality perspective. Also users have the recourse to manually reformulate as in prob2 if they really want the QP-only solver.
However it would be very nice if cvxpy automatically performed the reduction from SOCP to QP when a user specifies a QP-only solver.
If cvxpy's goal is to make convex optimization more accessible, then this is a good enhancement. Taking the position that norm shouldn't work with a quadratic programming solver is likely confusing to newcomers because they would assume it's just solving min ||u||^2 underneath, as this is how least squares is taught to undergraduates. Reformulating with the sum_squares atom is one option, but quad_form might be a bit obscure to newcomers. New users would expect cvxpy to perform whatever transformations are "best", and not want to second guess which atoms to use.
cvxpy has gotten complicated, it's true. It's more modular than it appears, but probably less accessible than before. The solver interfaces are more ad hoc now. Having one way of representing solver information wasn't working. I don't work personally on the commercial solver interfaces. Those are contributed by others, which is working fine for now. It would be well worth cleaning out all the legacy solver interfaces so the approach is clearer.
In terms of this issue, if we were to add SOCP to QP conversion I would not do it in an ad hoc way such as by catching norm2, converting it to sum_squares, but catching all possible cases. People in Boyd's group have looked at this and it's somewhat involved. I guess we can keep this issue open, but it's not something I see getting into cvxpy any time soon.
@enzobusseti the C++ code present in cvxpy 1.0 was already present in cvxpy 0.4, just under a different name (cvxcanon instead of cvxcore). The long-term plan is to remove the dependence on cvxcore and make a different high-speed backend designed only with cvxpy in mind. However for now, it is simply not possible to "branch cvxpy 0.4 and make cvxpy 2.0 without C++".
On a second note- It's not clear to me how or where commercial solvers entered the design process for cvxpy 1.0. Certainly cvxpy 1.0 was not written in a way that made it easy for me to write the 1.0 MOSEK interface, and the CPLEX interface is currently a 1.0 wrapper around an old 0.4-style interface. It is true that cvxpy 1.0 is written with a less-specific canonical form in mind (relative to 0.4), but that generality has nothing to do with any one solver. YALMIP similarly has flexible problem representations and supports a huge range of commercial and open-source solvers.
All the above said, I have done more thinking about SOCP to QP conversion and I realize now where the problem lies.
Here's one way to look at it: It can be shown that supporting the second-order cone is equivalent to supporting constraints of the form y.T * Q * y <= 0 where Q is a fixed matrix with at most one negative eigenvalue. QP solvers support constraints like x.T * A * x + 2 * b.T * x + c <= 0, for PSD A. This can be written in block-form as [[x], [1]].T * [ [A, b], [b.T, c] ] * [ [x], [1] ] <= 0. The block matrix [[A, b], [b.T, c]] indeed has at most one negative eigenvalue, but the block vector [[x], [1]] necessarily has the final entry fixed to 1. There isn't a way for a QP-only solver to allow that 1 in the block vector to take on the range of values needed for an SOCP.
Here is another way to look at it: start with the scalar function x ** 2. The sub-level sets of the perspective of this function are { (x,y,z) : x ** 2 <= y * z, y >= 0 }. This set is precisely the "rotated second order cone" in R^3. We cannot expect a QP solver to accommodate perspective functions of x ** 2, any more than we can expect a solver supporting log(x) to accommodate the relative entropy function (which is essentially the perspective of the negative logarithm).
This is all to say: an SOCP with nontrivial linear term (a-la || A * x || + b.T * x + c <= 0 with b != 0) cannot be modeled solely in terms of linear (in)equalities, and sublevel sets of PSD quadratic forms. And as a result, SOCPs with nontrivial linear terms cannot be parsed into equivalent problems for QP-only solvers.
In view of these fundamental obstacles, I am now open to closing this issue.
It would make sense to re-open the issue if there was a "QP" solver that supported constraints of the form y.T * Q * y <= 0 when Q has at most one negative eigenvalue, but until someone writes such a solver, there is nothing to be done on cvxpy's end.
For now, it simply might make sense to update the documentation for OSQP with cvxpy, to make sure that people use the sum_squares atom instead of norm when working with OSQP. (I think this is worth doing, since users might otherwise fall back on quad_form, which is far less efficient than sum_squares).
@rileyjmurray I agree with the last point. Also, an easy solution could be to write a more descriptive error when the user tries to solve with OSQP a problem with norm(u) in the objective mentioning that it could be rewritten with sum_squares.
I'm reworking the documentation a bit. Rather than saying "use quad_form when working with OSQP" (which is very specific and didn't really have a natural place to mention), I added a column on the Atomic Functions table indicating the solver capabilities needed for the constraint. See here for the updated page.
For example, log_det clearly states that the domain is PSD matrices, but it omits the fact that the solver also needs the exponential cone. In other cases, the Frobenius norm of a matrix is SOCP-representable, while the nuclear norm requires an SDP. The issue discussed in this thread is resolved by marking the vector-norm as an SOCP representable atom, and sum_squares as an SOCP or QP representable atom.
I did use the facts that (1) all LPs are compatible with SOCP, QP, and EXP solvers, and (2) all SOCPs are compatible with SDP solvers.
The new column in the documentation helps a lot I think. Might also be good for newcomers to see at the top of the table your facts (1) and (2), possibly in the form of containment: LP <= QP <= SOCP etc
@rileyjmurray I missed your update to the atoms table. This makes a lot of sense, and is similar to the Convex.jl documentation. I guess I left it out before because we only had cone programs, and I didn't think users would understand.
@enzobusseti thanks for clarifying. cvxpy can always be improved, substantially in some ways, but I don't have the time and energy that I used to have for such large alterations.
Started mapping cone requirements across a sample of atoms by tracing their canonicalizers in dcp2cone/canonicalizers/ (and dgp2dcp/ where relevant):
quad_over_lin → SOC
pnorm (p=2) → SOC; (p≠2) → PowCone3D
log_det → PSD + ExpCone (via LDL factorization)
geo_mean → no cone directly; it is handled as an affine expression in the DGP2DCP log-domain reduction rather than through DCP2Cone
I’m planning to go through the rest of cvxpy/atoms/ in the same way. Before scaling this up, would you prefer the result as static documentation (e.g. a table in the atoms reference), or as an inspectable attribute/method on each atom class (e.g. atom.required_cones())?
Activity
rileyjmurray commentedon Sep 2, 2018
I also said that it is correct as stands; that is why I used the "enhancement" label.
This may be a "long standing issue", but it's one that shouldn't be too hard to resolve in the context of cvxpy 1.0's reduction system.
wkschwartz commentedon Sep 12, 2018
If cvxpy's goal is to make convex optimization more accessible, then this is a good enhancement. Taking the position that
normshouldn't work with a quadratic programming solver is likely confusing to newcomers because they would assume it's just solvingmin ||u||^2underneath, as this is how least squares is taught to undergraduates. Reformulating with thesum_squaresatom is one option, butquad_formmight be a bit obscure to newcomers. New users would expect cvxpy to perform whatever transformations are "best", and not want to second guess which atoms to use.SteveDiamond commentedon Sep 15, 2018
cvxpy has gotten complicated, it's true. It's more modular than it appears, but probably less accessible than before. The solver interfaces are more ad hoc now. Having one way of representing solver information wasn't working. I don't work personally on the commercial solver interfaces. Those are contributed by others, which is working fine for now. It would be well worth cleaning out all the legacy solver interfaces so the approach is clearer.
In terms of this issue, if we were to add SOCP to QP conversion I would not do it in an ad hoc way such as by catching norm2, converting it to sum_squares, but catching all possible cases. People in Boyd's group have looked at this and it's somewhat involved. I guess we can keep this issue open, but it's not something I see getting into cvxpy any time soon.
rileyjmurray commentedon Sep 17, 2018
@enzobusseti the C++ code present in cvxpy 1.0 was already present in cvxpy 0.4, just under a different name (cvxcanon instead of cvxcore). The long-term plan is to remove the dependence on cvxcore and make a different high-speed backend designed only with cvxpy in mind. However for now, it is simply not possible to "branch cvxpy 0.4 and make cvxpy 2.0 without C++".
On a second note- It's not clear to me how or where commercial solvers entered the design process for cvxpy 1.0. Certainly cvxpy 1.0 was not written in a way that made it easy for me to write the 1.0 MOSEK interface, and the CPLEX interface is currently a 1.0 wrapper around an old 0.4-style interface. It is true that cvxpy 1.0 is written with a less-specific canonical form in mind (relative to 0.4), but that generality has nothing to do with any one solver. YALMIP similarly has flexible problem representations and supports a huge range of commercial and open-source solvers.
rileyjmurray commentedon Sep 17, 2018
All the above said, I have done more thinking about SOCP to QP conversion and I realize now where the problem lies.
Here's one way to look at it: It can be shown that supporting the second-order cone is equivalent to supporting constraints of the form
y.T * Q * y <= 0whereQis a fixed matrix with at most one negative eigenvalue. QP solvers support constraints likex.T * A * x + 2 * b.T * x + c <= 0, for PSDA. This can be written in block-form as[[x], [1]].T * [ [A, b], [b.T, c] ] * [ [x], [1] ] <= 0. The block matrix[[A, b], [b.T, c]]indeed has at most one negative eigenvalue, but the block vector[[x], [1]]necessarily has the final entry fixed to 1. There isn't a way for a QP-only solver to allow that1in the block vector to take on the range of values needed for an SOCP.Here is another way to look at it: start with the scalar function
x ** 2. The sub-level sets of the perspective of this function are{ (x,y,z) : x ** 2 <= y * z, y >= 0 }. This set is precisely the "rotated second order cone" in R^3. We cannot expect a QP solver to accommodate perspective functions ofx ** 2, any more than we can expect a solver supportinglog(x)to accommodate the relative entropy function (which is essentially the perspective of the negative logarithm).This is all to say: an SOCP with nontrivial linear term (a-la
|| A * x || + b.T * x + c <= 0withb != 0) cannot be modeled solely in terms of linear (in)equalities, and sublevel sets of PSD quadratic forms. And as a result, SOCPs with nontrivial linear terms cannot be parsed into equivalent problems for QP-only solvers.In view of these fundamental obstacles, I am now open to closing this issue.
y.T * Q * y <= 0whenQhas at most one negative eigenvalue, but until someone writes such a solver, there is nothing to be done on cvxpy's end.sum_squaresatom instead ofnormwhen working with OSQP. (I think this is worth doing, since users might otherwise fall back onquad_form, which is far less efficient thansum_squares).bstellato commentedon Sep 17, 2018
@rileyjmurray I agree with the last point. Also, an easy solution could be to write a more descriptive error when the user tries to solve with OSQP a problem with
norm(u)in the objective mentioning that it could be rewritten withsum_squares.rileyjmurray commentedon Oct 1, 2018
I'm reworking the documentation a bit. Rather than saying "use quad_form when working with OSQP" (which is very specific and didn't really have a natural place to mention), I added a column on the
Atomic Functionstable indicating the solver capabilities needed for the constraint. See here for the updated page.For example,
log_detclearly states that the domain is PSD matrices, but it omits the fact that the solver also needs the exponential cone. In other cases, the Frobenius norm of a matrix is SOCP-representable, while the nuclear norm requires an SDP. The issue discussed in this thread is resolved by marking the vector-norm as an SOCP representable atom, andsum_squaresas an SOCP or QP representable atom.I did use the facts that (1) all LPs are compatible with SOCP, QP, and EXP solvers, and (2) all SOCPs are compatible with SDP solvers.
wkschwartz commentedon Oct 1, 2018
The new column in the documentation helps a lot I think. Might also be good for newcomers to see at the top of the table your facts (1) and (2), possibly in the form of containment: LP <= QP <= SOCP etc
[-]add reduction transforming SOCPs to QPs[/-][+]update atom documentation - state required cone types[/+]SteveDiamond commentedon Oct 29, 2018
@rileyjmurray I missed your update to the atoms table. This makes a lot of sense, and is similar to the Convex.jl documentation. I guess I left it out before because we only had cone programs, and I didn't think users would understand.
@enzobusseti thanks for clarifying. cvxpy can always be improved, substantially in some ways, but I don't have the time and energy that I used to have for such large alterations.
sakshi2433 commentedon Sep 11, 2026
Started mapping cone requirements across a sample of atoms by tracing their canonicalizers in
dcp2cone/canonicalizers/(anddgp2dcp/where relevant):quad_over_lin→ SOCpnorm(p=2) → SOC; (p≠2) → PowCone3Dlog_det→ PSD + ExpCone (via LDL factorization)geo_mean→ no cone directly; it is handled as an affine expression in the DGP2DCP log-domain reduction rather than through DCP2ConeI’m planning to go through the rest of
cvxpy/atoms/in the same way. Before scaling this up, would you prefer the result as static documentation (e.g. a table in the atoms reference), or as an inspectable attribute/method on each atom class (e.g.atom.required_cones())?