@@ -123,8 +123,8 @@ def obj_val(self, x):
123123 # clear previous output and run direct solver
124124 try :
125125 os .remove (self ._objValFile )
126- except :
127- pass
126+ except OSError :
127+ pass # Ignore error if file does not exist
128128
129129 try :
130130 sp .call (self ._objValCommand , shell = True )
@@ -136,7 +136,7 @@ def obj_val(self, x):
136136 break
137137 # the return code of mpirun is useless, we test the value of the function
138138 self ._assert_isfinite (val )
139- except :
139+ except Exception :
140140 raise RuntimeError ("Objective function evaluation failed" )
141141 # end
142142
@@ -150,8 +150,8 @@ def obj_der(self, x):
150150 # clear previous output and run direct solver
151151 try :
152152 os .remove (self ._objDerFile )
153- except :
154- pass
153+ except OSError :
154+ pass # Ignore error if file does not exist
155155 N = x .shape [0 ]
156156 y = np .ndarray ((N ,))
157157
@@ -167,7 +167,7 @@ def obj_der(self, x):
167167 self ._assert_isfinite (val )
168168 y [i ] = val * obj_scale / var_scale
169169 # end
170- except :
170+ except Exception :
171171 raise RuntimeError ("Objective gradient evaluation failed" )
172172 # end
173173
@@ -186,7 +186,7 @@ def con_val(self, x):
186186 val = float (lines [1 ].split ("," )[col ])
187187 break
188188 self ._assert_isfinite (val )
189- except :
189+ except Exception :
190190 raise RuntimeError ("Constraint function evaluation failed" )
191191 # end
192192
@@ -200,8 +200,8 @@ def con_der(self, x):
200200 # clear previous output and run solver
201201 try :
202202 os .remove (self ._conDerFile )
203- except :
204- pass
203+ except OSError :
204+ pass # Ignore error if file does not exist
205205 N = x .shape [0 ]
206206 y = np .ndarray ((N ,))
207207
@@ -217,7 +217,7 @@ def con_der(self, x):
217217 self ._assert_isfinite (val )
218218 y [i ] = val * con_scale / var_scale
219219 # end
220- except :
220+ except Exception :
221221 raise RuntimeError ("Constraint function evaluation failed" )
222222 # end
223223
@@ -295,7 +295,7 @@ def finished(self):
295295 return self ._value == self ._maxi
296296
297297 def value (self ):
298- if self ._func == None :
298+ if self ._func is None :
299299 return self ._value
300300 else :
301301 return self ._func (self ._value )
0 commit comments