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

DiagnosticsToolbox #1228

Merged
merged 57 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
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
Jul 11, 2023
07067d3
Adding iniital display methods
Jul 11, 2023
28a7f7f
Removing caching
Jul 11, 2023
46a5d9c
Refining code and formatting of reports
Jul 14, 2023
fbb5178
Adding first numerical checks
Jul 14, 2023
f08fc2b
Adding basic doc string for class
Jul 14, 2023
1becf41
More doc strings
Jul 14, 2023
474ff3c
Import DiagnosticsToolbox in __init__
Jul 17, 2023
608763c
Fixing issues identified in tutorial
Jul 18, 2023
ca8ebd0
Cleaning up for initial PR
Jul 25, 2023
022ef65
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Jul 25, 2023
aa57b94
Fixing typos
Jul 26, 2023
192bd74
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Jul 28, 2023
c8a3e52
Merging main
Aug 8, 2023
24ca54c
Addressing comments and clean up
Aug 9, 2023
94b304e
DM independent blocks
Aug 9, 2023
499f4cc
Unit tests of private functions
Aug 9, 2023
5b37144
Adding lots of tests
Aug 10, 2023
3ebf494
Tests for collect structural warnings
Aug 10, 2023
faa3e26
More tests for collection methods
Aug 10, 2023
778f414
Tests for reprot methods
Aug 10, 2023
5d34255
Trying to fix Sphinx issues
Aug 10, 2023
f6b4cba
Still fighting Sphinx
Aug 10, 2023
0ab0c44
REsolving Sphinx and pylint issues
Aug 10, 2023
e9fab7a
Fixing external var test
Aug 10, 2023
f92ed17
testing for stats writer
Aug 10, 2023
7c5ed54
Fixing some tests
Aug 10, 2023
296a5e0
Adding Jacobian checks
Aug 11, 2023
120d592
Working on scaling tools
Aug 11, 2023
2c23b28
Fixing more deprecation warnings from expr.current
Aug 11, 2023
25edadd
Adding separate abs and rel tolerances to vars near bounds
Aug 11, 2023
c85e917
Fixing incorrect logic
Aug 11, 2023
cd986f1
Testing with tutorial
Aug 11, 2023
ddfdf5c
Better Jacobian analysis
Aug 14, 2023
126ef56
Some clean up before doing docs
Aug 14, 2023
aab2acc
Adding initial docs for diagnostics toolbox
Aug 14, 2023
8faa222
Fixing typo in docs
Aug 14, 2023
749f6fe
Fixing typo and condition number formatting
Aug 17, 2023
8a63559
Fixing typos in tests
Aug 18, 2023
8fe7b70
Fixing ordering of terms
Aug 18, 2023
1cfb383
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Aug 22, 2023
4cb0e26
Addressing some comments
Aug 22, 2023
312f88a
Addressing second round of comments
Aug 22, 2023
4b02908
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Aug 22, 2023
bee8dc6
Sorting extreme Jacobian entries
Aug 24, 2023
1593dd4
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Aug 24, 2023
316d7b0
Fixing import order for Pylint
Aug 24, 2023
e626a9f
Removing set_model method
Aug 24, 2023
01f0b87
Fixing typos in docs
Aug 24, 2023
7a33626
Merge branch 'main' of https://github.com/IDAES/idaes-pse into diagno…
Aug 24, 2023
3786990
Fixing doc string formatting
Aug 25, 2023
70c0d6e
Merge branch 'main' into diagnostics_1
Aug 25, 2023
696e0f2
Adding extra doc link to toolbox API
Aug 25, 2023
96cef98
Merge branch 'diagnostics_1' of https://github.com/andrewlee94/idaes-…
Aug 25, 2023
73c875a
Fixing version in deprecation warning
Aug 25, 2023
86bf0cb
Addressing more comments
Aug 28, 2023
deeb154
Fixing typo
Aug 28, 2023
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
1 change: 1 addition & 0 deletions docs/explanations/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Explanations
concepts
components/index
conventions
model_diagnostics/index
modeling_extensions/index
related_packages/index
faq
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/explanations/model_diagnostics/index.rst
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.
andrewlee94 marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
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.

Degeneracy Hunter is a collection of tools for diagnostics of mathematical programs.

* `Core ideas (conference paper) <https://www.sciencedirect.com/science/article/pii/B9780444635785501304>`_
* `Example notebook <https://idaes.github.io/examples-pse/latest/Examples/Tools/degeneracy_hunter_doc.html>`_
* :ref:`Full documentation<reference_guides/core/util/model_diagnostics:Degeneracy Hunter>`
* :ref:`Full documentation<reference_guides/core/util/diagnostics/degeneracy_hunter:Degeneracy Hunter>`
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ See also :doc:`IDAES concepts <explanations/concepts>` in this documentation.
| :doc:`Concepts <explanations/concepts>`
| :doc:`Components of IDAES <explanations/components/index>`
| :doc:`Conventions <explanations/conventions>`
| :doc:`Model Diagnostics Workflow <explanations/model_diagnostics/index>`
| :doc:`Modeling Extensions <explanations/modeling_extensions/index>`
| :doc:`Related Packages <explanations/related_packages/index>`
| :doc:`FAQ <explanations/faq>`
Expand Down
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:

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:
20 changes: 8 additions & 12 deletions docs/reference_guides/core/util/model_diagnostics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ Model Diagnostic Functions

The IDAES toolset contains a number of utility functions which can be useful for identifying modeling issues and debugging solver issues.

.. contents:: Contents
:depth: 2
.. toctree::
:maxdepth: 1

diagnostics/diagnostics_toolbox
diagnostics/degeneracy_hunter

Degeneracy Hunter
^^^^^^^^^^^^^^^^^

.. autoclass:: idaes.core.util.model_diagnostics.DegeneracyHunter
:members:


Available Methods
^^^^^^^^^^^^^^^^^
Other Methods
^^^^^^^^^^^^^

.. automodule:: idaes.core.util.model_diagnostics
:exclude-members: DegeneracyHunter
:exclude-members: DegeneracyHunter, DiagnosticsToolbox
:members:

1 change: 1 addition & 0 deletions idaes/core/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

from .model_serializer import to_json, from_json, StoreSpec
from .tags import svg_tag, ModelTag, ModelTagGroup
from .model_diagnostics import DiagnosticsToolbox
Loading
Loading