-
Notifications
You must be signed in to change notification settings - Fork 234
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 parallel constraint/variable check to report_numerical_issues
#1385
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ed3eb3a
update imports of native_types and pyomo_constant_types (which is dep…
Robbybp 842650b
Adding next batch of diagnostics tests
andrewlee94 6d09b5c
Next batch of daignsotics tests
andrewlee94 1389783
Merge branch 'consttype-import' of https://github.com/Robbybp/idaes-p…
andrewlee94 01e010c
Work around for ASL issue
andrewlee94 cc9c240
Adding more diagnostics checks
andrewlee94 2189347
Last unit model diagnostics tests
andrewlee94 7755690
Merge branch 'main' into diagnostics_testing
andrewlee94 8a9a7ee
Fixing typo
andrewlee94 92b54f4
Merge branch 'diagnostics_testing' of https://github.com/andrewlee94/…
andrewlee94 1b91594
Improving fix for ASL issue
andrewlee94 7f4a976
Better implementation of fix
andrewlee94 5af6d99
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
andrewlee94 448081a
Fixing pylint and Python 3.8 failures
andrewlee94 2d8afda
Removing old implementation of workaround
andrewlee94 a4a84dd
Fixing noisy test
andrewlee94 4cf5fb2
Moving registration of external functions
andrewlee94 55258cf
Reverting to version that works on Windows
andrewlee94 cd47ae2
Trying another way to get binary files
andrewlee94 dc7f8cc
add parallel variable/constraint checks to report_numerical_issues; c…
Robbybp 6c5a6c4
update tests
Robbybp 0a1894a
Merge branch 'main' of https://github.com/idaes/idaes-pse into diagno…
Robbybp 06c239d
Merge branch 'main' of https://github.com/idaes/idaes-pse into diagno…
Robbybp ad00bf9
tighten parallel_component_tolerance to 1e-8
Robbybp 69ba71f
adjust model to make parallel variable test less sensitive
Robbybp 8960343
update test to reflect new default tolerance of 1e-8
Robbybp c34099b
consistent format for displaying parallel tolerance
Robbybp d088358
Merge branch 'main' into diagnostics-parallel
Robbybp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,10 +975,10 @@ def test_display_near_parallel_variables(self): | |
model.v3 = Var() | ||
model.v4 = Var() | ||
|
||
model.c1 = Constraint(expr=model.v1 == model.v2 - 0.99999 * model.v4) | ||
model.c2 = Constraint(expr=model.v1 + 1.00001 * model.v4 == 1e-8 * model.v3) | ||
model.c1 = Constraint(expr=1e-8 * model.v1 == 1e-8 * model.v2 - 1e-8 * model.v4) | ||
model.c2 = Constraint(expr=1e-8 * model.v1 + 1e-8 * model.v4 == model.v3) | ||
model.c3 = Constraint( | ||
expr=1e8 * (model.v1 + model.v4) + 1e10 * model.v2 == 1e-6 * model.v3 | ||
expr=1e3 * (model.v1 + model.v4) + 1e3 * model.v2 == model.v3 | ||
) | ||
|
||
dt = DiagnosticsToolbox(model=model) | ||
|
@@ -1121,7 +1121,7 @@ def test_collect_numerical_warnings_jacobian(self): | |
|
||
warnings, next_steps = dt._collect_numerical_warnings() | ||
|
||
assert len(warnings) == 3 | ||
assert len(warnings) == 4 | ||
assert ( | ||
"WARNING: 2 Variables with extreme Jacobian values (<1.0E-08 or >1.0E+08)" | ||
in warnings | ||
|
@@ -1132,7 +1132,7 @@ def test_collect_numerical_warnings_jacobian(self): | |
) | ||
assert "WARNING: 1 Constraint with large residuals (>1.0E-05)" in warnings | ||
|
||
assert len(next_steps) == 3 | ||
assert len(next_steps) == 4 | ||
assert "display_variables_with_extreme_jacobians()" in next_steps | ||
assert "display_constraints_with_extreme_jacobians()" in next_steps | ||
assert "display_constraints_with_large_residuals()" in next_steps | ||
|
@@ -1338,8 +1338,7 @@ def test_report_numerical_issues_ok(self): | |
Suggested next steps: | ||
|
||
If you still have issues converging your model consider: | ||
display_near_parallel_constraints() | ||
display_near_parallel_variables() | ||
|
||
prepare_degeneracy_hunter() | ||
prepare_svd_toolbox() | ||
|
||
|
@@ -1369,9 +1368,11 @@ def test_report_numerical_issues_exactly_singular(self): | |
Jacobian Condition Number: Undefined (Exactly Singular) | ||
|
||
------------------------------------------------------------------------------------ | ||
1 WARNINGS | ||
3 WARNINGS | ||
|
||
WARNING: 2 Constraints with large residuals (>1.0E-05) | ||
WARNING: 1 pair of constraints are parallel (to tolerance 1.0E-08) | ||
WARNING: 1 pair of variables are parallel (to tolerance 1.0E-08) | ||
|
||
------------------------------------------------------------------------------------ | ||
0 Cautions | ||
|
@@ -1382,6 +1383,8 @@ def test_report_numerical_issues_exactly_singular(self): | |
Suggested next steps: | ||
|
||
display_constraints_with_large_residuals() | ||
display_near_parallel_constraints() | ||
display_near_parallel_variables() | ||
|
||
==================================================================================== | ||
""" | ||
|
@@ -1433,8 +1436,8 @@ def test_report_numerical_issues_jacobian(self): | |
model.v2 = Var(initialize=0) | ||
model.v3 = Var(initialize=0) | ||
|
||
model.c1 = Constraint(expr=model.v1 == model.v2) | ||
model.c2 = Constraint(expr=model.v1 == 1e-8 * model.v3) | ||
model.c1 = Constraint(expr=1e-2 * model.v1 == model.v2) | ||
model.c2 = Constraint(expr=1e-2 * model.v1 == 1e-8 * model.v3) | ||
model.c3 = Constraint(expr=1e8 * model.v1 + 1e10 * model.v2 == 1e-6 * model.v3) | ||
Comment on lines
-1436
to
1441
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I updated coefficients on |
||
|
||
dt = DiagnosticsToolbox(model=model) | ||
|
@@ -1445,14 +1448,15 @@ def test_report_numerical_issues_jacobian(self): | |
expected = """==================================================================================== | ||
Model Statistics | ||
|
||
Jacobian Condition Number: 1.407E+18 | ||
Jacobian Condition Number: 1.118E+18 | ||
|
||
------------------------------------------------------------------------------------ | ||
3 WARNINGS | ||
4 WARNINGS | ||
|
||
WARNING: 1 Constraint with large residuals (>1.0E-05) | ||
WARNING: 2 Variables with extreme Jacobian values (<1.0E-08 or >1.0E+08) | ||
WARNING: 1 Constraint with extreme Jacobian values (<1.0E-08 or >1.0E+08) | ||
WARNING: 3 pairs of variables are parallel (to tolerance 1.0E-08) | ||
|
||
------------------------------------------------------------------------------------ | ||
4 Cautions | ||
|
@@ -1468,6 +1472,7 @@ def test_report_numerical_issues_jacobian(self): | |
display_constraints_with_large_residuals() | ||
display_variables_with_extreme_jacobians() | ||
display_constraints_with_extreme_jacobians() | ||
display_near_parallel_variables() | ||
|
||
==================================================================================== | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was pretty fragile. The coefficients on
v3
are small relative to those on other variables, so its dot product is vacuously parallel with anything. This didn't show up previously because we were relying on the absolute tolerance of 1e-4 to give it an empty sparsity pattern. Maybe this raises the question of what to do when one of the vectors we are testing is zero. I've removed the coefficients onv3
so that this isn't an issue for now.Also, the 1e-8 ratio between small and large coefficients for
v1
andv2
lead to relative "distances-from-parallel" that are very close to our new tolerance of 1e-8, so I've adjusted some coefficients to give us a little more buffer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really because the relative tolerance should be comparing to is
diff <= tolerance * unorm *vnorm
, notdiff <= tolerance * max(unorm, vnorm)
. The absolute tolerance probably can get phased out entirely.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
unorm * vnorm
is the right denominator for the relative tolerance. I would still like to have an absolute tolerance, though, as I wouldn't want(1e-9, 2e-9)
to be considered parallel to(1, 2)
. (Unless we want to consider a zero vector as "parallel to everything", which I think is debatable.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support filtering out rows/columns with norms that are effectively zero, because otherwise they'll just spam the log as being parallel to every other row. No need to use an absolute tolerance for the inner product, though, we can just choose to skip displaying the row/column if one of the norms is too small.
In the diagnostics toolbox, the tolerance for this filtering should be the
CONFIG.jacobian_small_value_warning
, the same tolerance as used indisplay_variables_with_extreme_jacobians
anddisplay_constraints_with_extreme_jacobians
to display a warning message. That way it's displayed (once) to the user there.