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

Add subgraph method to IncidencegraphInterface #3122

Merged
merged 10 commits into from
Feb 15, 2024

Conversation

Robbybp
Copy link
Contributor

@Robbybp Robbybp commented Feb 5, 2024

Fixes

Reduces the number of times we need to walk expression trees (e.g. to compute AMPLRepns) when generating multiple different incidence graphs based on the same model.

Summary/Motivation:

Using IncidenceMethod.ampl_repn or IncidenceMethod.standard_repn seems to introduce significant overhead to incidence graph construction. Often, I want to work with several subgraphs based on a single model. For example, the subgraph that only includes equality constraints, or the subgraph on a particular set of variables (a particular block in a block triangularization, for instance). In these cases, constructing several incidence graphs becomes a performance bottleneck due to the effort required to determine variable-constraint incidence (edges in the graph). An IncidenceGraphInterface.subgraph method lets us get around this re-construction. Note that the incidence graph's data structures are copied, not modified in-place.

Changes proposed in this PR:

  • Add IncidenceGraphInterface.subgraph method
  • Allow construction of IncidenceGraphInterface from a tuple of (nz.Graph, list[Var], list[Constraint])
  • Rewrite extract_bipartite_subgraph to use NetworkX's subgraph and relabel_nodes methods, instead of re-implementing my own versions of them.

Note that this builds on #3069

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.

@Robbybp Robbybp changed the title Incidence subgraph Add subgraph method to IncidencegraphInterface Feb 5, 2024
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (5903fbc) 88.32% compared to head (90c4078) 88.32%.

Files Patch % Lines
pyomo/contrib/incidence_analysis/interface.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3122   +/-   ##
=======================================
  Coverage   88.32%   88.32%           
=======================================
  Files         832      832           
  Lines       92483    92492    +9     
=======================================
+ Hits        81685    81693    +8     
- Misses      10798    10799    +1     
Flag Coverage Δ
linux 86.21% <95.45%> (+<0.01%) ⬆️
osx 75.67% <95.45%> (+<0.01%) ⬆️
other 86.41% <95.45%> (+<0.01%) ⬆️
win 83.63% <95.45%> (+<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.

@blnicho blnicho self-requested a review February 13, 2024 19:46
@jsiirola jsiirola merged commit f81f34f into Pyomo:main Feb 15, 2024
33 checks passed
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.

5 participants