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

Adding contrib.piecewise package #2708

Merged
merged 51 commits into from
Mar 12, 2023
Merged

Conversation

emma58
Copy link
Contributor

@emma58 emma58 commented Jan 28, 2023

Fixes # .

Summary/Motivation:

This adds a contrib package to support modeling with and reformulating multivariate piecewise linear functions. It has no dependencies for univariate functions, and for multivariate functions it relies on numpy and possibly scipy (depending on how the function is specified.) This PR adds the modeling components and one transformation as a proof-of-concept. Further transformations are forthcoming...

Changes proposed in this PR:

  • Adds PiecewiseLinearFunction component that can be constructed from a list of points and a nonlinear function, a list of simplices (in the appropriate dimension) and a nonlinear function, or a list of simplices and a list of linear functions.
  • Adds PiecewiseLinearExpression component that represents a specific use of a PiecewiseLinearFunction.
  • Adds a proof-of-concept transformation that converts a model containing PiecewiseLinearFunctions to a GDP, and a small transformation that applies hull to that GDP in order to make a known MIP formulation from the literature.

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:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

…ions (returning linear expressions) and list of simplices
…ting piecewise functions. This is terrifying.
…o be a weakref in order to avoid circular references
…ooks at the PiecewiseLinearFunctions to decide what to transform
…lock, but I don't think it should have to be.
@codecov
Copy link

codecov bot commented Jan 28, 2023

Codecov Report

Patch coverage: 95.68% and project coverage change: +0.03 🎉

Comparison is base (ad2ba13) 86.97% compared to head (9a78f3f) 87.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2708      +/-   ##
==========================================
+ Coverage   86.97%   87.00%   +0.03%     
==========================================
  Files         752      758       +6     
  Lines       86602    86991     +389     
==========================================
+ Hits        75319    75689     +370     
- Misses      11283    11302      +19     
Flag Coverage Δ
linux 84.00% <95.68%> (+0.05%) ⬆️
osx 73.47% <95.68%> (+0.09%) ⬆️
other 84.18% <95.68%> (+0.05%) ⬆️
win 81.50% <95.68%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...o/contrib/piecewise/piecewise_linear_expression.py 90.00% <90.00%> (ø)
...ib/piecewise/transform/inner_representation_gdp.py 95.31% <95.31%> (ø)
...omo/contrib/piecewise/piecewise_linear_function.py 95.63% <95.63%> (ø)
pyomo/contrib/piecewise/__init__.py 100.00% <100.00%> (ø)
...wise/transform/disaggregated_convex_combination.py 100.00% <100.00%> (ø)
...ib/piecewise/transform/piecewise_to_mip_visitor.py 100.00% <100.00%> (ø)
pyomo/core/expr/compare.py 98.31% <100.00%> (+0.05%) ⬆️
pyomo/gdp/util.py 90.84% <100.00%> (-0.74%) ⬇️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

pyomo/contrib/piecewise/piecewise_linear_expression.py Outdated Show resolved Hide resolved
pyomo/contrib/piecewise/piecewise_linear_expression.py Outdated Show resolved Hide resolved

def nargs(self):
return len(self._args_)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing create_node_with_local_data method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this get called? I can't figure out how to test it.

pyomo/contrib/piecewise/piecewise_linear_function.py Outdated Show resolved Hide resolved
pyomo/contrib/piecewise/piecewise_linear_function.py Outdated Show resolved Hide resolved
pyomo/contrib/piecewise/piecewise_linear_function.py Outdated Show resolved Hide resolved
pyomo/contrib/piecewise/piecewise_linear_function.py Outdated Show resolved Hide resolved
…ction instead of them having to store them, but this doesn't fix the tests yet
…le because of the lambda function in _construct_from_univariate_function_and_segments
…ld the PiecewiseLinearExpression objects to the Vars created by transformation. This way the truth is on the model and they know whether something has been transformed or not.
@emma58
Copy link
Contributor Author

emma58 commented Mar 4, 2023

@jsiirola I think I fixed everything except that PiecewiseLinearFunction objects don't actually pickle it turns out, because of the linear-function creation factory. So not sure how to fix that?

@jsiirola jsiirola merged commit cf3fb9b into Pyomo:main Mar 12, 2023
@emma58 emma58 deleted the pw-linear-function branch February 15, 2024 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants