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

Bugfix: FBBT with ExternalFunction expressions #2657

Merged
merged 4 commits into from
Dec 6, 2022

Conversation

jsiirola
Copy link
Member

@jsiirola jsiirola commented Dec 5, 2022

Fixes #2650 .

Summary/Motivation:

This resolves exceptions raised by FBBT for expressions containing ExternalFunctionExpression nodes with string arguments. This works by treating External Functions as unbounded leaf nodes in both the root-to-leaf and leaf-to-root walkers.

Changes proposed in this PR:

  • Add special handling for ExternalFunctionExpression nodes
  • Simplify handling of NPV nodes (test is_potentially_variable and treat them as constant nodes as opposed to descending into them)
  • Add test for FBBT with ExternalFunctionExpression nodes.

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.

Copy link
Contributor

@michaelbynum michaelbynum left a comment

Choose a reason for hiding this comment

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

Assuming tests pass, this looks good to me.

Comment on lines +1131 to +1136
if not node.is_potentially_variable():
# NPV nodes are effectively constant leaves. Evaluate it
# and return the value.
val = value(node)
self.bnds_dict[node] = (val, val)
return True, None
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this :)

Comment on lines +1057 to +1058
if self.tightener is not fbbt:
raise unittest.SkipTest('Appsi FBBT does not support unkown expressions yet')
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we add a ticket to remind ourselves to add ExternalFunctionExpression to APPSI? I believe the issue is not actually the ExternalFunctionExpression, but rather that they are allowed (by AMPL and Pyomo) to have str arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fairly certain an exception would be raised somewhere else if we fixed the str problem. Yes, we should add a ticket.

@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Base: 87.03% // Head: 87.06% // Increases project coverage by +0.03% 🎉

Coverage data is based on head (21e3d55) compared to base (da48977).
Patch coverage: 85.71% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2657      +/-   ##
==========================================
+ Coverage   87.03%   87.06%   +0.03%     
==========================================
  Files         754      754              
  Lines       84051    84362     +311     
==========================================
+ Hits        73151    73448     +297     
- Misses      10900    10914      +14     
Flag Coverage Δ
linux 84.44% <85.71%> (-0.01%) ⬇️
osx 74.84% <85.71%> (+<0.01%) ⬆️
other 84.63% <85.71%> (+<0.01%) ⬆️
win 81.79% <85.71%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
pyomo/contrib/fbbt/fbbt.py 96.67% <85.71%> (-0.05%) ⬇️
pyomo/core/expr/visitor.py 93.24% <0.00%> (-0.16%) ⬇️
pyomo/contrib/pyros/uncertainty_sets.py 93.49% <0.00%> (+0.93%) ⬆️

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 at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants