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

Merged
merged 23 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fb0f8fd
first commit
avdudchenko Oct 26, 2024
a719e47
typo fixes
avdudchenko Oct 26, 2024
9a09cc0
Update model_statistics.py
avdudchenko Oct 26, 2024
4a25d72
updates to tests
avdudchenko Oct 28, 2024
2324cbb
moved where we count greybox var
avdudchenko Oct 28, 2024
01c3a8a
add additonal functions to get grayboxblocks
avdudchenko Oct 28, 2024
e67e56b
initial addi tion of grayboxs stats to dignostic tools
avdudchenko Oct 29, 2024
f6a36e6
Update test_model_statistics.py
avdudchenko Oct 29, 2024
880a1be
Merge branch 'main' into add_gray_box_do_counting
avdudchenko Oct 29, 2024
75cc0c1
Merge branch 'main' into add_gray_box_do_counting
avdudchenko Oct 31, 2024
03291fa
udpate to diagonotsics
avdudchenko Nov 1, 2024
4b6de4c
Update test_model_diagnostics.py
avdudchenko Nov 1, 2024
d9ff557
Update model_diagnostics.py
avdudchenko Nov 1, 2024
2cd193a
Merge branch 'main' into add_gray_box_do_counting
avdudchenko Nov 21, 2024
c3498fc
addressign comments #1
avdudchenko Nov 22, 2024
5ce566e
added errors for greybox
avdudchenko Nov 22, 2024
fe052f3
Merge branch 'main' into add_gray_box_do_counting
avdudchenko Nov 22, 2024
695b9cf
add exception tests
avdudchenko Nov 22, 2024
2e01052
Merge branch 'add_gray_box_do_counting' of https://github.com/avdudch…
avdudchenko Nov 22, 2024
1bf6ff2
Update model_statistics.py
avdudchenko Nov 22, 2024
b7bf7e0
Merge branch 'main' into add_gray_box_do_counting
avdudchenko Dec 5, 2024
e972091
Update idaes/core/util/model_statistics.py
avdudchenko Dec 12, 2024
d3d2082
Merge branch 'main' into add_gray_box_do_counting
ksbeattie Dec 19, 2024
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