Skip to content

Commit cd729bf

Browse files
committed
maintain backwards compatibility
1 parent 44da068 commit cd729bf

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ 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 compatability
238+
if self._pyomo_model.component('scaling_factor') is not None:
239+
need_scaling = True
237240

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

pyomo/contrib/pynumero/interfaces/pyomo_nlp.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ 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 compatability
304+
if self._pyomo_model.component('scaling_factor') is None:
305+
return val
306+
else:
307+
return 1.0 if val is None else val
304308

305309
# overloaded from NLP
306310
def get_primals_scaling(self):
@@ -312,7 +316,11 @@ def get_primals_scaling(self):
312316
if val is not None:
313317
primals_scaling[i] = val
314318
ret = primals_scaling
315-
return ret
319+
# maintain backwards compatability
320+
if self._pyomo_model.component('scaling_factor') is None:
321+
return ret
322+
else:
323+
return primals_scaling
316324

317325
# overloaded from NLP
318326
def get_constraints_scaling(self):
@@ -324,7 +332,11 @@ def get_constraints_scaling(self):
324332
if val is not None:
325333
constraints_scaling[i] = val
326334
ret = constraints_scaling
327-
return ret
335+
# maintain backwards compatability
336+
if self._pyomo_model.component('scaling_factor') is None:
337+
return ret
338+
else:
339+
return constraints_scaling
328340

329341
def extract_subvector_grad_objective(self, pyomo_variables):
330342
"""Compute the gradient of the objective and return the entries
@@ -612,6 +624,9 @@ def __init__(self, pyomo_model):
612624
if v_scaling is not None:
613625
need_scaling = True
614626
self._primals_scaling[i] = v_scaling
627+
# maintain backwards compatability
628+
if self._pyomo_model.component('scaling_factor') is not None:
629+
need_scaling = True
615630

616631
self._constraints_scaling = []
617632
pyomo_nlp_scaling = self._pyomo_nlp.get_constraints_scaling()

0 commit comments

Comments
 (0)