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

Add support for Greybox model DOF counitng in degrees_of_freedom function #1512

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions idaes/core/util/model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
deactivated_objectives_set,
variables_in_activated_constraints_set,
variables_not_in_activated_constraints_set,
number_activated_greybox_equalities,
number_deactivated_greybox_equalities,
activated_greybox_block_set,
deactivated_greybox_block_set,
greybox_block_set,
unfixed_greybox_variables,
greybox_variables,
degrees_of_freedom,
large_residuals_set,
variables_near_bounds_set,
Expand Down Expand Up @@ -486,7 +493,10 @@ def __init__(self, model: BlockData, **kwargs):
"model argument must be an instance of a Pyomo BlockData object "
"(either a scalar Block or an element of an indexed Block)."
)

if len(greybox_block_set(model)) != 0:
raise NotImplementedError(
"Model contains Greybox models, which are not supported by Diagnostics toolbox at the moment"
)
self._model = model
self.config = CONFIG(kwargs)

Expand Down Expand Up @@ -1746,7 +1756,12 @@ def report_structural_issues(self, stream=None):

# Potential evaluation errors
# TODO: High Index?
if len(greybox_block_set(self._model)) != 0:
raise NotImplementedError(
"Model contains Greybox models, which are not supported by Diagnostics toolbox at the moment"
)
stats = _collect_model_statistics(self._model)

warnings, next_steps = self._collect_structural_warnings()
cautions = self._collect_structural_cautions()

Expand Down Expand Up @@ -1790,7 +1805,6 @@ def report_numerical_issues(self, stream=None):
"""
if stream is None:
stream = sys.stdout

jac, nlp = get_jacobian(self._model, scaled=False)

warnings, next_steps = self._collect_numerical_warnings(jac=jac, nlp=nlp)
Expand Down Expand Up @@ -1935,7 +1949,10 @@ def __init__(self, model: BlockData, **kwargs):
"model argument must be an instance of a Pyomo BlockData object "
"(either a scalar Block or an element of an indexed Block)."
)

if len(greybox_block_set(model)) != 0:
raise NotImplementedError(
"Model contains Greybox models, which are not supported by Diagnostics toolbox at the moment"
)
self._model = model
self.config = SVDCONFIG(kwargs)

Expand Down Expand Up @@ -2377,7 +2394,10 @@ def __init__(self, model, **kwargs):
"model argument must be an instance of a Pyomo BlockData object "
"(either a scalar Block or an element of an indexed Block)."
)

if len(greybox_block_set(model)) != 0:
raise NotImplementedError(
"Model contains Greybox models, which are not supported by Diagnostics toolbox at the moment"
)
self._model = model
self.config = DHCONFIG(kwargs)

Expand Down Expand Up @@ -3475,7 +3495,10 @@ def __init__(self, model, **kwargs):
"model argument must be an instance of a Pyomo BlockData object "
"(either a scalar Block or an element of an indexed Block)."
)

if len(greybox_block_set(model)) != 0:
raise NotImplementedError(
"Model contains Greybox models, which are not supported by Diagnostics toolbox at the moment"
)
self.config = self.CONFIG(kwargs)

self._model = model
Expand Down Expand Up @@ -4402,8 +4425,8 @@ def _collect_model_statistics(model):
f"(External: {len(ext_fixed_vars_in_constraints)})"
)
stats.append(
f"{TAB}Activated Equality Constraints: {len(activated_equalities_set(model))} "
f"(Deactivated: {len(deactivated_equalities_set(model))})"
f"{TAB}Activated Equality Constraints: {len(activated_equalities_set(model))+number_activated_greybox_equalities(model)} "
f"(Deactivated: {len(deactivated_equalities_set(model))+number_deactivated_greybox_equalities(model)})"
)
stats.append(
f"{TAB}Activated Inequality Constraints: {len(activated_inequalities_set(model))} "
Expand All @@ -4414,6 +4437,21 @@ def _collect_model_statistics(model):
f"(Deactivated: {len(deactivated_objectives_set(model))})"
)

# Only show graybox info if they are present
if len(greybox_block_set(model)) != 0:
stats.append(f"{TAB}GreyBox Statistics")
stats.append(
f"{TAB* 2}Activated GreyBox models: {len(activated_greybox_block_set(model))} "
f"(Deactivated: {len(deactivated_greybox_block_set(model))})"
)
stats.append(
f"{TAB* 2}Activated GreyBox Equalities: {number_activated_greybox_equalities(model)} "
f"(Deactivated: {number_deactivated_greybox_equalities(model)})"
)
stats.append(
f"{TAB* 2}Free Variables in Activated GreyBox Equalities: {len(unfixed_greybox_variables(model))} (Fixed: {len(greybox_variables(model)-unfixed_greybox_variables(model))})"
)

return stats


Expand Down
Loading
Loading