Skip to content

Commit

Permalink
simplifying the code
Browse files Browse the repository at this point in the history
  • Loading branch information
bknueven committed Apr 11, 2024
1 parent 82fcddc commit 071d0f5
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions pyomo/contrib/iis/mis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@

from pyomo.opt import WriterFactory

try:
from idaes.core.solvers import get_solver

have_idaes = True
except:
have_idaes = False

logger = logging.getLogger("pyomo.contrib.iis")
logger.setLevel(logging.INFO)

_default_nl_writer = WriterFactory.get_class("nl")


class _VariableBoundsAsConstraints(IsomorphicTransformation):
"""Replace all variables bounds and domain information with constraints.
Expand Down Expand Up @@ -69,7 +60,7 @@ def _apply_to(self, instance, **kwds):


def compute_infeasibility_explanation(
model, solver=None, tee=False, tolerance=1e-8, logger=logger
model, solver, tee=False, tolerance=1e-8, logger=logger
):
"""
This function attempts to determine why a given model is infeasible. It deploys
Expand All @@ -87,7 +78,7 @@ def compute_infeasibility_explanation(
Args
----
model: A pyomo block
solver (optional): A pyomo solver, a string, or None
solver: A pyomo solver object or a string for SolverFactory
tee (optional): Display intermediate solves conducted (False)
tolerance (optional): The feasibility tolerance to use when declaring a
constraint feasible (1e-08)
Expand All @@ -99,12 +90,7 @@ def compute_infeasibility_explanation(
# hold the original harmless
modified_model = model.clone()

if solver is None:
if have_idaes:
solver = get_solver()
else:
raise ValueError("solver needed unless IDAES is installed")
elif isinstance(solver, str):
if isinstance(solver, str):
solver = pyo.SolverFactory(solver)
else:
# assume we have a solver
Expand Down Expand Up @@ -252,10 +238,6 @@ def _constraint_generator():
)

# Phase 2 -- deletion filter
# TODO: the model created here seems to mess with the nl_v2
# writer sometimes. So we temporarily switch to nl_v1 writer.
WriterFactory.register("nl")(WriterFactory.get_class("nl_v1"))

# remove slacks by fixing them to 0
for v in slack_block.component_data_objects(pyo.Var):
v.fix(0)
Expand Down Expand Up @@ -305,8 +287,6 @@ def _constraint_generator():
msg += "Constraints / bounds in guards for stability:"
msg = _get_results(guards, msg)

WriterFactory.register("nl")(_default_nl_writer)

logger.info(msg)


Expand Down

0 comments on commit 071d0f5

Please sign in to comment.