Why isn't CVX accepting my model? READ THIS FIRST!

(Michael C. Grant) #1

If you are here because CVX is rejecting your model, or if you do not know if CVX will accept your model, please read this page before posting a question. Many of the questions posed in this forum are addressed fully by the general answers given here.

I know CVX looks easy to use—we designed it that way—but when used improperly, it’s surprisingly frustrating. So it is extremely important that users understand CVX’s inherent requirements and limitations to avoid wasting time.

In short: using CVX incorrectly is actually worse (for you!) than not using it at all.

The first thing we must ask you is this:

Is your model convex?

No, my model is not convex.

You should not be trying to use CVX. CVX is not a general purpose optimization framework. It is designed specifically for certain kinds of convex optimization problems, as well as certain mixed-integer convex models and geometric programs. If you do not already know that your problem fits into one of CVX’s supported problem classes, then CVX is not the correct tool to use.

I do not know if my model is convex.

Then the answer is the same as above: You should not be using CVX. Save yourself considerable frustration and stop now. CVX is a framework for disciplined convex programming. What that means is that you have to know in advance that your model is convex, and you have to be able to prove that fact by building your model according to a specific set of rules.

CVX is not particularly useful as a convexity verification system. That is, if you do not know that your model is convex, don’t just enter it into CVX “to see what happens”. You really do need to do the advance work yourself.

Yes, I have proved that my model is convex!

Are you sure? Have you rigorously proven that it is convex? Unfortunately, it is very common for people to ask why CVX cannot solve their convex model, only to discover that their model is not actually convex. For example, ratios f(x)/g(x) of affine or convex/concave expressions are almost never convex, and yet countless people have come to this forum and others claiming that they are.

Do not trust your intuition alone on convexity. Prove it. In fact, in order to use CVX, for reasons we explain below, CVX only accepts models that can be proven convex using only the rules in CVX’s DCP ruleset. If you have not yet done that, go do that now and come back to this FAQ.

The paper where I found the model says it is convex.

This is not sufficient. Please do not use CVX until you have thoroughly proven that the model is a convex optimization problem.

It does happen, sometimes, that authors are incorrect. But more commonly, they are imprecise. That is: some models that are claimed to be convex are convex geometrically, but they are not in a standard convex optimization form. For a simple, but contrived example, consider the constraint \lceil x \rceil \geq 1 is not a valid constraint in a convex optimization setting, even though it describes the same interval as the linear inequality x>0. (I’ve not seen this particular example in practice, but I have seen others; e.g., beamforming papers.)

If you are having difficulty proving that a model you found in a paper is convex, please contact the authors to see if you can get clarification. In fact, if they say they’ve solved the problem with CVX themselves, ask them for the code! But please do not try to use CVX until you’ve done so. And please do not ask for help with this here at this forum.

Yes, I am sure my model is convex!

Wonderful. Well done. (I know there’s a “but” coming, though…) What error message did you get?

Matlab returned this error: Function “so-and-so” undefined for objects of type “cvx”.

This is because you’ve tried to use a function that is not on CVX’s list of supported functions. If you cannot express your model in terms of these functions, CVX cannot handle it. It is not straightforward to add new functions to CVX, due to the unique way that it operates; more on this below.

Matlab gave me a “Disciplined convex programming error”.

