Skip to content

Commit

Permalink
adding SuffixFinder to PyomoNLPWithGreyBoxBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Jun 21, 2024
1 parent c2e00f2 commit c7b1bca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions pyomo/contrib/pynumero/interfaces/pyomo_grey_box_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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_scaling is not None:
need_scaling = True
self._primals_scaling[i] = v_scaling

self._constraints_scaling = BlockVector(len(nlps))
for i, nlp in enumerate(nlps):
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/pynumero/interfaces/pyomo_nlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit c7b1bca

Please sign in to comment.