Skip to content

Commit 5b42601

Browse files
committed
div canon stuff
1 parent 5097446 commit 5b42601

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cvxpy/reductions/expr2smooth/canonicalizers/div_canon.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@
1616

1717
from cvxpy.expressions.variable import Variable
1818

19-
19+
# We canonicalize div(x, y) as z * y = x.
2020
def div_canon(expr, args):
21-
denom = Variable(args[1].shape)
22-
if args[1].value is not None:
23-
denom.value = args[1].value
21+
# TODO: potential bounds here?
22+
# TODO: wrong dimension for z here
23+
z = Variable(args[1].shape)
24+
y = Variable(args[1].shape, bounds=[0, None])
25+
26+
if args[1].value is not None and args[1].value != 0.0:
27+
y.value = args[1].value
28+
else:
29+
y.value = expr.point_in_domain()
30+
31+
if args[0].value is not None:
32+
z.value = args[0].value / y.value
2433
else:
25-
denom.value = expr.point_in_domain()
26-
return expr.copy([args[0], denom]), [denom == args[1]]
34+
z.value = expr.point_in_domain()
35+
# TODO: should we also include y >= 0 here?
36+
return z, [z * y == args[0], y == args[1]]#], #y >= 0, z >= 0]

cvxpy/reductions/solvers/nlp_solvers/ipopt_nlpif.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def solve_via_data(self, data, warm_start: bool, verbose: bool, solver_opts, sol
153153
)
154154
nlp.add_option('mu_strategy', 'adaptive')
155155
nlp.add_option('tol', 1e-7)
156+
nlp.add_option('honor_original_bounds', 'yes')
156157
nlp.add_option('hessian_approximation', "limited-memory")
157158
_, info = nlp.solve(x0)
158159
return info

cvxpy/tests/test_nlp_solvers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ def test_mle(self):
9090
np.random.seed(1234)
9191
data = np.random.randn(n)
9292

93-
mu = cp.Variable(name="mu")
94-
mu.value = np.array(0.0)
95-
sigma = cp.Variable(name="sigma")
96-
sigma.value = np.array(1.0)
93+
mu = cp.Variable((1, ), name="mu")
94+
mu.value = np.array([0.0])
95+
sigma = cp.Variable((1, ), name="sigma")
96+
sigma.value = np.array([1.0])
9797

9898
constraints = [mu == sigma**2]
9999
residual_sum = cp.sum_squares(data - mu)

0 commit comments

Comments
 (0)