@@ -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