Skip to content

Commit

Permalink
use context argument for SuffixFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Aug 15, 2024
1 parent bb944fe commit 031500b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def __init__(self, pyomo_model):
need_scaling = True

self._primals_scaling = np.ones(self.n_primals())
scaling_suffix_finder = SuffixFinder('scaling_factor')
scaling_suffix_finder = SuffixFinder(
'scaling_factor', context=self._pyomo_model
)
for i, v in enumerate(self._pyomo_model_var_datas):
v_scaling = scaling_suffix_finder.find(v)
if v_scaling is not None:
Expand Down
14 changes: 10 additions & 4 deletions pyomo/contrib/pynumero/interfaces/pyomo_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_inequality_constraint_indices(self, constraints):
# overloaded from NLP
def get_obj_scaling(self):
obj = self.get_pyomo_objective()
val = SuffixFinder('scaling_factor').find(obj)
val = SuffixFinder('scaling_factor', context=self._pyomo_model).find(obj)
# maintain backwards compatibility
scaling_suffix = self._pyomo_model.component('scaling_factor')
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
Expand All @@ -309,7 +309,9 @@ def get_obj_scaling(self):

# overloaded from NLP
def get_primals_scaling(self):
scaling_suffix_finder = SuffixFinder('scaling_factor')
scaling_suffix_finder = SuffixFinder(
'scaling_factor', context=self._pyomo_model
)
primals_scaling = np.ones(self.n_primals())
ret = None
for i, v in enumerate(self.get_pyomo_variables()):
Expand All @@ -326,7 +328,9 @@ def get_primals_scaling(self):

# overloaded from NLP
def get_constraints_scaling(self):
scaling_suffix_finder = SuffixFinder('scaling_factor')
scaling_suffix_finder = SuffixFinder(
'scaling_factor', context=self._pyomo_model
)
constraints_scaling = np.ones(self.n_constraints())
ret = None
for i, c in enumerate(self.get_pyomo_constraints()):
Expand Down Expand Up @@ -621,7 +625,9 @@ def __init__(self, pyomo_model):
need_scaling = True

self._primals_scaling = np.ones(self.n_primals())
scaling_suffix_finder = SuffixFinder('scaling_factor')
scaling_suffix_finder = SuffixFinder(
'scaling_factor', context=self._pyomo_model
)
for i, v in enumerate(self.get_pyomo_variables()):
v_scaling = scaling_suffix_finder.find(v)
if v_scaling is not None:
Expand Down

0 comments on commit 031500b

Please sign in to comment.