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] Use standard repn for incidence graph generation #2834

Merged
merged 27 commits into from
May 22, 2023

Conversation

Robbybp
Copy link
Contributor

@Robbybp Robbybp commented May 21, 2023

Fixes

Variables with zero coefficients appear in incidence graphs

Summary/Motivation:

Incidence graphs where 0*x appears as an edge can lead to incorrect results when analyzing singularity or generating decompositions.

Changes proposed in this PR:

  • get_incident_variables function, which accepts a method argument that can be used to switch between using identify_variables and generate_standard_repn
  • IncidenceConfig ConfigBlock to consolidate specification of default options for incidence graph generation
  • Tests for this new functionality, including a linear_only option for incidence graph generation

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.

jsiirola
jsiirola previously approved these changes May 21, 2023
Copy link
Member

@jsiirola jsiirola 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! Just a couple minor questions that you can address or ignore.

pyomo/contrib/incidence_analysis/config.py Outdated Show resolved Hide resolved
pyomo/contrib/incidence_analysis/incidence.py Outdated Show resolved Hide resolved
@jsiirola jsiirola dismissed their stale review May 21, 2023 05:57

(tests need to pass before merging)

@codecov
Copy link

codecov bot commented May 21, 2023

Codecov Report

Patch coverage: 93.33% and project coverage change: -0.01 ⚠️

Comparison is base (dca0388) 87.19% compared to head (eb3d362) 87.19%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2834      +/-   ##
==========================================
- Coverage   87.19%   87.19%   -0.01%     
==========================================
  Files         765      767       +2     
  Lines       88471    88548      +77     
==========================================
+ Hits        77146    77211      +65     
- Misses      11325    11337      +12     
Flag Coverage Δ
linux 84.26% <93.18%> (+0.01%) ⬆️
osx 73.92% <93.18%> (+0.01%) ⬆️
other 84.43% <93.18%> (+0.01%) ⬆️
win 81.81% <93.18%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
pyomo/util/subsystems.py 96.02% <75.00%> (-1.80%) ⬇️
pyomo/contrib/incidence_analysis/incidence.py 94.87% <94.87%> (ø)
pyomo/contrib/incidence_analysis/__init__.py 100.00% <100.00%> (ø)
pyomo/contrib/incidence_analysis/config.py 100.00% <100.00%> (ø)
pyomo/contrib/incidence_analysis/interface.py 96.34% <100.00%> (+0.70%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -53,8 +53,7 @@ with fields for each of the four subsets defined by the partition:
If any variables or constraints are unmatched, the (Jacobian of the) model
is structurally singular.

.. doctest::
:skipif: not scipy_available or not networkx_available or not asl_available
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

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

Can we leave a comment as to why this is not being tested? Or better, why is this nondeterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment noting that the unmatched variables/constraints are not mathematically unique, and expanded on this in the text, noting that they depend on (a) how we identify incident variables and (b) the implementation of the matching algorithm.

@Robbybp
Copy link
Contributor Author

Robbybp commented May 21, 2023

"Regression test" on several examples:

Example N. edges (6.5.0) N. edges (main) N. edges (this PR) Correct?
DoF 3,921 3,933 3,921 Y
Stuct. sing. 6,922 6,943 6,922 Y
Num. sing. 7,282 7,792 7,588 Y
Init. cond. 14, 560 14,560 14,560 Y
Discretization 3,900 3,916 3,900 Y*
Initialization 897 900 897 Y*

*Leads to a different number of diagonal blocks in the block triangularization (between this PR and main)

Here "Correct" means that, with this PR, the analysis leads us to the correct conclusion about what is wrong with the model. These were all run with IDAES 2.0. The comparison in #2816 uses a recent IDAES main, so the numbers reported in these two tables may not be directly comparable.

@Robbybp
Copy link
Contributor Author

Robbybp commented May 22, 2023

Pypy test failure appears unrelated

@Robbybp
Copy link
Contributor Author

Robbybp commented May 22, 2023

@andrewlee94 can you run IDAES tests with this branch?

@andrewlee94
Copy link
Contributor

andrewlee94 commented May 22, 2023

@Robbybp That fixed the known failures, but it does create two new ones, both related to the following:

self = <pyomo.util.subsystems.ParamSweeper object at 0x7f549e6820d0>

    def __enter__(self):
        to_fix = self._vars_to_fix
        to_deactivate = self._cons_to_deactivate
        to_set = self._comps_to_set
        to_unfix = self._vars_to_unfix
>       self._var_was_fixed = [(var, var.fixed) for var in to_fix + to_unfix]
E       TypeError: unsupported operand type(s) for +: 'ComponentMap' and 'list'

These are coming up in the gas network tests (but I don't think that actually matters here).

@Robbybp
Copy link
Contributor Author

Robbybp commented May 22, 2023

@andrewlee94 this should be fixed in IDAES/idaes-pse#1188

@mrmundt
Copy link
Contributor

mrmundt commented May 22, 2023

@Robbybp - Okay if we merge?

@Robbybp
Copy link
Contributor Author

Robbybp commented May 22, 2023

@mrmundt Yep!

@mrmundt mrmundt merged commit aa4d274 into Pyomo:main May 22, 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.

6 participants