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

contrib.piecewise: Adding nonlinear-to-piecewise-linear transformation #3333

Merged
merged 58 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0f6fe16
Adding initial draft of nonlinear to pwl transformation
emma58 Mar 28, 2024
b34820b
Not screaming about fixed Var bounds, but this still doesn't work bec…
emma58 Mar 28, 2024
33fd778
Complete rewrite of nonlinear to piecewise linear
emma58 Mar 29, 2024
3271a0e
Adding handler to safely ignore LogicalConstraints in piecewise linea…
emma58 Mar 29, 2024
159766a
Starting to add tests for nonlinear to pw linear transformation
emma58 Mar 29, 2024
f295490
Adding mapping between original and transformed components and starti…
emma58 Apr 3, 2024
51c3967
Merging main
emma58 Jul 18, 2024
4811883
whoops, fixing typo from last commit
emma58 Jul 18, 2024
02cef2d
Putting common part of log x tests into helper function for tests
emma58 Jul 18, 2024
a619cf6
Removing hard dependencies
emma58 Jul 18, 2024
5ccd890
Generalizing log tests, adding chaos test that doesn't do anything yet
emma58 Jul 23, 2024
2c6b760
Adding in an API to get the transformed linear and general nonlinear …
emma58 Jul 30, 2024
f8d9c53
Merge branch 'main' into nonlinear-to-pwl
emma58 Jul 30, 2024
5b85af7
Adding APIs for getting transformed nonlinear and quadratic Constrain…
emma58 Jul 31, 2024
1cc71bd
Adding a lot of tests, including 3D
emma58 Jul 31, 2024
2a6ad46
Incorporating black's opinions
emma58 Jul 31, 2024
e3d3fd6
Fixing some typos
emma58 Jul 31, 2024
1fe0f00
Fixing a couple bugs with additive decomposition in nonlinear-to-pwl
emma58 Aug 2, 2024
9ae91fb
Adding partial test of additive decomposition
emma58 Aug 2, 2024
8074fe0
NFC: Reformatting some docstrings
emma58 Aug 5, 2024
b78efe5
Adding max depth argument to be used for the linear tree domain parti…
emma58 Aug 5, 2024
31a95ba
Adding tests with absolute value for linear model tree partitioning
emma58 Aug 5, 2024
c89ddbf
NFC: black
emma58 Aug 5, 2024
e4bfca0
Finishing integration test, adding bigger linear model tree test
emma58 Aug 5, 2024
96b9aee
NFC: black
emma58 Aug 5, 2024
76459a2
nonlinear_to_pwl.py
emma58 Aug 5, 2024
c61a705
Black
emma58 Aug 5, 2024
c8b46d5
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 5, 2024
4145590
Making a lot of helper functions private
emma58 Aug 5, 2024
9e56e1d
NFC: removing some comments
emma58 Aug 5, 2024
738a8f8
Apparently black has an opinion about that
emma58 Aug 5, 2024
92b8ba1
DomainPartitioningMethod imports with the module
emma58 Aug 5, 2024
ad74710
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 5, 2024
953a39d
Skipping tests when numpy not available
emma58 Aug 6, 2024
03010fe
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 6, 2024
398c468
Merge branch 'nonlinear-to-pwl' of github.com:emma58/pyomo into nonli…
emma58 Aug 6, 2024
68b15a5
HA, she can code... Fixing dumb typos in previous commit
emma58 Aug 6, 2024
dabafbf
Skipping 3 more tests if scipy is not available
emma58 Aug 6, 2024
ead6f93
Adding a (currently failing) test for cloning a transformed model
emma58 Aug 12, 2024
7bd2118
Fixing two bugs with cloning transformed PiecewiseLinearFunctions
emma58 Aug 13, 2024
208c9d6
Black
emma58 Aug 13, 2024
ffcffc6
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 13, 2024
defc953
Adding a test for cloning a multivariate piecewise linear function too
emma58 Aug 13, 2024
46e5bfb
Adding linear-tree to optional dependencies
emma58 Aug 13, 2024
fc5ebc8
Black being black
emma58 Aug 13, 2024
844b09a
Adding (failing) test for sampling discrete domains
emma58 Aug 13, 2024
11326eb
Only use linear-tree for pypi, it appears to not be on conda
emma58 Aug 13, 2024
3c233e1
Whoops, actually intercepting the logging stream I want to make sure …
emma58 Aug 13, 2024
e890a25
Not sampling outside of discrete domains in uniform_grid and random_grid
emma58 Aug 13, 2024
10b9026
black
emma58 Aug 13, 2024
a8ed8c9
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 13, 2024
34cc34e
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 14, 2024
86d4fff
not triggering scipy install on pypy
emma58 Aug 14, 2024
5bda911
Skipping two more tests when scipy not available--this really should …
emma58 Aug 15, 2024
652389f
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 15, 2024
804ad04
Moving quadratic repn visitor to instance attribute on nonlinear to p…
emma58 Aug 19, 2024
3a0c49e
Merge branch 'nonlinear-to-pwl' of github.com:emma58/pyomo into nonli…
emma58 Aug 19, 2024
b3429e1
Merge branch 'main' into nonlinear-to-pwl
emma58 Aug 19, 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
4 changes: 2 additions & 2 deletions .github/workflows/test_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defaults:
env:
PYTHONWARNINGS: ignore::UserWarning
PYTHON_CORE_PKGS: wheel
PYPI_ONLY: z3-solver
PYPY_EXCLUDE: scipy numdifftools seaborn statsmodels
PYPI_ONLY: z3-solver linear-tree
PYPY_EXCLUDE: scipy numdifftools seaborn statsmodels linear-tree
CACHE_VER: v221013.1
NEOS_EMAIL: tests@pyomo.org
SRC_REF: ${{ github.head_ref || github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ defaults:
env:
PYTHONWARNINGS: ignore::UserWarning
PYTHON_CORE_PKGS: wheel
PYPI_ONLY: z3-solver
PYPY_EXCLUDE: scipy numdifftools seaborn statsmodels
PYPI_ONLY: z3-solver linear-tree
PYPY_EXCLUDE: scipy numdifftools seaborn statsmodels linear-tree
CACHE_VER: v221013.1
NEOS_EMAIL: tests@pyomo.org
SRC_REF: ${{ github.head_ref || github.ref }}
Expand Down
4 changes: 4 additions & 0 deletions pyomo/contrib/piecewise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
from pyomo.contrib.piecewise.transform.convex_combination import (
ConvexCombinationTransformation,
)
from pyomo.contrib.piecewise.transform.nonlinear_to_pwl import (
DomainPartitioningMethod,
NonlinearToPWL,
)
from pyomo.contrib.piecewise.transform.nested_inner_repn import (
NestedInnerRepresentationGDPTransformation,
)
Expand Down
16 changes: 13 additions & 3 deletions pyomo/contrib/piecewise/piecewise_linear_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
BlockData.__init__(self, component)

with self._declare_reserved_components():
# map of PiecewiseLinearExpression objects to integer indices in
# self._expressions
self._expression_ids = ComponentMap()
# index is monotonically increasing integer
self._expressions = Expression(NonNegativeIntegers)
self._transformed_exprs = ComponentMap()
self._simplices = None
Expand All @@ -63,8 +67,9 @@
return self._evaluate(*args)
else:
expr = PiecewiseLinearExpression(args, self)
idx = id(expr)
idx = len(self._expressions)
self._expressions[idx] = expr
self._expression_ids[expr] = idx
return self._expressions[idx]

def _evaluate(self, *args):
Expand Down Expand Up @@ -134,7 +139,12 @@
Records on the PiecewiseLinearFunction object that the transformed
form of the PiecewiseLinearExpression object pw_expr is the Var v.
"""
self._transformed_exprs[self._expressions[id(pw_expr)]] = v
if pw_expr not in self._expression_ids:
raise DeveloperError(

Check warning on line 143 in pyomo/contrib/piecewise/piecewise_linear_function.py

View check run for this annotation

Codecov / codecov/patch

pyomo/contrib/piecewise/piecewise_linear_function.py#L143

Added line #L143 was not covered by tests
"ID of PiecewiseLinearExpression '%s' not in the _expression_ids "
"dictionary of PiecewiseLinearFunction '%s'" % (pw_expr, self)
)
self._transformed_exprs[self._expressions[self._expression_ids[pw_expr]]] = v

def get_transformation_var(self, pw_expr):
"""
Expand All @@ -159,7 +169,7 @@


class _multivariate_linear_functor(AutoSlots.Mixin):
__slots__ = 'normal'
__slots__ = ('normal',)

def __init__(self, normal):
self.normal = normal
Expand Down
Loading
Loading