Skip to content

Commit

Permalink
take care of Miranda's helpful comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DLWoodruff committed Apr 21, 2024
1 parent 73f4a2f commit ac3d587
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions doc/OnlineDocs/contributed_packages/iis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ 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 and is governed by a license shown
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
Expand Down Expand Up @@ -115,7 +116,7 @@ Hence for difficult NLPs even the “Phase 1” may “fail” – in that when
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 it’s assumptions are not satisfied.
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
--------------
Expand Down
12 changes: 7 additions & 5 deletions pyomo/contrib/iis/mis.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class _VariableBoundsAsConstraints(IsomorphicTransformation):

def _apply_to(self, instance, **kwds):

boundconstrblockname = unique_component_name(instance, "_variable_bounds")
instance.add_component(boundconstrblockname, pyo.Block())
boundconstrblock = instance.component(boundconstrblockname)
bound_constr_block_name = unique_component_name(instance, "_variable_bounds")
instance.add_component(bound_constr_block_name, pyo.Block())
bound_constr_block = instance.component(bound_constr_block_name)

for v in instance.component_data_objects(pyo.Var, descend_into=True):
if v.fixed:
Expand All @@ -72,11 +72,11 @@ def _apply_to(self, instance, **kwds):
if lb is not None:
con_name = "lb_for_" + var_name
con = pyo.Constraint(expr=(lb, v, None))
boundconstrblock.add_component(con_name, con)
bound_constr_block.add_component(con_name, con)
if ub is not None:
con_name = "ub_for_" + var_name
con = pyo.Constraint(expr=(None, v, ub))
boundconstrblock.add_component(con_name, con)
bound_constr_block.add_component(con_name, con)

# now we deactivate the variable bounds / domain
v.domain = pyo.Reals
Expand Down Expand Up @@ -317,6 +317,7 @@ def _constraint_generator():


def _get_results_with_value(constr_value_generator, msg=None):
# note that "lb_for_" and "ub_for_" are 7 characters long
if msg is None:
msg = ""
for c, value in constr_value_generator:
Expand All @@ -335,6 +336,7 @@ def _get_results_with_value(constr_value_generator, msg=None):


def _get_results(constr_generator, msg=None):
# note that "lb_for_" and "ub_for_" are 7 characters long
if msg is None:
msg = ""
for c in constr_generator:
Expand Down
9 changes: 4 additions & 5 deletions pyomo/contrib/iis/tests/test_mis.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_write_mis_ipopt(self):
_test_mis("ipopt")

def test__get_constraint_errors(self):
# A not-completely-cyincal way to get the coverage up.
# A not-completely-cynical way to get the coverage up.
m = _get_infeasible_model() # not modified
fct = _get_constraint

Expand All @@ -76,14 +76,14 @@ def _check_output(file_name):
trigger = "Constraints / bounds in MIS:"
nugget = "lb of var y"
live = False # (long i)
wewin = False
found_nugget = False
for line in lines:
if trigger in line:
live = True
if live:
if nugget in line:
wewin = True
if not wewin:
found_nugget = True
if not found_nugget:
raise RuntimeError(f"Did not find '{nugget}' after '{trigger}' in output")
else:
pass
Expand All @@ -96,7 +96,6 @@ def _test_mis(solver_name):
# This test seems to fail on Windows as it unlinks the tempfile, so live with it
# On a Windows machine, we will not use a temp dir and just try to delete the log file
if os.name == "nt":
print("we have nt")
file_name = f"_test_mis_{solver_name}.log"
logger = logging.getLogger(f"test_mis_{solver_name}")
logger.setLevel(logging.INFO)
Expand Down

0 comments on commit ac3d587

Please sign in to comment.