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

Code for infeasibility diagnostics called mis #3172

Merged
merged 44 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5630263
getting started moving mis code into Pyomo contrib
DLWoodruff Mar 1, 2024
bceaff1
we have a test for mis, but it needs more coverage
DLWoodruff Mar 1, 2024
fc9167b
now testing some exceptions
DLWoodruff Mar 1, 2024
3030fdc
slight change to doc
DLWoodruff Mar 1, 2024
9a32b21
black
DLWoodruff Mar 1, 2024
a24432b
Merge branch 'main' into mis
DLWoodruff Mar 1, 2024
20e4196
fixing _get_constraint test
bknueven Mar 1, 2024
099eb8b
Merge pull request #1 from bknueven/mis_bk
DLWoodruff Mar 1, 2024
f9f7a0d
removing some spelling errors
DLWoodruff Mar 1, 2024
1ba2437
more spelling errors removed
DLWoodruff Mar 1, 2024
9dc6fc8
update typos.toml for mis
DLWoodruff Mar 1, 2024
b3cbc0e
I forgot to push the __init__.py file in tests
DLWoodruff Mar 1, 2024
c6376aa
a little documentation cleanup
DLWoodruff Mar 1, 2024
4eac988
Merge branch 'main' into mis
mrmundt Mar 5, 2024
746a6fb
Merge branch 'main' into mis
DLWoodruff Mar 17, 2024
90bfcf3
moved mis to be part of iis
DLWoodruff Mar 17, 2024
5211a9b
correct bad import in mis test
DLWoodruff Mar 17, 2024
2674690
I didn't realize it would run every py file in the test directory
DLWoodruff Mar 18, 2024
09ad1ad
trying to get the Windows tests to pass by explicitly releasing the l…
DLWoodruff Mar 18, 2024
485cddc
run black on test_mis.py
DLWoodruff Mar 18, 2024
9f624d6
trying to manage the temp dir using the tempfilemanager as a context
DLWoodruff Mar 29, 2024
2b7bfe7
catch the error that kills windows tests
DLWoodruff Mar 30, 2024
7c04022
run black again
DLWoodruff Mar 30, 2024
1629bd7
windows started passing, but linux failing; one quick check to see if…
DLWoodruff Mar 30, 2024
daeed6e
run black again
DLWoodruff Mar 30, 2024
ce6bac4
On windows we are just going to have to leave a log file from the test
DLWoodruff Mar 30, 2024
fe6cc1d
Merge branch 'main' into mis
DLWoodruff Mar 30, 2024
d3d9d6f
Merge branch 'main' into mis
DLWoodruff Apr 3, 2024
82fcddc
Merge branch 'main' into mis
mrmundt Apr 9, 2024
86daaa1
merge main
DLWoodruff Apr 17, 2024
f35bce5
add a test for a feasible model
DLWoodruff Apr 17, 2024
1c14f10
Merge branch 'mis' of https://github.com/DLWoodruff/pyomo into mis
DLWoodruff Apr 17, 2024
57f52a0
Update pyomo/contrib/iis/mis.py
DLWoodruff Apr 17, 2024
ed526db
Changes suggested by Miranda
DLWoodruff Apr 17, 2024
1739d99
run black again
DLWoodruff Apr 17, 2024
a4a9496
simplifying the code
bknueven Apr 11, 2024
73f4a2f
Merge pull request #2 from bknueven/mis_bk
DLWoodruff Apr 17, 2024
ac3d587
take care of Miranda's helpful comments
DLWoodruff Apr 21, 2024
2b75576
Merge branch 'main' into mis
DLWoodruff Apr 21, 2024
0f26a0a
Merge branch 'main' into mis
mrmundt Apr 23, 2024
1b638e6
Merge branch 'main' into mis
DLWoodruff Apr 26, 2024
f4f4b2c
add sorely needed f to format error messages
DLWoodruff May 1, 2024
21aa8c8
added suggestions from R. Parker to the comments
DLWoodruff May 1, 2024
a16bf7f
Merge branch 'main' into mis
DLWoodruff May 5, 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
3 changes: 3 additions & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ WRONLY = "WRONLY"
Hax = "Hax"
# Big Sur
Sur = "Sur"
# contrib package named mis and the acronym whence the name comes
mis = "mis"
MIS = "MIS"
# Ignore the shorthand ans for answer
ans = "ans"
# Ignore the keyword arange
Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'sphinx.ext.todo',
'sphinx_copybutton',
'enum_tools.autoenum',
'sphinx.ext.autosectionlabel',
#'sphinx.ext.githubpages',
]

Expand Down
129 changes: 129 additions & 0 deletions doc/OnlineDocs/contributed_packages/iis.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,135 @@
Infeasibility Diagnostics
!!!!!!!!!!!!!!!!!!!!!!!!!

There are two closely related tools for infeasibility diagnosis:

