Skip to content

Commit 9ca3928

Browse files
committed
maintain backwards compatibility
1 parent 44da068 commit 9ca3928

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def __init__(self, pyomo_model):
234234
if v_scaling is not None:
235235
need_scaling = True
236236
self._primals_scaling[i] = v_scaling
237+
# maintain backwards compatibility
238+
scaling_suffix = self._pyomo_model.component('scaling_factor')
239+
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
240+
need_scaling = True
237241

238242
self._constraints_scaling = BlockVector(len(nlps))
239243
for i, nlp in enumerate(nlps):

pyomo/contrib/pynumero/interfaces/pyomo_nlp.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,12 @@ def get_inequality_constraint_indices(self, constraints):
300300
def get_obj_scaling(self):
301301
obj = self.get_pyomo_objective()
302302
val = SuffixFinder('scaling_factor').find(obj)
303-
return val
303+
# maintain backwards compatibility
304+
scaling_suffix = self._pyomo_model.component('scaling_factor')
305+
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
306+
return 1.0 if val is None else val
307+
else:
308+
return val
304309

305310
# overloaded from NLP
306311
def get_primals_scaling(self):
@@ -312,7 +317,12 @@ def get_primals_scaling(self):
312317
if val is not None:
313318
primals_scaling[i] = val
314319
ret = primals_scaling
315-
return ret
320+
# maintain backwards compatibility
321+
scaling_suffix = self._pyomo_model.component('scaling_factor')
322+
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
323+
return primals_scaling
324+
else:
325+
return ret
316326

317327
# overloaded from NLP
318328
def get_constraints_scaling(self):
@@ -324,7 +334,12 @@ def get_constraints_scaling(self):
324334
if val is not None:
325335
constraints_scaling[i] = val
326336
ret = constraints_scaling
327-
return ret
337+
# maintain backwards compatibility
338+
scaling_suffix = self._pyomo_model.component('scaling_factor')
339+
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
340+
return constraints_scaling
341+
else:
342+
return ret
328343

329344
def extract_subvector_grad_objective(self, pyomo_variables):
330345
"""Compute the gradient of the objective and return the entries
@@ -612,6 +627,10 @@ def __init__(self, pyomo_model):
612627
if v_scaling is not None:
613628
need_scaling = True
614629
self._primals_scaling[i] = v_scaling
630+
# maintain backwards compatibility
631+
scaling_suffix = self._pyomo_model.component('scaling_factor')
632+
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
633+
need_scaling = True
615634

616635
self._constraints_scaling = []
617636
pyomo_nlp_scaling = self._pyomo_nlp.get_constraints_scaling()

0 commit comments

Comments
 (0)