Skip to content

Conversation

@michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR modifies the contrib.piecewise.nonlinear_to_pwl transformation so that linear parts of a constraint always get separated from the nonlinear parts, even if additively_decompose is False. The idea is that

y >= exp(x) + x**3

should become

y >= PWL(exp(x) + x**3)

and not

0 >= PWL(exp(x) + x**3 - y)

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.

@michaelbynum michaelbynum requested a review from emma58 January 13, 2026 15:11
@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.44%. Comparing base (e0fcc81) to head (cff61ab).

Files with missing lines Patch % Lines
...mo/contrib/piecewise/transform/nonlinear_to_pwl.py 89.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3814      +/-   ##
==========================================
- Coverage   89.45%   89.44%   -0.01%     
==========================================
  Files         905      905              
  Lines      105467   105492      +25     
==========================================
+ Hits        94341    94361      +20     
- Misses      11126    11131       +5     
Flag Coverage Δ
builders 29.13% <10.34%> (-0.02%) ⬇️
default 86.07% <89.65%> (?)
expensive 35.76% <10.34%> (?)
linux 86.76% <89.65%> (-2.45%) ⬇️
linux_other 86.76% <89.65%> (-0.01%) ⬇️
osx 82.92% <89.65%> (-0.01%) ⬇️
win 85.00% <89.65%> (-0.01%) ⬇️
win_other 85.00% <89.65%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@emma58 emma58 left a comment

Choose a reason for hiding this comment

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

I think this makes sense. If you could put in a comment with the example you put in the PR description for why _separate_linear_parts is necessary, I think that would be helpful for future us. My guess is this is not currently the fastest thing we could possibly do, but for now, I'm not so concerned with that. @jsiirola, @sadavis1, @bammari, this might be worth glancing at if you have a minute.

Comment on lines +674 to +677
if x1 == x2:
nonlinear += coef * var_map[x1] ** 2
else:
nonlinear += coef * (var_map[x1] * var_map[x2])
Copy link
Contributor

Choose a reason for hiding this comment

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

Does separating these two cases matter? I mean, obviously you make a different expression tree, but do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it matters to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to leave this just for consistency with QuadraticRepn.

Comment on lines +684 to +686
if repn.multiplier_flag(repn.multiplier) != 1:
linear *= repn.multiplier
nonlinear *= repn.multiplier
Copy link
Contributor

@emma58 emma58 Jan 13, 2026

Choose a reason for hiding this comment

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

@jsiirola, can this happen? I have something in the back of my mind telling me multiplier is sure to be 1 at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied the to_expression code from the QuadraticRepn class and modified it slightly...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which is to say that I have no idea. I'll take a look, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I can't read. This question was for @jsiirola. My bad.

@michaelbynum
Copy link
Contributor Author

Okay, if this does make some sense, I'll clean it up a bit.

@michaelbynum
Copy link
Contributor Author

Okay, assuming tests pass, this should be good to go.

Copy link
Contributor

@emma58 emma58 left a comment

Choose a reason for hiding this comment

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

This looks good to me. I still have the multiplier question, if you can check that when you look, @jsiirola

@blnicho blnicho requested a review from jsiirola January 21, 2026 06:19
@github-project-automation github-project-automation bot moved this from Todo to Reviewer Approved in Pyomo 6.10 Jan 21, 2026
@blnicho blnicho moved this from Reviewer Approved to Review In Progress in Pyomo 6.10 Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

3 participants