cvxpy / cvxpy

A Python-embedded modeling language for convex optimization problems.

Home Page:https://www.cvxpy.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to add new atomic functions

langit opened this issue · comments

Is your feature request related to a problem? Please describe.
When using cvxpy, I encountered the DCP error, though I know for sure my problem is a convex optimization problem. Therefore, I wonder if there is a way to add new atomic functions to cvxpy.

Describe the solution you'd like
It would be ideal to write some python code and declare a new atomic function with certain curvature.

Describe alternatives you've considered
Or maybe provide some documentation on how to do this at a lower level than python.

Additional context
This feature can dramatically widen the range of use for cvxpy.

Hi @langit, can you describe the function you want to model? Sometimes it is possible to rewrite it using existing atoms.

Sure, thanks for asking! It is basically the following:

# x is a vector of 5 variables
# A is a matrix, C is a vector of constants
maximize sum (x[i] * cvxpy.log(1/x[i]) for i in range(5))
s.t.   A x <= C

That solves my problem! Many thanks! @jonathanberthias

By the way, if a class is coded in the same way as cvxpy.entr, does that define a new atomic function?

Wow, it is cool to create an atom. Would it be nice to have everything in one single python file, like the atom class, the “canonicalizers”, and the boilerplate code that can be dynamically propagated to the rest of cvxpy. Just a random thought.