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

Fix methods in SVD Toolbox #1288

Merged
merged 6 commits into from
Dec 7, 2023
Merged

Fix methods in SVD Toolbox #1288

merged 6 commits into from
Dec 7, 2023

Conversation

dallan-keylogic
Copy link
Contributor

@dallan-keylogic dallan-keylogic commented Nov 16, 2023

Summary/Motivation:

Use PyNumero methods to get constraint/variable indices rather than list.index because (I think) list.index uses == to compare elements, which is not what should be done for Pyomo objects. Fixes #1285 .

Also add in string formatting for magnitude of Jacobian elements. Now it uses scientific notation with three digits past the decimal place. It's a lot better than having to deal with 16 digits.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  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.

@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Nov 16, 2023
Copy link

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (214f32a) 77.41% compared to head (bb8f3ba) 77.40%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1288      +/-   ##
==========================================
- Coverage   77.41%   77.40%   -0.01%     
==========================================
  Files         390      390              
  Lines       63404    63399       -5     
  Branches    11658    11658              
==========================================
- Hits        49082    49074       -8     
- Misses      11793    11797       +4     
+ Partials     2529     2528       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1450,6 +1450,10 @@ def __init__(self, model: _BlockData, **kwargs):
self._model, scaled=False, equality_constraints_only=True
)

# Get list of equality constraint and variable names
self.eq_con_list = self.nlp.get_pyomo_equality_constraints()
Copy link
Member

Choose a reason for hiding this comment

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

I think you should make these private. There is no reason the user should be changing these.

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 they should be changing them, but they might have the desire to look at them. We can still make them semiprivate, though.

Copy link
Member

Choose a reason for hiding this comment

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

If they want to see them then they can access to the nlp object themselves, so I would tend toward hiding them until w have a good case otherwise (and then consider making them properties so they can't be changed). "Private" in Python is just convention anyways.

Copy link
Member

@andrewlee94 andrewlee94 left a comment

Choose a reason for hiding this comment

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

Only one minor request.

Copy link
Member

@Robbybp Robbybp left a comment

Choose a reason for hiding this comment

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

Good fix. list.index is indeed not safe here.

Comment on lines -1633 to +1629
nonzeroes = self.jacobian[:, var_idx].nonzero()
nonzeros = self.jacobian.getcol(var_idx).nonzero()
Copy link
Member

Choose a reason for hiding this comment

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

What is the type of self.jacobian here? I.e. dense, COO, CSC, etc. I guess for a single variable, performance isn't an issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's some sparse type, I forget whether it's row or column based. Performance probably isn't an issue, so this is probably unnecessary, but I'm familiar with the methods whereas it's unclear (at least to me) how indexing sparse matrices works.

Copy link
Member

@Robbybp Robbybp Dec 7, 2023

Choose a reason for hiding this comment

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

getcol and indexing do the same thing AFAIK. So one of row/col is slow and one is fast depending on whether the matrix CSC or CSR. If the matrix is COO, both are slow.

@andrewlee94 andrewlee94 enabled auto-merge (squash) December 7, 2023 19:23
@andrewlee94 andrewlee94 merged commit 3e9b43c into IDAES:main Dec 7, 2023
38 of 39 checks passed
@dallan-keylogic dallan-keylogic deleted the svd_fix branch December 7, 2023 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SVD Toolbox display_constraints_including_variable error
4 participants