From 5e8ef5bb37782f0a3fe22bc6384a0dbfcf3bd867 Mon Sep 17 00:00:00 2001 From: Bernard Knueven Date: Thu, 20 Jun 2024 20:42:04 -0600 Subject: [PATCH] adding SuffixFinder to PyomoNLPWithGreyBoxBlocks --- .../pynumero/interfaces/pyomo_grey_box_nlp.py | 13 +++++++------ pyomo/contrib/pynumero/interfaces/pyomo_nlp.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py b/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py index e6ed40e9974..7df0d68033f 100644 --- a/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py +++ b/pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py @@ -31,6 +31,7 @@ ) from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock from pyomo.contrib.pynumero.interfaces.nlp_projections import ProjectedNLP +from pyomo.core.base.suffix import SuffixFinder # Todo: make some of the numpy arrays not writable from __init__ @@ -227,12 +228,12 @@ def __init__(self, pyomo_model): need_scaling = True self._primals_scaling = np.ones(self.n_primals()) - scaling_suffix = pyomo_model.component('scaling_factor') - if scaling_suffix and scaling_suffix.ctype is pyo.Suffix: - need_scaling = True - for i, v in enumerate(self._pyomo_model_var_datas): - if v in scaling_suffix: - self._primals_scaling[i] = scaling_suffix[v] + scaling_suffix_finder = SuffixFinder('scaling_factor') + for i, v in enumerate(self._pyomo_model_var_datas): + v_scaling = scaling_suffix_finder.find(v) + if v in scaling_suffix: + need_scaling = True + self._primals_scaling[i] = v_scaling 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 f81299bb372..eebf7099b4f 100644 --- a/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py +++ b/pyomo/contrib/pynumero/interfaces/pyomo_nlp.py @@ -20,13 +20,13 @@ from pyomo.common.tempfiles import TempfileManager from pyomo.opt import WriterFactory import pyomo.core.base as pyo -from pyomo.core.base.suffix import SuffixFinder from pyomo.common.collections import ComponentMap from pyomo.common.env import CtypesEnviron from pyomo.solvers.amplfunc_merge import amplfunc_merge from ..sparse.block_matrix import BlockMatrix from pyomo.contrib.pynumero.interfaces.ampl_nlp import AslNLP from pyomo.contrib.pynumero.interfaces.nlp import NLP +from pyomo.core.base.suffix import SuffixFinder from .external_grey_box import ExternalGreyBoxBlock