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

### 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:

### 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.

7 Likes

2 posts were split to a new topic: Signomial optimization