Skip to content

Commit

Permalink
Option to skip aprallel constraint checks (IDAES#1417)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 committed May 26, 2024
1 parent 3cf3a84 commit 1d927a6
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions idaes/core/util/model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,15 @@ def _collect_structural_cautions(self):

return cautions

def _collect_numerical_warnings(self, jac=None, nlp=None):
def _collect_numerical_warnings(
self, jac=None, nlp=None, ignore_parallel_components=False
):
"""
Runs checks for numerical warnings and returns two lists.
Args:
ignore_parallel_components - ignore checks for parallel components
Returns:
warnings - list of warning messages from numerical analysis
next_steps - list of suggested next steps to further investigate warnings
Expand Down Expand Up @@ -1236,27 +1241,30 @@ def _collect_numerical_warnings(self, jac=None, nlp=None):
)

# Parallel variables and constraints
partol = self.config.parallel_component_tolerance
par_cons = check_parallel_jacobian(
self._model, tolerance=partol, direction="row", jac=jac, nlp=nlp
)
par_vars = check_parallel_jacobian(
self._model, tolerance=partol, direction="column", jac=jac, nlp=nlp
)
if par_cons:
p = "pair" if len(par_cons) == 1 else "pairs"
warnings.append(
f"WARNING: {len(par_cons)} {p} of constraints are parallel"
f" (to tolerance {partol:.1E})"
if not ignore_parallel_components:
partol = self.config.parallel_component_tolerance
par_cons = check_parallel_jacobian(
self._model, tolerance=partol, direction="row", jac=jac, nlp=nlp
)
next_steps.append(self.display_near_parallel_constraints.__name__ + "()")
if par_vars:
p = "pair" if len(par_vars) == 1 else "pairs"
warnings.append(
f"WARNING: {len(par_vars)} {p} of variables are parallel"
f" (to tolerance {partol:.1E})"
par_vars = check_parallel_jacobian(
self._model, tolerance=partol, direction="column", jac=jac, nlp=nlp
)
next_steps.append(self.display_near_parallel_variables.__name__ + "()")
if par_cons:
p = "pair" if len(par_cons) == 1 else "pairs"
warnings.append(
f"WARNING: {len(par_cons)} {p} of constraints are parallel"
f" (to tolerance {partol:.1E})"
)
next_steps.append(
self.display_near_parallel_constraints.__name__ + "()"
)
if par_vars:
p = "pair" if len(par_vars) == 1 else "pairs"
warnings.append(
f"WARNING: {len(par_vars)} {p} of variables are parallel"
f" (to tolerance {partol:.1E})"
)
next_steps.append(self.display_near_parallel_variables.__name__ + "()")

return warnings, next_steps

Expand Down Expand Up @@ -1404,16 +1412,21 @@ def assert_no_structural_warnings(
if len(warnings) > 0:
raise AssertionError(f"Structural issues found ({len(warnings)}).")

def assert_no_numerical_warnings(self):
def assert_no_numerical_warnings(self, ignore_parallel_components=False):
"""
Checks for numerical warnings in the model and raises an AssertionError
if any are found.
Args:
ignore_parallel_components - ignore checks for parallel components
Raises:
AssertionError if any warnings are identified by numerical analysis.
"""
warnings, _ = self._collect_numerical_warnings()
warnings, _ = self._collect_numerical_warnings(
ignore_parallel_components=ignore_parallel_components
)
if len(warnings) > 0:
raise AssertionError(f"Numerical issues found ({len(warnings)}).")

Expand Down

0 comments on commit 1d927a6

Please sign in to comment.