Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul PyROS Preprocessor Subroutine and Subproblem Objects #3341

Open
wants to merge 232 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 185 commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
57b0550
Update PyROS solver variable scope
shermanjasonaf May 30, 2024
5734e52
Modularize the preprocessor
shermanjasonaf May 30, 2024
dc84806
Add method for partitioning vars by adjustability
shermanjasonaf May 31, 2024
9385c2b
Update effective variable partitioning subroutine
shermanjasonaf Jun 2, 2024
e837730
Add tests for effective variable partitioning
shermanjasonaf Jun 10, 2024
66f591d
Tweak variable partitioning debug message
shermanjasonaf Jun 10, 2024
a562545
Reduce scope of and fix effective partitioning routine
shermanjasonaf Jun 10, 2024
7e504e1
Add tolerance for pretriangularization linear coefs
shermanjasonaf Jun 10, 2024
649aabc
Add tests for variable bounds resolution
shermanjasonaf Jun 10, 2024
b7752a3
Fix var bounds test error message
shermanjasonaf Jun 10, 2024
5043b8d
Include domain state check in var bounds testing
shermanjasonaf Jun 10, 2024
b2570ba
Begin full rewrite of the preprocessor
shermanjasonaf Jun 10, 2024
4989b74
Lint util block retrieval code line
shermanjasonaf Jun 10, 2024
668e194
Rearrange and improvement documentation of new bound functions
shermanjasonaf Jun 10, 2024
34f5019
Add new methods for turning variable bounds to constraints
shermanjasonaf Jun 11, 2024
9b62ce5
Change terminology: 'interval bound' -> 'declared bound'
shermanjasonaf Jun 11, 2024
14eb02a
Add new method for standardizing inequality cons
shermanjasonaf Jun 11, 2024
15fe9dc
Declare variable bound constraints on user model
shermanjasonaf Jun 11, 2024
461597e
Add method for standardizing equality constraints
shermanjasonaf Jun 12, 2024
e566173
Ensure var bound cons declared on user model block
shermanjasonaf Jun 12, 2024
7bb5b9f
Add new method for standardizing active objective
shermanjasonaf Jun 12, 2024
5c54567
Add modified methods for DR component declaration
shermanjasonaf Jun 12, 2024
eaf8a68
Add method for retrieving and noting all nonadjustable vars
shermanjasonaf Jun 12, 2024
6e8c447
Add mappings between second-stage variables and DR components
shermanjasonaf Jun 12, 2024
baf2e28
Add coefficient matching; fix working model setup
shermanjasonaf Jun 13, 2024
ce993ca
Fix working model setup block warning
shermanjasonaf Jun 13, 2024
e7b5a73
Add preprocessor progress logging messages
shermanjasonaf Jun 13, 2024
11af931
Finalize return value of new preprocessor routine
shermanjasonaf Jun 13, 2024
800c75f
Make coefficient matching tests more rigorous
shermanjasonaf Jun 13, 2024
78b5264
Simplify objective standardization expression testing
shermanjasonaf Jun 13, 2024
16c06bd
Add method for logging model statistics
shermanjasonaf Jun 13, 2024
b3f5aaf
Prevent duplicates in constraint partitions
shermanjasonaf Jun 13, 2024
589f7b5
Log effective partitioning info in model stats
shermanjasonaf Jun 13, 2024
c25c6c4
Compile all working model variables into list
shermanjasonaf Jun 13, 2024
fdb860a
Don't log model statistics during preprocessing
shermanjasonaf Jun 13, 2024
ad65e1a
Make var bound to constraint tests more rigorous
shermanjasonaf Jun 24, 2024
e4d5a54
Modify constraint standardization routines
shermanjasonaf Jun 24, 2024
68adb9d
Modify naming of standardized constraint objects
shermanjasonaf Jun 24, 2024
4859043
Formalize exception raised in event of bound misclassification
shermanjasonaf Jun 24, 2024
4f40228
Modify standard form of performance ineq/eq constraints
shermanjasonaf Jun 25, 2024
ffbefd5
Don't modify eq cons; tweak expr/constraint standardization docs
shermanjasonaf Jun 25, 2024
39af8b1
Tweak docstring of `get_summands`
shermanjasonaf Jun 25, 2024
22ad137
Remove equality upper bound assertion in coefficient matching
shermanjasonaf Jun 25, 2024
43e4ed6
Rename user variable partitioning objects
shermanjasonaf Jun 25, 2024
2f38a06
Rename `declare_perstage_objective_summands` -> `declare_objective_ex…
shermanjasonaf Jun 25, 2024
665098f
Account for obj focus in constraint classification
shermanjasonaf Jun 25, 2024
35ca58d
Simplify and sharpen DR constraint tests
shermanjasonaf Jun 25, 2024
ee4bdd4
Add constraint partitioning checks to coeff matching tests
shermanjasonaf Jun 25, 2024
0846b1b
Fix constraint pretriangularization routine
shermanjasonaf Jun 25, 2024
1e40c77
Make fixes to new coefficient matching routine
shermanjasonaf Jun 25, 2024
29802d3
Add tests for new preprocessing function
shermanjasonaf Jun 25, 2024
881ae30
Sharpen testing of preprocessor effective var partitioning
shermanjasonaf Jun 25, 2024
bc36419
Add obj focus considerations to preprocessor constraint testing
shermanjasonaf Jun 25, 2024
695fe9c
Add tests for preprocessor objective standardization
shermanjasonaf Jun 25, 2024
871fc0c
Add preprocessor constraint expression testing
shermanjasonaf Jun 26, 2024
d521ada
Move preprocessor tests to new module
shermanjasonaf Jun 26, 2024
6b67c3c
Add test for working model setup routine
shermanjasonaf Jun 26, 2024
e958f79
Add tests for logging of model component stats
shermanjasonaf Jun 26, 2024
45206a4
Add methods for construction of new master problem
shermanjasonaf Jun 26, 2024
9d0ed4e
Rearrange module imports
shermanjasonaf Jun 26, 2024
fc6a02e
Remove superfluous parameterized import
shermanjasonaf Jun 26, 2024
f8d01bc
Update new master problem creation method docstrings
shermanjasonaf Jun 26, 2024
be99dec
Add new methods for separation problem construction
shermanjasonaf Jun 27, 2024
9a173a2
Add alternative method for checking fixed uncertain params
shermanjasonaf Jun 27, 2024
2c53fef
Rearrange separation module imports
shermanjasonaf Jun 27, 2024
a4989d0
Add new master feasibility problem routine
shermanjasonaf Jun 27, 2024
57adb05
Rearrange master problem module docstring and imports
shermanjasonaf Jun 27, 2024
13992c6
Add refined method for DR polishing problem construction
shermanjasonaf Jun 27, 2024
f57fafb
Do clone first-stage constraints across master blocks
shermanjasonaf Jun 27, 2024
37d9c9b
Remove unused import
shermanjasonaf Jun 27, 2024
94b94c2
Start merging new preprocessor and problems into main methods
shermanjasonaf Jun 28, 2024
d210869
Fix inequality constraint classification
shermanjasonaf Jun 28, 2024
1c59fd7
Fix retrieval of master epigraph objective
shermanjasonaf Jun 28, 2024
cc34b89
Fix reference to original model name
shermanjasonaf Jun 28, 2024
3d87ede
Remove unused solver variable
shermanjasonaf Jun 28, 2024
a353ba8
Simplify classification of inequality constraints
shermanjasonaf Jun 28, 2024
566bbd2
Deactivate duplicated master problem constraints
shermanjasonaf Jun 29, 2024
f1bf474
Fix coefficient matching regression test
shermanjasonaf Jul 4, 2024
09ff939
Account for BARON version in coefficient matching regression test
shermanjasonaf Jul 4, 2024
f9a097d
Check duplicated first-stage master constraints deactivated
shermanjasonaf Jul 4, 2024
ea6f6cd
Remove original coefficient matching routine
shermanjasonaf Jul 4, 2024
262baff
Start updating uncertainty sets and interactions with sep model
shermanjasonaf Jul 10, 2024
cd9a895
Merge branch 'Pyomo:main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Jul 10, 2024
075d6ca
Fixes to `IntersectionSet` and `CardinalitySet`
shermanjasonaf Jul 11, 2024
dd0f962
Fix `DiscreteScenarioSet` methods and tests
shermanjasonaf Jul 11, 2024
067d759
Remove unused method
shermanjasonaf Jul 11, 2024
a090eee
Fix tests for `AxisAlignedEllipsoidalSet`
shermanjasonaf Jul 11, 2024
0eb0724
Fix methods and tests for `EllipsoidalSet`
shermanjasonaf Jul 11, 2024
09d1ce4
Fix `PolyhedralSet` tests
shermanjasonaf Jul 11, 2024
3bb6086
Simplify test module imports
shermanjasonaf Jul 11, 2024
05710d1
Simplify test module imports
shermanjasonaf Jul 11, 2024
c990289
Add tests for uncertainty set subclassing
shermanjasonaf Jul 11, 2024
d1ea0be
Remove unused import
shermanjasonaf Jul 11, 2024
f705dc8
Make method for adding bounds on param vars private
shermanjasonaf Jul 11, 2024
4fe5273
Remove unused imports
shermanjasonaf Jul 11, 2024
388976c
Make docstrings more consistent
shermanjasonaf Jul 11, 2024
fd72cb3
Fix test module docstring
shermanjasonaf Jul 11, 2024
22a5a16
Make `set_as_constraint` tests more comprehensive
shermanjasonaf Jul 11, 2024
80eeae2
Make test docstrings consistent
shermanjasonaf Jul 11, 2024
01c6dbc
Add method for evaluating auxiliary parameter values
shermanjasonaf Jul 11, 2024
aeb12eb
Test PyROS solve with `FactorModelSet` instance
shermanjasonaf Jul 11, 2024
f608791
Update documentation of `set_as_constraint`
shermanjasonaf Jul 11, 2024
93c66cf
Test separation problem uncertainty components
shermanjasonaf Jul 11, 2024
adb2f2d
Simplify uncertain param var preprocessing
shermanjasonaf Jul 11, 2024
1335086
Keep track of auxiliary uncertain parameter values in subproblems
shermanjasonaf Jul 11, 2024
8bcb196
Remove unused preprocessing functions
shermanjasonaf Jul 11, 2024
1400814
Fix testing for method `solve_master`
shermanjasonaf Jul 11, 2024
036d74d
Fix DR polishing tests
shermanjasonaf Jul 11, 2024
74170f3
Remove unused method for identifying objective expressions
shermanjasonaf Jul 11, 2024
d6b4e9c
Remove unused selective cloning method
shermanjasonaf Jul 11, 2024
cc476cf
Name uncertainty modeling components more carefully
shermanjasonaf Jul 11, 2024
528506e
Unify logging of master and DR polishing results
shermanjasonaf Jul 11, 2024
a09e701
Remove unused imports
shermanjasonaf Jul 11, 2024
6d62eea
Add tests for backup solver mechanism
shermanjasonaf Jul 11, 2024
2d26caf
Fix naming of missed regression tests
shermanjasonaf Jul 11, 2024
cf52e5d
Deactivate DR polishing constraints in fixed Vars
shermanjasonaf Jul 11, 2024
ba3fa3b
Simplify names of revised methods and classes
shermanjasonaf Jul 11, 2024
3c6bbd8
Remove unused module imports
shermanjasonaf Jul 11, 2024
793bf57
Remove unused subproblem data containers
shermanjasonaf Jul 11, 2024
1ea438f
Simplify master results object
shermanjasonaf Jul 12, 2024
06ad830
Simplify master problem constructor
shermanjasonaf Jul 12, 2024
2bb5d1a
Reorder model variable stats breakdown
shermanjasonaf Jul 12, 2024
f1d214d
Merge branch 'Pyomo:main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Jul 12, 2024
5a5c51a
Tweak factor model set aux params calculations
shermanjasonaf Jul 12, 2024
093301d
Merge branch 'new-pyros-preprocessor-and-subproblems' of github.com:s…
shermanjasonaf Jul 12, 2024
0912729
Apply black
shermanjasonaf Jul 12, 2024
846d858
Avoid use of deprecated method for `scipy.linprog`
shermanjasonaf Jul 12, 2024
06a0bf8
Simplify main solve and subproblem results objects
shermanjasonaf Jul 13, 2024
fc95ac3
Fix testing error messages
shermanjasonaf Jul 13, 2024
7ecd149
Update and more thoroughly test `EllipsoidalSet.point_in_set`
shermanjasonaf Jul 13, 2024
8e942de
Ensure DR polishing success status properly updated
shermanjasonaf Jul 16, 2024
c751802
Simplify namedtuple import
shermanjasonaf Jul 16, 2024
6391b18
Make pretriangularization optional
shermanjasonaf Jul 18, 2024
9364337
Make pretriangularization mandatory again
shermanjasonaf Jul 29, 2024
6f0d5f4
Modify online docs methodology section
shermanjasonaf Jul 29, 2024
aecea50
Assert that `FactorModelSet` instances have matrices of full column rank
shermanjasonaf Jul 31, 2024
20c2cf0
Simplify methods for calculating auxiliary param values
shermanjasonaf Jul 31, 2024
3a8be0a
Standardize validation of arguments to `point_in_set`
shermanjasonaf Jul 31, 2024
3e870d8
Adjust polishing model component declarations
shermanjasonaf Jul 31, 2024
3046d26
Further adjust DR polishing component declarations
shermanjasonaf Jul 31, 2024
a6d6da0
Switch DR polishing obj to nonstatic infinity norm
shermanjasonaf Aug 1, 2024
6aff08b
Resolve ambiguity in new DR polishing efficiency
shermanjasonaf Aug 1, 2024
36b146f
Include static DR term in polishing norm
shermanjasonaf Aug 1, 2024
56b6bd3
Remove nonstatic terms from DR polishing norm
shermanjasonaf Aug 1, 2024
c10b514
Restore 1-norm as DR polishing objective
shermanjasonaf Aug 1, 2024
3d3820f
Tweak polishing problem comments
shermanjasonaf Aug 1, 2024
1a2ab17
Rephrase text of online docs methodology section
shermanjasonaf Aug 1, 2024
1556123
Add copyright statement to testing modules
shermanjasonaf Aug 1, 2024
6901f43
Modify PyROS solver test module docstring
shermanjasonaf Aug 1, 2024
361ae93
Drop static DR terms from polishing norm
shermanjasonaf Aug 1, 2024
43e7128
Add todo comment on DR polishing obj
shermanjasonaf Aug 2, 2024
bc4625a
Reformulate all state variable independent equality cons
shermanjasonaf Aug 6, 2024
f4650e1
Add normalization of DR polishing variables
shermanjasonaf Aug 6, 2024
d845e08
Make documentation of `FactorModelSet.psi_mat` more informative
shermanjasonaf Aug 6, 2024
4190f18
Undo DR polishing variable normalization
shermanjasonaf Aug 6, 2024
d58847a
Reorganize and rename working model stagewise components
shermanjasonaf Aug 10, 2024
cc0d3f5
Remove unused solve time retrieval method
shermanjasonaf Aug 10, 2024
799d694
Unify component data arg type validators
shermanjasonaf Aug 10, 2024
3aac693
Change coeff matching logging level to DEBUG
shermanjasonaf Aug 10, 2024
7187693
Fix and test robust infeas detection from master problem
shermanjasonaf Aug 11, 2024
649ecc8
Remove unused p-robustness subroutine
shermanjasonaf Aug 11, 2024
3c22d04
Test DR polishing small param coefficients efficiency
shermanjasonaf Aug 11, 2024
f4204f0
Update PyROS solver logging documentation
shermanjasonaf Aug 11, 2024
33ff4d8
Add note on 'adj.' abbreviation in docs
shermanjasonaf Aug 11, 2024
3bb1d9d
Apply black
shermanjasonaf Aug 11, 2024
38b0f33
Fix typos
shermanjasonaf Aug 11, 2024
392ec39
Tweak punctuation of phrase
shermanjasonaf Aug 11, 2024
4c4fd0b
Fix separation subsolver error testing
shermanjasonaf Aug 11, 2024
fcd73ca
Remove unused solve data methods
shermanjasonaf Aug 11, 2024
2bac631
Reorganize main model data object
shermanjasonaf Aug 11, 2024
69dc039
Ensure PyROS has working separation priority interface
shermanjasonaf Aug 12, 2024
0346771
Apply black
shermanjasonaf Aug 12, 2024
3f59465
Fold config into model data objects
shermanjasonaf Aug 12, 2024
b263173
Apply black and typos
shermanjasonaf Aug 12, 2024
fb6f05a
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 12, 2024
c1689fe
Add solver license check to coeff matching test
shermanjasonaf Aug 12, 2024
44fe269
Merge branch 'new-pyros-preprocessor-and-subproblems' of github.com:s…
shermanjasonaf Aug 12, 2024
9c2e9ba
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 12, 2024
0d8f12b
Fix numpy/scipy imports
shermanjasonaf Aug 12, 2024
890b100
Fix expression testing numpy int types
shermanjasonaf Aug 12, 2024
0fcd838
Merge branch 'new-pyros-preprocessor-and-subproblems' of github.com:s…
shermanjasonaf Aug 12, 2024
5e2a88a
Apply black
shermanjasonaf Aug 12, 2024
403d3ef
Update version number, changelog
shermanjasonaf Aug 13, 2024
b34052b
Add PyROS installation instructions section
shermanjasonaf Aug 13, 2024
cb87b9f
Add extra test for inequality constraint preprocessing
shermanjasonaf Aug 13, 2024
a6cdb9a
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 20, 2024
0004efa
Fix new PyROS installation instructions
shermanjasonaf Aug 20, 2024
b50a4a5
Add named constant for uncertainty set point checks
shermanjasonaf Aug 20, 2024
ece5beb
Move new `VariableValueData` namedtuple to module scope
shermanjasonaf Aug 20, 2024
0615fca
Update NL writer tolerance PyROS tests
shermanjasonaf Aug 20, 2024
6277fe4
Add new named constant for DR polishing tolerance
shermanjasonaf Aug 20, 2024
9b65ce1
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 20, 2024
39fdfde
Add new enum for specification of bound types
shermanjasonaf Aug 20, 2024
80c2dd6
Substitute `ParameterizedQuadaraticRepnVisitor` for standard repn
shermanjasonaf Aug 20, 2024
96b4ede
Apply black
shermanjasonaf Aug 20, 2024
e7597fe
Use SCIP for nonlinear coeff matching test
shermanjasonaf Aug 20, 2024
14f0d16
Try BARON (except 24.1.5) again for failing test
shermanjasonaf Aug 23, 2024
a748529
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 23, 2024
2ba5334
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 27, 2024
c670407
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Aug 28, 2024
c863ae1
Test decision rule order efficiency
shermanjasonaf Sep 9, 2024
dc6624d
Merge branch 'new-pyros-preprocessor-and-subproblems' of github.com:s…
shermanjasonaf Sep 9, 2024
4d6d5fa
Apply black
shermanjasonaf Sep 9, 2024
b61f5e7
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Sep 11, 2024
24f0c4b
Perform final cleanup of master results objects
shermanjasonaf Sep 23, 2024
0687977
Use SCIP for failing tests
shermanjasonaf Sep 23, 2024
2858f23
Apply black
shermanjasonaf Sep 23, 2024
fe42b4d
Restore `InvalidValueError` exception type check
shermanjasonaf Sep 23, 2024
3a50708
Merge branch 'new-pyros-preprocessor-and-subproblems' of github.com:s…
shermanjasonaf Sep 23, 2024
9580236
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
jsiirola Oct 4, 2024
95adf1f
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Oct 4, 2024
6c27f8d
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
blnicho Oct 15, 2024
3ecb3f5
Use BARON 24.5.8 for failing test
shermanjasonaf Oct 16, 2024
e6c02d5
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Oct 16, 2024
d39be64
Simplify coefficient matching test
shermanjasonaf Oct 18, 2024
00ad39a
Fix nonlinear coefficient matching test option
shermanjasonaf Oct 18, 2024
bd9a786
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
jsiirola Oct 28, 2024
a7bffa8
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Oct 31, 2024
e292d68
Update documentation of main model data objects
shermanjasonaf Oct 31, 2024
7db96d2
Tweak uncertainty set documentation
shermanjasonaf Oct 31, 2024
3e0ff19
Simplify uncertainty set module docstring
shermanjasonaf Oct 31, 2024
01400d7
Fix references to PyROS solve method
shermanjasonaf Oct 31, 2024
7762142
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
blnicho Oct 31, 2024
d159b99
Clarify documentation of PyROS results object
shermanjasonaf Oct 31, 2024
14ec9ce
Finalize PyROS online doc updates
shermanjasonaf Oct 31, 2024
42e747f
Adapt to deprecation of expression walker arguments
shermanjasonaf Oct 31, 2024
73d89b5
Finalize documentation of uncertainty set methods
shermanjasonaf Oct 31, 2024
5857949
Final typo fix
shermanjasonaf Oct 31, 2024
7b98415
Modify unittest imports
shermanjasonaf Nov 4, 2024
61663e9
Modularize creation of repeatedly used models
shermanjasonaf Nov 5, 2024
dc53d51
Rename `conlist` -> `con_list`
shermanjasonaf Nov 5, 2024
4c82203
Merge branch 'main' into new-pyros-preprocessor-and-subproblems
shermanjasonaf Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 131 additions & 78 deletions doc/OnlineDocs/contributed_packages/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 @@ -19,7 +19,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 @@ -131,24 +135,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 @@ -172,40 +158,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
Loading