Skip to content

Commit 1b3824e

Browse files
authored
fix error message if sample bounds are not set (#161)
1 parent 92fae4c commit 1b3824e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

cvxpy/reductions/solvers/nlp_solving_chain.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ def _set_random_nlp_initial_point(problem, run, user_initials):
132132
var.value = None
133133

134134
# Determine effective sample bounds: use explicit sample_bounds if set,
135-
# otherwise fall back to variable bounds if both are finite.
135+
# otherwise fall back to variable bounds.
136136
sb = var.sample_bounds
137137
if sb is None:
138-
lb, ub = var.get_bounds()
139-
if np.all(np.isfinite(lb)) and np.all(np.isfinite(ub)):
140-
sb = (lb, ub)
141-
142-
# Sample initial value if effective sample bounds are available
138+
sb = var.get_bounds()
139+
140+
# Sample initial value if effective sample bounds are available. Otherwise
141+
# raise an error.
143142
if sb is not None:
144143
low, high = sb
145144
if not np.all(np.isfinite(low)) or not np.all(np.isfinite(high)):
146145
raise ValueError(
147-
"Variable %s has non-finite sample_bounds %s. Cannot generate"
146+
"Variable %s has non-finite sample_bounds. Cannot generate"
148147
" random initial point. Either add sample bounds or set the value. "
149-
% (var.name(), sb)
148+
" You can add sample bounds via var.sample_bounds = (low, high)."
149+
% (var.name())
150150
)
151151

152152
initial_val = np.random.uniform(low=low, high=high, size=var.shape)

0 commit comments

Comments
 (0)