Skip to content

Commit

Permalink
fix tests and black
Browse files Browse the repository at this point in the history
  • Loading branch information
dallan-keylogic committed Nov 16, 2023
1 parent 84c7941 commit 926cd42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions idaes/core/util/model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ def display_constraints_including_variable(self, variable, stream=None):
# Get index of variable in Jacobian
try:
var_idx = self.nlp.get_primal_indices([variable])[0]
except (ValueError, PyomoException):
except (KeyError, PyomoException):
raise AttributeError(f"Could not find {variable.name} in model.")

nonzeros = self.jacobian.getcol(var_idx).nonzero()
Expand Down Expand Up @@ -1670,15 +1670,17 @@ def display_variables_in_constraint(self, constraint, stream=None):
# Get index of variable in Jacobian
try:
con_idx = self.nlp.get_constraint_indices([constraint])[0]
except ValueError:
except KeyError:
raise AttributeError(f"Could not find {constraint.name} in model.")

nonzeros = self.jacobian[con_idx, :].nonzero()

# Build a list of all vars in constraint
vars_in_cons = []
for c in nonzeros[1]:
vars_in_cons.append(f"{self.var_list[c].name}: {self.jacobian[(con_idx, c)]:.3e}")
vars_in_cons.append(
f"{self.var_list[c].name}: {self.jacobian[(con_idx, c)]:.3e}"
)

# Write the output
_write_report_section(
Expand Down
8 changes: 4 additions & 4 deletions idaes/core/util/tests/test_model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,8 @@ def test_display_constraints_including_variable(self):
expected = """====================================================================================
The following constraints involve v[1]:
c1: 1.0
c4: 8.0
c1: 1.000e+00
c4: 8.000e+00
====================================================================================
"""
Expand Down Expand Up @@ -1653,8 +1653,8 @@ def test_display_variables_in_constraint(self):
expected = """====================================================================================
The following variables are involved in c1:
v[1]: 1.0
v[2]: 2.0
v[1]: 1.000e+00
v[2]: 2.000e+00
====================================================================================
"""
Expand Down

0 comments on commit 926cd42

Please sign in to comment.