Adding (parameterized) linear programming dual transformation!#3402
Merged
blnicho merged 81 commits intoPyomo:mainfrom Nov 15, 2024
Merged
Adding (parameterized) linear programming dual transformation!#3402blnicho merged 81 commits intoPyomo:mainfrom
blnicho merged 81 commits intoPyomo:mainfrom
Conversation
… with where the mappings are stored
…ing transformed model match
…that assume that the data is numeric. Creating my own csr and csc classes that are almost complete
…ssions in the data
…rized_standard_form itself.
…use the correct converstion to a CSC matrix depending on the circumstances, testing the conversion to nonnegative vars
…ut parameterized standard repn doesn't
Contributor
Author
jsiirola
reviewed
Nov 11, 2024
Comment on lines
+33
to
+51
| def __call__(self, x): | ||
| if hasattr(x, 'ctype') and x.ctype is self._ctype: | ||
| if not x.is_indexed(): | ||
| return ComponentSet([x]) | ||
| ans = ComponentSet() | ||
| for j in x.index_set(): | ||
| ans.add(x[j]) | ||
| return ans | ||
| elif hasattr(x, '__iter__'): | ||
| ans = ComponentSet() | ||
| for i in x: | ||
| ans.update(self(i)) | ||
| return ans | ||
| else: | ||
| _ctype_name = str(self._ctype) | ||
| raise ValueError( | ||
| f"Expected {_ctype_name} or iterable of " | ||
| f"{_ctype_name}s.\n\tReceived {type(x)}" | ||
| ) |
Member
There was a problem hiding this comment.
There are some issues with this implementation:
- it doesn't actually return a list. ;)
- it doesn't actually validate the ctype for list-like inputs
Maybe the following would be a more robust alternative:
def __init__(self, ctype):
if isinstance(ctype, Sequence):
self._ctypes = set(ctype)
else:
self._ctypes = set([ctype])
def __call__(self, x):
return list(self._process(x))
def _process(self, x):
if hasattr(x, 'ctype'):
if x.ctype not in self._ctypes:
raise ValueError(" .... ")
if x.is_indexed():
yield from x.values()
else:
yield x
elif isinstance(x, Sequence):
for y in x:
yield from self._process(y)
else:
raise ValueError(" ... ")
def domain_name(self):
_names = ', '.join(ct.__name__ for ct in self._ctypes)
if len(self._ctypes) > 1:
_names = '[' + _names + ']'
return f"ComponentDataList({_names})")
Contributor
Author
There was a problem hiding this comment.
I actually really want it to both return and accept ComponentSets, but just took your suggestions otherwise (and renamed it accordingly)
jsiirola
reviewed
Nov 12, 2024
| return _ParameterizedLinearStandardFormCompiler_impl(config).write(model) | ||
|
|
||
|
|
||
| class _SparseMatrixBase(object): |
Member
There was a problem hiding this comment.
Some day (not today) we should refactor the sparse sets into pyomo.common
jsiirola
reviewed
Nov 13, 2024
pyomo/util/config_domains.py
Outdated
Comment on lines
+41
to
+43
| # Ordering for determinism | ||
| _ctypes = sorted([ct.__name__ for ct in self._ctypes]) | ||
| _names = ', '.join(_ctypes) |
Member
There was a problem hiding this comment.
We don't want to convert the set() to a list: that is unnecessary and converts O(1) lookups into O(n). We should sort the names ... but again, we should only generate the names string if we are going to actually use it (i.e. before raising an exception).
jsiirola
approved these changes
Nov 13, 2024
mrmundt
approved these changes
Nov 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the complaints of several reasonable people
Summary/Motivation:
This PR adds a transformation in
coreto take the dual of a linear program. For the purposes of supporting bilevel programming, it also allows for this dual to be "parameterized" by certain variables--that is, the user can specify a list of Vars that are treated as data for the purposes of taking the dual (e.g., if they are the outer variables of a bilevel program with an LP inner problem).Changes proposed in this PR:
core.lp_dualtransformation.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: