Skip to content

Commit

Permalink
Merge pull request Pyomo#3341 from shermanjasonaf/new-pyros-preproces…
Browse files Browse the repository at this point in the history
…sor-and-subproblems

Overhaul PyROS Preprocessor Subroutine and Subproblem Objects
  • Loading branch information
blnicho authored Nov 6, 2024
2 parents f46e2fd + 58c6526 commit 22a1dac
Show file tree
Hide file tree
Showing 17 changed files with 10,778 additions and 8,221 deletions.
229 changes: 143 additions & 86 deletions doc/OnlineDocs/explanation/solvers/pyros.rst

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions pyomo/contrib/pyros/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
PyROS CHANGELOG
===============

-------------------------------------------------------------------------------
PyROS 1.3.0 12 Aug 2024
-------------------------------------------------------------------------------
- Fix interactions between PyROS and NL writer-based solvers
- Overhaul the preprocessor
- Update subproblem formulations and modeling objects
- Update `UncertaintySet` class and pre-implemented subclasses to
facilitate new changes to the subproblems
- Update documentation and logging system in light of new preprocessor
and subproblem changes
- Make all tests more rigorous and extensive


-------------------------------------------------------------------------------
PyROS 1.2.11 17 Mar 2024
-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/pyros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ___________________________________________________________________________

from pyomo.contrib.pyros.pyros import PyROS
from pyomo.contrib.pyros.pyros import ObjectiveType, pyrosTerminationCondition
from pyomo.contrib.pyros.util import ObjectiveType, pyrosTerminationCondition
from pyomo.contrib.pyros.uncertainty_sets import (
UncertaintySet,
EllipsoidalSet,
Expand Down
67 changes: 14 additions & 53 deletions pyomo/contrib/pyros/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from pyomo.core.base import Var, VarData
from pyomo.core.base.param import Param, ParamData
from pyomo.opt import SolverFactory
from pyomo.contrib.pyros.util import ObjectiveType, setup_pyros_logger
from pyomo.contrib.pyros.util import (
ObjectiveType,
setup_pyros_logger,
standardize_component_data,
)
from pyomo.contrib.pyros.uncertainty_sets import UncertaintySet


Expand Down Expand Up @@ -132,24 +136,6 @@ def __init__(
self.cdatatype_validator = cdatatype_validator
self.allow_repeats = allow_repeats

def standardize_ctype_obj(self, obj):
"""
Standardize object of type ``self.ctype`` to list
of objects of type ``self.cdatatype``.
"""
if self.ctype_validator is not None:
self.ctype_validator(obj)
return list(obj.values())

def standardize_cdatatype_obj(self, obj):
"""
Standardize object of type ``self.cdatatype`` to
``[obj]``.
"""
if self.cdatatype_validator is not None:
self.cdatatype_validator(obj)
return [obj]

def __call__(self, obj, from_iterable=None, allow_repeats=None):
"""
Cast object to a flat list of Pyomo component data type
Expand All @@ -173,40 +159,15 @@ def __call__(self, obj, from_iterable=None, allow_repeats=None):
ValueError
If the resulting list contains duplicate entries.
"""
if allow_repeats is None:
allow_repeats = self.allow_repeats

if isinstance(obj, self.ctype):
ans = self.standardize_ctype_obj(obj)
elif isinstance(obj, self.cdatatype):
ans = self.standardize_cdatatype_obj(obj)
elif isinstance(obj, Iterable) and not isinstance(obj, str):
ans = []
for item in obj:
ans.extend(self.__call__(item, from_iterable=obj))
else:
from_iterable_qual = (
f" (entry of iterable {from_iterable})"
if from_iterable is not None
else ""
)
raise TypeError(
f"Input object {obj!r}{from_iterable_qual} "
"is not of valid component type "
f"{self.ctype.__name__} or component data type "
f"{self.cdatatype.__name__}."
)

# check for duplicates if desired
if not allow_repeats and len(ans) != len(ComponentSet(ans)):
comp_name_list = [comp.name for comp in ans]
raise ValueError(
f"Standardized component list {comp_name_list} "
f"derived from input {obj} "
"contains duplicate entries."
)

return ans
return standardize_component_data(
obj=obj,
valid_ctype=self.ctype,
valid_cdatatype=self.cdatatype,
ctype_validator=self.ctype_validator,
cdatatype_validator=self.cdatatype_validator,
allow_repeats=allow_repeats,
from_iterable=from_iterable,
)

def domain_name(self):
"""Return str briefly describing domain encompassed by self."""
Expand Down
Loading

0 comments on commit 22a1dac

Please sign in to comment.