-
Notifications
You must be signed in to change notification settings - Fork 265
DiagnosticsToolbox #1228
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
Merged
Merged
DiagnosticsToolbox #1228
Changes from 52 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
79d702f
Initial outline of diagnostics toolbox
07067d3
Adding iniital display methods
28a7f7f
Removing caching
46a5d9c
Refining code and formatting of reports
fbb5178
Adding first numerical checks
f08fc2b
Adding basic doc string for class
1becf41
More doc strings
474ff3c
Import DiagnosticsToolbox in __init__
608763c
Fixing issues identified in tutorial
ca8ebd0
Cleaning up for initial PR
022ef65
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
aa57b94
Fixing typos
192bd74
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
c8a3e52
Merging main
24ca54c
Addressing comments and clean up
94b304e
DM independent blocks
499f4cc
Unit tests of private functions
5b37144
Adding lots of tests
3ebf494
Tests for collect structural warnings
faa3e26
More tests for collection methods
778f414
Tests for reprot methods
5d34255
Trying to fix Sphinx issues
f6b4cba
Still fighting Sphinx
0ab0c44
REsolving Sphinx and pylint issues
e9fab7a
Fixing external var test
f92ed17
testing for stats writer
7c5ed54
Fixing some tests
296a5e0
Adding Jacobian checks
120d592
Working on scaling tools
2c23b28
Fixing more deprecation warnings from expr.current
25edadd
Adding separate abs and rel tolerances to vars near bounds
c85e917
Fixing incorrect logic
cd986f1
Testing with tutorial
ddfdf5c
Better Jacobian analysis
126ef56
Some clean up before doing docs
aab2acc
Adding initial docs for diagnostics toolbox
8faa222
Fixing typo in docs
749f6fe
Fixing typo and condition number formatting
8a63559
Fixing typos in tests
8fe7b70
Fixing ordering of terms
1cfb383
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
4cb0e26
Addressing some comments
312f88a
Addressing second round of comments
4b02908
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
bee8dc6
Sorting extreme Jacobian entries
1593dd4
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
316d7b0
Fixing import order for Pylint
e626a9f
Removing set_model method
01f0b87
Fixing typos in docs
7a33626
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
3786990
Fixing doc string formatting
70c0d6e
Merge branch 'main' into diagnostics_1
696e0f2
Adding extra doc link to toolbox API
96cef98
Merge branch 'diagnostics_1' of https://github.com/andrewlee94/idaes-…
73c875a
Fixing version in deprecation warning
86bf0cb
Addressing more comments
deeb154
Fixing typo
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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Model Diagnostics Workflow | ||
========================== | ||
|
||
.. contents:: | ||
:depth: 3 | ||
:local: | ||
|
||
Introduction | ||
------------ | ||
|
||
Writing well-posed equation-oriented models is a significant challenge, and even the most experienced developers often have to spend a lot of time diagnosing and resolving issues before a model is able to solve reliably. This documentation is intended to assist users with this process by outlining a general workflow for model development and debugging in order to more easily identify and resolve modeling issues. | ||
|
||
General Workflow | ||
---------------- | ||
|
||
The diagram below shows a high-level overview of the model development and diagnosis workflow recommended by the IDAES team. Boxes in blue represent model development tasks whilst green boxes indicate diagnosis and debugging steps. It is important to note that the workflow is inherently iterative; any change to the model you should start again from the beginning of the workflow to ensure that the changes you made did not introduce any unexpected new issues. | ||
|
||
.. image:: diagnostics_workflow.png | ||
|
||
Choose a Model to Debug | ||
""""""""""""""""""""""" | ||
|
||
As shown above, all model development begins with a model and the IDAES team recommends starting with the simplest possible model you can. It is always easier to debug small changes, so users should apply this workflow from the very beginning of model development starting with the simplest possible representation of their system (e.g., a single unit model or set of material balances). At each step of the process (i.e., each change or new constraint), you should check to ensure that your model is well-posed and that it solves robustly before making additional changes. In this way, it will be clear where to start looking for new issues as they arise, as they will be related in some way to the change you just made. | ||
|
||
Start with a Square Model | ||
""""""""""""""""""""""""" | ||
|
||
Next, you should ensure your model has zero degrees of freedom (as best you can); whilst your ultimate goal may be to solve some optimization problem with degrees of freedom, you should always start from a square model first. Firstly, this is because many of the model diagnosis tools work best with square models. Secondly, all models are based on the foundation of a square model; an optimization problem is just a square model with some degrees of freedom added. If your underlying square model is not well-posed then any more advanced problem you solve based on it is fundamentally flawed (even if it solves). | ||
|
||
Check for Structural Issues | ||
""""""""""""""""""""""""""" | ||
|
||
Once you have a square model, the next step is to check to see if there are any issues with the structure of the model; for example structural singularities or unit consistency issues. As these issues exist in the very structure of the model, it is possible to check for these before calling a solver and in doing so make it more likely that you will be able to successfully solve the model. Any issues identified at this stage should be resolved before trying to move forwards. | ||
|
||
Try to Solve Model | ||
"""""""""""""""""" | ||
|
||
Once you have ensured there are no structural issues with your model, the next step is to try to solve your model (or initialize it if you haven't already) using the solver of your choice (you should also experiment with different solvers if needed). Hopefully you will get some solution back from the solver, even if it is not optimal and/or feasible (in cases where you get critical solver failures, see the section later in this documentation). | ||
|
||
Check for Numerical Issues | ||
"""""""""""""""""""""""""" | ||
|
||
Once you have at least a partial solution to your model, the next step is to check for numerical issues in your model, such as possible bounds violations and poor scaling. Due to their nature, numerical issues depend on having a solution to the model, and they can often be limited to certain model states (i.e., it is possible to have a model which behaves well at one model state only to fail badly if you change your model state). As such, numerical checks should be performed at a number of points across the full range of expected states to try to ensure that the model is well-posed across the full modeling range. Any issues that are identified here should be addressed before moving on, and remember that after any changes you should always start by checking for structural issues again. | ||
|
||
Apply Advanced Diagnostics Tools (if required) | ||
"""""""""""""""""""""""""""""""""""""""""""""" | ||
|
||
If you are still having trouble solving your model after running the structural and numerical checks, then you will need to look to more advanced (and computationally expensive) tools to try and resolve your issues. Finally, once you are satisfied that your model is robust and well behaved, you can move on to solving more complex problems. | ||
|
||
Diagnostics Toolbox | ||
------------------- | ||
|
||
Whilst the workflow outlined above gives a high-level overview of the model development and diagnostics process, there is a lot of detail buried in each of the steps. Rather than provide the user with a long series of steps and check-boxes to complete, the :ref:`IDAES Diagnostics Toolbox<reference_guides/core/util/diagnostics/diagnostics_toolbox:Diagnostics Toolbox>` instead provides a centralized interface for accessing diagnostics tools and guiding users through the diagnostics workflow. High level methods are provided for each of the model diagnosis steps (green boxes) in the workflow above which will provide a summary of any issues identified, and these will recommend additional methods and tools to use to further examine each issue identified. | ||
|
||
Modeling Log Book | ||
----------------- | ||
|
||
Model development and diagnostics is inherently an iterative process, and often you will try one approach to resolve an issue only to find it made things worse or that you can no longer reproduce an import result from a previous model. Due to this, users are strongly encouraged to maintain a "modeling log book" which records their model development activities. This log book should record each change made to the model and why, along with a Git hash (or equivalent version control marker) and a record on any important results that were generated with the current version of the model. This log book will prove to be invaluable when (and not if) you need to revert to an older version of the model to undo some unsuccessful changes or to work out why a previous result can no longer be reproduced. | ||
andrewlee94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Handling Critical Solver Failures | ||
--------------------------------- | ||
|
||
TBA |
This file contains hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
docs/reference_guides/core/util/diagnostics/degeneracy_hunter.rst
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Degeneracy Hunter | ||
================= | ||
|
||
.. note:: | ||
|
||
v2.2: The Degeneracy Hunter tool is being deprecated in favor of the newer Diagnostics Toolbox. | ||
|
||
Over the next few releases the functionality of Degeneracy Hunter will be moved over to the new Diagnostics Toolbox which will also contain a number of other tools for diagnosing model issues. | ||
|
||
.. autoclass:: idaes.core.util.model_diagnostics.DegeneracyHunter | ||
:members: | ||
|
7 changes: 7 additions & 0 deletions
7
docs/reference_guides/core/util/diagnostics/diagnostics_toolbox.rst
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Diagnostics Toolbox | ||
=================== | ||
|
||
The IDAES Diagnostics Toolbox is intended to provide a comprehensive collection of tools for identifying potential modeling issues, and guiding the user through the model diagnosis workflow. For more in-depth discussion of the model diagnosis workflow see the :ref:`Model Diagnostics Workflow<explanations/model_diagnostics/index:Model Diagnostics Workflow>` documentation. | ||
|
||
.. autoclass:: idaes.core.util.model_diagnostics.DiagnosticsToolbox | ||
:members: |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.