Skip to content

Commit 5b3eb31

Browse files
Transurgeonclaude
andcommitted
Update NLP initial point tests to use _set_nlp_initial_point
Tests now import and call the module-level helper directly instead of the removed Problem.set_NLP_initial_point() method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c6166a commit 5b3eb31

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

cvxpy/tests/nlp_tests/test_problem.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,79 @@
22
import numpy as np
33

44
import cvxpy as cp
5+
from cvxpy.reductions.solvers.nlp_solving_chain import _set_nlp_initial_point
56

67

78
class TestProblem():
89
"""
9-
This class can be used to test internal function for Problem that have been added
10+
This class can be used to test internal function for Problem that have been added
1011
in the DNLP extension.
1112
"""
1213

1314
def test_set_initial_point_both_bounds_infinity(self):
1415
# when both bounds are infinity, the initial point should be zero vector
15-
16+
1617
# test 1
1718
x = cp.Variable((3, ))
1819
prob = cp.Problem(cp.Minimize(cp.sum(x)))
19-
prob.set_NLP_initial_point()
20+
_set_nlp_initial_point(prob)
2021
assert (x.value == np.zeros((3, ))).all()
2122

2223
# test 2
2324
x = cp.Variable((3, ), bounds=[None, None])
2425
prob = cp.Problem(cp.Minimize(cp.sum(x)))
25-
prob.set_NLP_initial_point()
26+
_set_nlp_initial_point(prob)
2627
assert (x.value == np.zeros((3, ))).all()
2728

2829
# test 3
2930
x = cp.Variable((3, ), bounds=[-np.inf, np.inf])
3031
prob = cp.Problem(cp.Minimize(cp.sum(x)))
31-
prob.set_NLP_initial_point()
32+
_set_nlp_initial_point(prob)
3233
assert (x.value == np.zeros((3, ))).all()
3334

3435
# test 4
3536
x = cp.Variable((3, ), bounds=[None, np.inf])
3637
prob = cp.Problem(cp.Minimize(cp.sum(x)))
37-
prob.set_NLP_initial_point()
38+
_set_nlp_initial_point(prob)
3839
assert (x.value == np.zeros((3, ))).all()
3940

4041
# test 5
4142
x = cp.Variable((3, ), bounds=[-np.inf, None])
4243
prob = cp.Problem(cp.Minimize(cp.sum(x)))
43-
prob.set_NLP_initial_point()
44+
_set_nlp_initial_point(prob)
4445
assert (x.value == np.zeros((3, ))).all()
4546

46-
47+
4748
def test_set_initial_point_lower_bound_infinity(self):
4849
# when one bound is infinity, the initial point should be one unit
4950
# away from the finite bound
5051

5152
# test 1
5253
x = cp.Variable((3, ), bounds=[None, 3.5])
5354
prob = cp.Problem(cp.Minimize(cp.sum(x)))
54-
prob.set_NLP_initial_point()
55+
_set_nlp_initial_point(prob)
5556
assert (x.value == 2.5 * np.ones((3, ))).all()
5657

5758
# test 2
5859
x = cp.Variable((3, ), bounds=[-np.inf, 3.5])
5960
prob = cp.Problem(cp.Minimize(cp.sum(x)))
60-
prob.set_NLP_initial_point()
61+
_set_nlp_initial_point(prob)
6162
assert (x.value == 2.5 * np.ones((3, ))).all()
62-
63+
6364
def test_set_initial_point_upper_bound_infinity(self):
6465
# when one bound is infinity, the initial point should be one unit
6566
# away from the finite bound
6667

6768
# test 1
6869
x = cp.Variable((3, ), bounds=[3.5, None])
6970
prob = cp.Problem(cp.Minimize(cp.sum(x)))
70-
prob.set_NLP_initial_point()
71+
_set_nlp_initial_point(prob)
7172
assert (x.value == 4.5 * np.ones((3, ))).all()
7273

7374
# test 2
7475
x = cp.Variable((3, ), bounds=[3.5, np.inf])
7576
prob = cp.Problem(cp.Minimize(cp.sum(x)))
76-
prob.set_NLP_initial_point()
77+
_set_nlp_initial_point(prob)
7778
assert (x.value == 4.5 * np.ones((3, ))).all()
7879

7980
def test_set_initial_point_both_bounds_finite(self):
@@ -83,34 +84,34 @@ def test_set_initial_point_both_bounds_finite(self):
8384
# test 1
8485
x = cp.Variable((3, ), bounds=[3.5, 4.5])
8586
prob = cp.Problem(cp.Minimize(cp.sum(x)))
86-
prob.set_NLP_initial_point()
87+
_set_nlp_initial_point(prob)
8788
assert (x.value == 4.0 * np.ones((3, ))).all()
8889

8990
def test_set_initial_point_mixed_inf_and_finite(self):
9091
lb = np.array([-np.inf, 3.5, -np.inf, -1.5, 2, 2.5])
9192
ub = np.array([-4, 4.5, np.inf, 4.5, np.inf, 4.5])
9293
x = cp.Variable((6, ), bounds=[lb, ub])
9394
prob = cp.Problem(cp.Minimize(cp.sum(x)))
94-
prob.set_NLP_initial_point()
95+
_set_nlp_initial_point(prob)
9596
expected = np.array([-5, 4.0, 0.0, 1.5, 3, 3.5])
9697
assert (x.value == expected).all()
9798

9899
def test_set_initial_point_two_variables(self):
99100
x = cp.Variable((2, ), bounds=[-np.inf, np.inf])
100101
y = cp.Variable((2, ), bounds=[-3, np.inf])
101102
prob = cp.Problem(cp.Minimize(cp.sum(x) + cp.sum(y)))
102-
prob.set_NLP_initial_point()
103+
_set_nlp_initial_point(prob)
103104
assert (x.value == np.zeros((2, ))).all()
104105
assert (y.value == -2 * np.ones((2, ))).all()
105106

106107
def test_set_initial_point_nonnegative_attributes(self):
107108
x = cp.Variable((2, ), nonneg=True)
108109
prob = cp.Problem(cp.Minimize(cp.sum(x)))
109-
prob.set_NLP_initial_point()
110+
_set_nlp_initial_point(prob)
110111
assert (x.value == np.ones((2, ))).all()
111112

112113
def test_set_initial_point_nonnegative_attributes_and_bounds(self):
113114
x = cp.Variable((2, ), nonneg=True, bounds=[1, None])
114115
prob = cp.Problem(cp.Minimize(cp.sum(x)))
115-
prob.set_NLP_initial_point()
116-
assert (x.value == 2 * np.ones((2, ))).all()
116+
_set_nlp_initial_point(prob)
117+
assert (x.value == 2 * np.ones((2, ))).all()

0 commit comments

Comments
 (0)