It is definitely possible to construct convex expressions that violate the DCP ruleset. For instance, consider sqrt(sum(square(x)). This is just a representation of the convex Euclidean norm, but CVX rejects this expression as a violation of the rules. Fortunately, you can just use norm(x) in that case instead.

Similarly, if you want CVX to solve your model, you must find a way to express it in a manner that complies with the DCP ruleset.

But I can’t use the DCP rules alone to prove it; I had to use other principles, like a derivative test or a secant test, as well.

Unfortunately, if you cannot rewrite your model to avoid a DCP error, that means that CVX cannot solve your model. We do not claim that CVX can solve every convex model, and we do not consider this a bug.

Can’t I just tell CVX somehow that my model is convex?

No, you can’t. To understand why, you must understand that the DCP ruleset is not for your benefit. Yes, we want you to be able to prove that your model is convex, and the rules can certainly help. But in fact, the rules are needed by CVX. The real purpose of the rules is that CVX relies upon them to convert problems to a solvable form.

Each individual rule corresponds to a specific step in the process of converting your model into the so-called conic form demanded by SeDuMi, SDPT3, etc. In mathematical terms, each rule corresponds to a specific equivalency- and convexity-preserving transformation. This conversion process is by no means straightforward, as you know if you have tried to do it by hand. We’ve accumulated a library of these transformations in CVX in order to automate that process for you—and each of those steps is tied to one of the DCP rules.

So whether you realize it or not, by ensuring sure that your model is expressed according to the rules, you are giving CVX not just a proof of convexity, but also a recipe for solving your problem. If your model violates the rules, then CVX is unable to construct the necessary transformation. If you want a more technical explanation, please read the papers listed here.

Can I add my convex/concave function to the CVX function library?

Possibly, but it’s not straightforward. We have documented the approach in the advanced section of the users’ guide, Keep in mind that this involves building up a description of the function using the existing set of DCP rules. Unless you are an advanced CVX user, I would not recommend trying this.

Unfortunately, some of CVX’s limitations are dictated by the specific solvers that it targets (SeDuMi, SDPT3, Gurobi, MOSEK, etc.). Even if you were try and bypass CVX completely, you would still find that many problems cannot be handled by these solvers. However, if you have studied up on how CVX represents functions, and you think that there’s a good chance that your function should be compatible with these solvers, go ahead and post it here on the forum!

But my function is smooth. Other modeling systems just let me provide code to compute the function and its derivatives. Why can’t I do that with CVX?

This makes perfect sense for traditional smooth NLP solvers. But in fact, CVX does not consider function derivatives at all. The solvers do not either: they are conic solvers which rely not on functions but on convex cones to describe constraints. CVX uses an entirely different way of describing functions to these conic solvers than the traditional value/derivative-based approach found in a traditional modeling system like AMPL or GAMS. For more information, you’ll need to read one of these papers.

OK, OK, I give! I accept that CVX cannot actually solve my model. But what can I do?

Well, if your model is smooth, a traditional NLP solver, coupled with a traditional modeling framework like AMPL or GAMS, may be useful. YALMIP is a modeling framework in MATLAB that supports both convex and non-convex problems, and it connects to a wider variety of solvers than CVX. So that might be worth a try if you want to stay in MATLAB. And of course, MATLAB has an optimization toolbox of its own. Unfortunately, I do not use any of these tools regularly, so I cannot offer more specific advice.

Cannot perform the operation: {real affine} .* {convex}”
log_sum_exp( {mixed concave/constant} )
Cannot perform the operation: {real affine} ./ {real affine}?!
How can I model the optimization problem in CVX?
Solving an SDP optimization problem
CVX Invalid quadratic form(s): not a square
CVX error, Invalid constraint: {concave} == {real affine}
Cannot perform the operation {convex}*{convex}
How to minimize following function in CVX form
Illegal operation: - {log-concave}
Invalid quadratic form(s): not a square (multiplication variables)
How to achieve myself function?
Finding global extrema of polynomials
Illegal operation: {complex constant} - {convex}
Constraints not accepted by the solver
Linearizing nonlinear mixed-integer constraint
Cannot maximize a(n) log-convex expression error!
Using fminsearch inside a cvx model
DCP error/ Expreesion in objective function must be real
Nonconvex constraint
Eigenvalues in CVX
Invalid constraint problem
Please help for the Invalid constraint
Error using cvx/times (line 262) Disciplined convex programming error: Invalid quadratic form(s): not a square
Disciplined convex programming error:Invalid computation: prod( {convex} )
Invalid constraint: {concave} == {real affine}
SOCP with quadratic inequality constraints
How to deal with $\ell_1$ norm equality constraint?
Formulate problem in CVX and using subgradient algorithm
Newcnstr( evalin( 'caller', 'cvx_problem', '[]' ), x, y, '>=' );
Is the following function convex?
Is the following function convex?
Error in problem forumlation
Logical constraint problem
Least mean square optimimization with a constraint
Matrix Multiplication
Non-Convex fractional quadratic optimization
Gaussian Mixture Model in CVX
Need help with formularizing a problem with matrix quadratic form
Network rate optimization
Pardon our dust!
Unable to use sort function inside CVX
I have tried to solve the following problem. But CVX wouldnt accept the norm constraint
How can I use CVX to solve the following fractional quadratic problem?
HELP! How to solve vector prod in CVX
HELP! How to solve vector prod in CVX
Can CVX solve the equivalent Lagrangian dual of a convex optimization problem?
How can i model x^3/x^2>=-2 constraint in cvx?
Invalid quadratic form: must be a scalar
How to use inv(x) functions in constrain?
How could I solve this problem?
Is it possible to solve for objective function with x.*exp(x+y)+y.*exp(x+y)
How to solve Disciplined convex programming error: Illegal operation: exp( {affine} )
How to make the formulation consistent with the DCP ruleset?
Why does CVX give this error for my model?
Minimizing the norm of an expression containing a hermitian matrix to some power
How to discribe integral ,including parameter,in a function
Constraint error
How to express this concave function in cvx?
Error while solving OP with constraint
How can I solve this problem by cvx solver?
Illegal operation: abs( {concave} )
How should I describe this problem in CVX?
Division used in cvx
How to write this expression in cvx?
Cone programming (xy<=z^2)
Disciplined convex programming error: Matrix powers not permitted
Cannot perform the operation: {real affine} .* {log-affine} in CVX
X/(x+1)^2 convex for x>=2
Sum of sigmoid function and linear function
Ask for help to solve the problem
DCP error:Illegal operation: {log-affine} + {concave}
How to present my convex optimization in a CVX-compliant way
How to write an optimization problem in cvx
Can this OP be solved in CVX?
How to fix the constraint
Supporting vectors of a matrix
Formulating the max min problem in CVX with concave square dinside
log(det(A+Y)/det(Y)) constraint?
Quadratic constraint
Quasiconcave: {CONCAVE}.^2
How to solve or avoid the problem of “{log-affine} .* {concave}”?
Only scalay quadratic forms can be specified in cvs on multiplication of 3 term can i know why is it so?
How can I minimize the following term taking alpha and beta as variables
How can formulate difference between to variable
Problems with the pow_p and a convex input x - need help for alternative representation
Is it possible to use sin or cos in cvx?
Curve fitting with two exponential functions
Undefined function 'find' for input arguments of type 'cvxcnst'
If-else constraints in CVX
How to use "external" MATLAB functions in CVX?
How to express x(1)^2+x(2)^2=y^2?
How to express x*log(y)
How to do matrix inverse in CVX
How to solve "Cannot perform the operation: {convex} .* {real affine}"
Error using cvx/times: Invalid quadratic form(s): not a square
How to describe the constraints for all values ​​in the domain?
What can I do about the Disciplined convex programming error?
How to add the constraints $trace(power(z,2))==1$ in cvx sdp problem, where z is a matrix?
New to CVX and MatLab
Simulated annealing with equality constrainsts
Quadratic constraint of a matrix is not allowed in cvx?
How to solve a [non-]convex problem with multiple scalar and matrix variables
Disciplined convex programming error:{concave} == {constant}
Please help me to fix the problem
Solve problem with cvx
Use cvx to check a function is convex or not
Finding an optimum value of $x$ using CVX
CVX error in using pow_cvx
About function of log,can't solve
Error in performing integration
Solving Reciprocal of Concave
Invalid operation: {positive convex} - {positive convex}
How can I solve log(normalcdf(a-x)-normalcdf(b-x)) with cvx
Is it a convex problem? Could it be solved by cvx?
Illegal operation: log( {convex} ) how to deal with this kind of operation, please give me a favor
Cannot perform the operation: constant complex affine .* convex
How to divide real affine matrix by real affine scalar?
Maximizing polynomial
DCP error: Only scalar quadratic forms can be specified in CVX
Problem: Invalid quadratic form(s): not a square
Cannot perform the operation: {concave} ./ {concave}
How to deal with this convex problem by cvx
The second argument must be positive or negative semidefinite for convex objective function
Constraint on the product of two variable matrices
How to solve minimization problem with unconvex constrains as follows with cvx
Infinity norm minimization
Multiple Variables in Objective Function
Can anyone help me on this constraint? Many thanks!
Why does CVX accept log(2^exp(x)) but don't accept log(2^exp(x)-1)
How can I solve maximum probability program?
Why isn't cvx accepting $log(x^t*A*x)$, where A is positive definite?
Is there any form to implement the matrix multiplied by its own conjugate transpose
Can anyone help me with this problem?
Error using .* (line 262) Disciplined convex programming error: Invalid quadratic form(s): not a square
Multiply two variables
Invalid quadratic form(s): not a square error
Invalid quadratic form(s): not a square error
Norm of non-separable bilinear term
Disciplined convex programming:
How to implement following objective function by using cvx?
Question on Rank Constraint
How to write following objective in matlab using CVX?
Maximizing linear function over convex set
Maximizing polynomial
Time delay of estimation
Time delay of estimation
"Error using cvx / prod (line 84) Disciplined convex programming error: Invalid computation: prod ({convex}) "
Minimization of losses of dc-dc boost converter
Minimization of losses of dc-dc boost converter
Simple quadratic sequence makes Invalid quadratic form(s): not a square. error
Invalid quadratic forms: not a square
Cannot perform the operation: {real affine} ./ {real affine}?!
Cannot perform the operation {convex}*{affine} and Only scalar quadratic forms can be specified in CVX
Problem with nonlinear lmi in cvx
Question about defining formula in the cvx
Disciplined convex programming error: Invalid constraint: {convex} <= {convex}
Disciplined convex programming error: Invalid constraint: {convex} <= {convex}
Error : {invalid} .* {convex}
Problem in cvx with log2 function?
How can calculation this problem
Is convex or not convex problem?
Ask for a help about the cvx's error
Require some help in solving an optimization plb
Can we minimize a scalar like x'Ay?
Log( {positive convex} )
How to express exp(x).*log(1+exp(y).*inv_pos(z))?
How can i solve this problem by CVX?
How can i solve this problem by CVX?
Can I write this ( xy + xz +yz <1 ) as a SOCP?
CVX Diciplined errot
CVX Diciplined errot
DCP-compliant way to scale by sum(x)?
How to solve this LMI
Illegal operation: {invalid} + {mixed real affine/constant}
How to solve this optimization problem? Thanks!
Algebraic Riccati Equation in cvx
How to write this fomula into CVX expression?
CVX error in using inv_pos
Cannot perform the operation norm( {convex}, 2 )
Need help to reformulate Projectile Motion to a convex problem
Disciplined convex programming error: Cannot perform the operation: {real affine} .* {convex}
Disciplined convex programming error: Cannot perform the operation: {real affine} .* {convex}
DCP convex programming error: Only scalar quadratic forms can be specified in CVX
DCP convex programming error: Only scalar quadratic forms can be specified in CVX
How do I change these 2 equations to ensure the problem is convex and fits into CVX
How can I write this kind of constraint in cvx
Optimization involving the inverse of an SDP matrix
How to express the following function in cvx
Solving maximize( quad_form(x,P)) ) subject to norm(x,2)<=N
First kind of fredholm equation Ax=b than
How to express "t*e^(x/t)-t" in CVX?
Cannot perform the operation: {real affine} ./ {real affine}
How solve this optimization problem using cvx solve?
How solve this optimization problem using cvx solve?
Log operation with "Error: Invalid quadratic form(s): not a square"
Convex or nonconvex problem
How to solve the error Only scalar quadratic forms can be specified in CVX
Why can't the code run if i just modify some variable and formula?
Shannon Capacity formula (Disciplined convex programming error)
Why can't the code run if i just modify some variable and formula?
How can CVX maximize -sum_(i,j) x(i,j)*log(sum_j x(i,j))?
Disciplined convex programming error
Multiplying two variables
How to formulate the eigenvalue maximization problem in CVX
Linear fraction with SDP
Comparison on variables
Does this problem is a SDP? How to solve it?
Help to formulate
How to solve an optimization problem with non-convex constraint
Log matrix cvx
How to formulate this optimization problem
Error using double Conversion to double from cvx is not possible
Convex function or not?
Convex constraint rejected
Cannot perform the operation norm( {mixed convex/affine}, 2 )
How to express `minimize $trace(\sqrt{X'X}A)$` by CVX?
How to express this objective function in CVX
How to express this objective function in CVX
Invalid operation error: log ({positive convex})
(Mark L. Stone) #16

(Mark L. Stone) #17

How to rewrite this constraint function subject to DCP rules?
(Michael C. Grant) #18

2 posts were split to a new topic: Signomial optimization

(Michael C. Grant) #20

Can I use CVX to solve the problem which use function trace?
Expressing shannon capacity in CVX
Help with CVX DCP rule
How can I solve maximum probability program?
Disciplined convex programming error: Invalid constraint: {convex} <= {convex}
Error when using cov function in CVX
Log{convex} log(1+1/(1+x))
Integer linear programming in CVX
CVX wrong. How can I deal with this problem correctly?
Minimization of losses of dc-dc boost converter