Skip to content

Commit a1ddcbb

Browse files
nbelakovskizaikunzhang
authored andcommitted
Minor PR feedback
1 parent 60add9d commit a1ddcbb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pyprima/src/pyprima/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,12 @@ def scalar_fun(x):
131131
tol = get_arrays_tol(lb, ub)
132132
_fixed_idx = (
133133
(lb <= ub)
134-
& (np.abs(lb - ub) < tol)
134+
& (ub <= lb + tol)
135135
)
136136
if any(_fixed_idx) and not all(_fixed_idx):
137+
# We should NOT reduce the problem if all variables are fixed. Otherwise, Aineq would be [], and
138+
# then bineq will be set to [] in the end. In this way, we lose completely the information in
139+
# these constraints. Consequently, we cannot evaluate the constraint violation correctly when needed.
137140
_fixed_values = 0.5 * (
138141
lb[_fixed_idx] + ub[_fixed_idx]
139142
)
@@ -246,7 +249,7 @@ def calcfc(x):
246249
)
247250

248251
if any(_fixed_idx):
249-
newx = np.zeros(lenx0)
252+
newx = np.zeros(lenx0) + np.nan
250253
newx[_fixed_idx] = _fixed_values
251254
newx[~_fixed_idx] = result.x
252255
result.x = newx

python/prima/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ def minimize(fun, x0, args=(), method=None, bounds=None, constraints=(), callbac
124124
tol = get_arrays_tol(lb, ub)
125125
_fixed_idx = (
126126
(lb <= ub)
127-
& (np.abs(lb - ub) < tol)
127+
& (ub <= lb + tol)
128128
)
129129
if any(_fixed_idx) and not all(_fixed_idx):
130+
# We should NOT reduce the problem if all variables are fixed. Otherwise, Aineq would be [], and
131+
# then bineq will be set to [] in the end. In this way, we lose completely the information in
132+
# these constraints. Consequently, we cannot evaluate the constraint violation correctly when needed.
130133
_fixed_values = 0.5 * (
131134
lb[_fixed_idx] + ub[_fixed_idx]
132135
)
@@ -137,9 +140,6 @@ def minimize(fun, x0, args=(), method=None, bounds=None, constraints=(), callbac
137140
)
138141
if isinstance(x0, np.ndarray):
139142
x0 = np.array(x0)[~_fixed_idx]
140-
elif x0_is_scalar:
141-
raise Exception("You have provided a scalar x with fixed bounds, there is" \
142-
"no optimization to be done.")
143143
else:
144144
# In this case x is presumably a list, so we turn it into a numpy array
145145
# for the convenience of indexing and then turn it back into a list
@@ -244,7 +244,7 @@ def fixed_nlc_fun(x):
244244
)
245245

246246
if any(_fixed_idx):
247-
newx = np.zeros(lenx0)
247+
newx = np.zeros(lenx0) + np.nan
248248
newx[_fixed_idx] = _fixed_values
249249
newx[~_fixed_idx] = result.x
250250
result.x = newx

0 commit comments

Comments
 (0)