Skip to content

Commit c7b1bca

Browse files
committedJun 21, 2024·
adding SuffixFinder to PyomoNLPWithGreyBoxBlocks
1 parent c2e00f2 commit c7b1bca

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
 

‎pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock
3333
from pyomo.contrib.pynumero.interfaces.nlp_projections import ProjectedNLP
34+
from pyomo.core.base.suffix import SuffixFinder
3435

3536

3637
# Todo: make some of the numpy arrays not writable from __init__
@@ -227,12 +228,12 @@ def __init__(self, pyomo_model):
227228
need_scaling = True
228229

229230
self._primals_scaling = np.ones(self.n_primals())
230-
scaling_suffix = pyomo_model.component('scaling_factor')
231-
if scaling_suffix and scaling_suffix.ctype is pyo.Suffix:
232-
need_scaling = True
233-
for i, v in enumerate(self._pyomo_model_var_datas):
234-
if v in scaling_suffix:
235-
self._primals_scaling[i] = scaling_suffix[v]
231+
scaling_suffix_finder = SuffixFinder('scaling_factor')
232+
for i, v in enumerate(self._pyomo_model_var_datas):
233+
v_scaling = scaling_suffix_finder.find(v)
234+
if v_scaling is not None:
235+
need_scaling = True
236+
self._primals_scaling[i] = v_scaling
236237

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

‎pyomo/contrib/pynumero/interfaces/pyomo_nlp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
from pyomo.common.tempfiles import TempfileManager
2121
from pyomo.opt import WriterFactory
2222
import pyomo.core.base as pyo
23-
from pyomo.core.base.suffix import SuffixFinder
2423
from pyomo.common.collections import ComponentMap
2524
from pyomo.common.env import CtypesEnviron
2625
from pyomo.solvers.amplfunc_merge import amplfunc_merge
2726
from ..sparse.block_matrix import BlockMatrix
2827
from pyomo.contrib.pynumero.interfaces.ampl_nlp import AslNLP
2928
from pyomo.contrib.pynumero.interfaces.nlp import NLP
29+
from pyomo.core.base.suffix import SuffixFinder
3030
from .external_grey_box import ExternalGreyBoxBlock
3131

3232

0 commit comments

Comments
 (0)
Please sign in to comment.