- :ref:`Infeasible Irreducible System (IIS) Tool`
- :ref:`Minimal Intractable System finder (MIS) Tool`

The first simply provides a conduit for solvers that compute an
infeasible irreducible system (e.g., Cplex, Gurobi, or Xpress). The
second provides similar functionality, but uses the ``mis`` package
contributed to Pyomo.


Infeasible Irreducible System (IIS) Tool
========================================

.. automodule:: pyomo.contrib.iis.iis

.. autofunction:: pyomo.contrib.iis.write_iis

Minimal Intractable System finder (MIS) Tool
============================================

The file ``mis.py`` finds sets of actions that each, independently,
would result in feasibility. The zero-tolerance is whatever the
solver uses, so users may want to post-process output if it is going
to be used for analysis. It also computes a minimal intractable system
(which is not guaranteed to be unique). It was written by Ben Knueven
as part of the watertap project (https://github.com/watertap-org/watertap)
and is therefore governed by a license shown
at the top of ``mis.py``.

The algorithms come from John Chinneck's slides, see: https://www.sce.carleton.ca/faculty/chinneck/docs/CPAIOR07InfeasibilityTutorial.pdf

Solver
------

At the time of this writing, you need to use IPopt even for LPs.

Quick Start
-----------

The file ``trivial_mis.py`` is a tiny example listed at the bottom of
this help file, which references a Pyomo model with the Python variable
`m` and has these lines:

.. code-block:: python

from pyomo.contrib.mis import compute_infeasibility_explanation
ipopt = pyo.SolverFactory("ipopt")
compute_infeasibility_explanation(m, solver=ipopt)

.. Note::
This is done instead of solving the problem.

.. Note::
IDAES users can pass ``get_solver()`` imported from ``ideas.core.solvers``
as the solver.

Interpreting the Output
-----------------------

Assuming the dependencies are installed, running ``trivial_mis.py``
(shown below) will
produce a lot of warnings from IPopt and then meaningful output (using a logger).

Repair Options
^^^^^^^^^^^^^^

This output for the trivial example shows three independent ways that the model could be rendered feasible:


.. code-block:: text

Model Trivial Quad may be infeasible. A feasible solution was found with only the following variable bounds relaxed:
ub of var x[1] by 4.464126126706818e-05
lb of var x[2] by 0.9999553410114216
Another feasible solution was found with only the following variable bounds relaxed:
lb of var x[1] by 0.7071067726864677
ub of var x[2] by 0.41421355687130673
ub of var y by 0.7071067651855212
Another feasible solution was found with only the following inequality constraints, equality constraints, and/or variable bounds relaxed:
constraint: c by 0.9999999861866736


Minimal Intractable System (MIS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This output shows a minimal intractable system:


.. code-block:: text

Computed Minimal Intractable System (MIS)!
Constraints / bounds in MIS:
lb of var x[2]
lb of var x[1]
constraint: c

Constraints / bounds in guards for stability
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This part of the report is for nonlinear programs (NLPs).

When we’re trying to reduce the constraint set, for an NLP there may be constraints that when missing cause the solver
to fail in some catastrophic fashion. In this implementation this is interpreted as failing to get a `results`
object back from the call to `solve`. In these cases we keep the constraint in the problem but it’s in the
set of “guard” constraints – we can’t really be sure they’re a source of infeasibility or not,
just that “bad things” happen when they’re not included.

Perhaps ideally we would put a constraint in the “guard” set if IPopt failed to converge, and only put it in the
MIS if IPopt converged to a point of local infeasibility. However, right now the code generally makes the
assumption that if IPopt fails to converge the subproblem is infeasible, though obviously that is far from the truth.
Hence for difficult NLPs even the “Phase 1” may “fail” – in that when finished the subproblem containing just the
constraints in the elastic filter may be feasible -- because IPopt failed to converge and we assumed that meant the
subproblem was not feasible.

Dealing with NLPs is far from clean, but that doesn’t mean the tool can’t return useful results even when its assumptions are not satisfied.

trivial_mis.py
--------------

.. code-block:: python

import pyomo.environ as pyo
m = pyo.ConcreteModel("Trivial Quad")
m.x = pyo.Var([1,2], bounds=(0,1))
m.y = pyo.Var(bounds=(0, 1))
m.c = pyo.Constraint(expr=m.x[1] * m.x[2] == -1)
m.d = pyo.Constraint(expr=m.x[1] + m.y >= 1)

from pyomo.contrib.mis import compute_infeasibility_explanation
ipopt = pyo.SolverFactory("ipopt")
compute_infeasibility_explanation(m, solver=ipopt)
1 change: 1 addition & 0 deletions pyomo/contrib/iis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# ___________________________________________________________________________

from pyomo.contrib.iis.iis import write_iis
from pyomo.contrib.iis.mis import compute_infeasibility_explanation
Loading
Loading