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: Fixing a bug caused by degenerate simplices #2797

Merged
merged 16 commits into from
Apr 11, 2023

Conversation

emma58
Copy link
Contributor

@emma58 emma58 commented Apr 7, 2023

Fixes # .

Summary/Motivation:

When we construct a PiecewiseLinearFunction from a set of points, a lot of times users will give us a grid. This means that the Delaunay triangulation is quite degenerate, so we get a lot of degenerate simplices back. This PR adds a check after calling the triangulation to filter out all simplices that are not full-dimensional.

Changes proposed in this PR:

  • Filter the simplices from scipy.spatial.Delaunay and keep only full-dimensional ones
  • Log when points were dropped in the triangulation due to numerical issues
  • Raise a DeveloperError when the linear system solve to find the hyperplane above a simplex is unexpectedly singular: this is a sign that we didn't correctly filter out degenerate simplices (in particular, it's possible we'll need a tolerance rather than keeping anything with a determinant that's not exactly 0.)

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.

@emma58 emma58 changed the title contrib.piecewise: Fixing a bug with caused by degenerate simplices contrib.piecewise: Fixing a bug caused by degenerate simplices Apr 7, 2023
@codecov
Copy link

codecov bot commented Apr 9, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (5a9cc2e) 87.01% compared to head (ce046ca) 87.01%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2797   +/-   ##
=======================================
  Coverage   87.01%   87.01%           
=======================================
  Files         763      763           
  Lines       87213    87229   +16     
=======================================
+ Hits        75886    75901   +15     
- Misses      11327    11328    +1     
Flag Coverage Δ
linux 84.02% <100.00%> (+<0.01%) ⬆️
osx 73.52% <100.00%> (+<0.01%) ⬆️
other 84.20% <100.00%> (+<0.01%) ⬆️
win 81.53% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...omo/contrib/piecewise/piecewise_linear_function.py 95.94% <100.00%> (+0.31%) ⬆️

... 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.

@blnicho blnicho requested review from mrmundt and blnicho April 11, 2023 18:40
@@ -30,6 +33,8 @@
# be zero.
ZERO_TOLERANCE = 1e-8

logger = logging.getLogger('contrib.piecewise')
Copy link
Contributor

Choose a reason for hiding this comment

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

We love logging. Yes, we do.

@jsiirola jsiirola merged commit bc96d79 into Pyomo:main Apr 11, 2023
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