From cd729bf808981bd8757446238df64d90768a623f Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Thu, 27 Jun 2024 12:35:35 -0600 Subject: [PATCH] maintain backwards compatibility --- .../pynumero/interfaces/pyomo_grey_box_nlp.py | 3 +++ .../contrib/pynumero/interfaces/pyomo_nlp.py | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py b/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py index 8f122eff08d..178bcd3d392 100644 --- a/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py +++ b/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py @@ -234,6 +234,9 @@ def __init__(self, pyomo_model): if v_scaling is not None: need_scaling = True self._primals_scaling[i] = v_scaling + # maintain backwards compatability + if self._pyomo_model.component('scaling_factor') is not None: + need_scaling = True self._constraints_scaling = BlockVector(len(nlps)) for i, nlp in enumerate(nlps): diff --git a/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py b/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py index 1416bf0f8b8..fe27cb52966 100644 --- a/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py +++ b/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py @@ -300,7 +300,11 @@ def get_inequality_constraint_indices(self, constraints): def get_obj_scaling(self): obj = self.get_pyomo_objective() val = SuffixFinder('scaling_factor').find(obj) - return val + # maintain backwards compatability + if self._pyomo_model.component('scaling_factor') is None: + return val + else: + return 1.0 if val is None else val # overloaded from NLP def get_primals_scaling(self): @@ -312,7 +316,11 @@ def get_primals_scaling(self): if val is not None: primals_scaling[i] = val ret = primals_scaling - return ret + # maintain backwards compatability + if self._pyomo_model.component('scaling_factor') is None: + return ret + else: + return primals_scaling # overloaded from NLP def get_constraints_scaling(self): @@ -324,7 +332,11 @@ def get_constraints_scaling(self): if val is not None: constraints_scaling[i] = val ret = constraints_scaling - return ret + # maintain backwards compatability + if self._pyomo_model.component('scaling_factor') is None: + return ret + else: + return constraints_scaling def extract_subvector_grad_objective(self, pyomo_variables): """Compute the gradient of the objective and return the entries @@ -612,6 +624,9 @@ def __init__(self, pyomo_model): if v_scaling is not None: need_scaling = True self._primals_scaling[i] = v_scaling + # maintain backwards compatability + if self._pyomo_model.component('scaling_factor') is not None: + need_scaling = True self._constraints_scaling = [] pyomo_nlp_scaling = self._pyomo_nlp.get_constraints_scaling()