Skip to content

Commit a530fba

Browse files
committed
testing reduction and it seems to work!
1 parent 2e8cd8e commit a530fba

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

cvxpy/atoms/atom.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def is_atom_log_log_affine(self) -> bool:
154154
"""
155155
return self.is_atom_log_log_concave() and self.is_atom_log_log_convex()
156156

157+
def is_atom_smooth(self) -> bool:
158+
pass
159+
157160
@abc.abstractmethod
158161
def is_incr(self, idx) -> bool:
159162
"""Is the composition non-decreasing in argument idx?
@@ -212,6 +215,12 @@ def is_dpp(self, context='dcp') -> bool:
212215

213216
def is_smooth(self) -> bool:
214217
"The expression is smooth"
218+
if self.is_constant():
219+
return True
220+
elif self.is_smooth_atom(self):
221+
for idx, arg in enumerate(self.args):
222+
if not arg.is_smooth():
223+
return False
215224
return True
216225

217226
@perf.compute_once

cvxpy/reductions/expr2smooth/canonicalizers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
"""
1616
from cvxpy.atoms import maximum
17-
from cvxpy.reductions.expr2smooth.canonicalizers import maximum_canon
17+
from cvxpy.reductions.expr2smooth.canonicalizers.maximum_canon import maximum_canon
1818

1919
CANON_METHODS = {
2020
maximum : maximum_canon,

cvxpy/reductions/expr2smooth/expr2smooth.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
from typing import Tuple
1818

19+
import cvxpy as cp
1920
from cvxpy import problems
2021
from cvxpy.expressions.expression import Expression
21-
from cvxpy.problems.objective import Minimize
2222
from cvxpy.reductions.canonicalization import Canonicalization
2323
from cvxpy.reductions.expr2smooth.canonicalizers import CANON_METHODS as smooth_canon_methods
2424
from cvxpy.reductions.inverse_data import InverseData
@@ -36,8 +36,8 @@ def __init__(self, problem=None, quad_obj: bool = False) -> None:
3636
self.quad_obj = quad_obj
3737

3838
def accepts(self, problem):
39-
"""A problem is accepted if it is a minimization."""
40-
return type(problem.objective) == Minimize
39+
"""A problem is always accepted"""
40+
return True
4141

4242
def apply(self, problem):
4343
"""Converts an expr to a smooth program"""
@@ -108,3 +108,19 @@ def canonicalize_expr(self, expr, args, affine_above: bool) -> Tuple[Expression,
108108
return self.smooth_canon_methods[type(expr)](expr, args)
109109

110110
return expr.copy(args), []
111+
112+
def example_max():
113+
# Define variables
114+
x = cp.Variable(1)
115+
y = cp.Variable(1)
116+
117+
objective = cp.Minimize(-cp.maximum(x,y))
118+
119+
constraints = [x - 14 == 0, y - 6 == 0]
120+
121+
problem = cp.Problem(objective, constraints)
122+
return problem
123+
124+
prob = example_max()
125+
new_problem, inverse = Expr2smooth(prob).apply(prob)
126+
print(new_problem)

0 commit comments

Comments
 (0)