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 88.17%. Comparing base (8fbddce) to head (7b78841).

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.44%   88.17%   -1.28%     
==========================================
  Files         906      906              
  Lines      105444   105469      +25     
==========================================
- Hits        94317    92993    -1324     
- Misses      11127    12476    +1349     
Flag Coverage Δ
builders 29.14% <10.34%> (-0.01%) ⬇️
default 86.05% <89.65%> (?)
expensive 35.75% <10.34%> (?)
linux 70.67% <75.86%> (-18.54%) ⬇️
linux_other 70.67% <75.86%> (-16.05%) ⬇️
osx ?
win ?
win_other ?

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.

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.

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.

2 participants