From ac3d587ee2d3d964fd5c54f993ce5749e2392683 Mon Sep 17 00:00:00 2001 From: "David L. Woodruff" Date: Sun, 21 Apr 2024 15:36:34 -0700 Subject: [PATCH] take care of Miranda's helpful comments --- doc/OnlineDocs/contributed_packages/iis.rst | 5 +++-- pyomo/contrib/iis/mis.py | 12 +++++++----- pyomo/contrib/iis/tests/test_mis.py | 9 ++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/doc/OnlineDocs/contributed_packages/iis.rst b/doc/OnlineDocs/contributed_packages/iis.rst index c6e588720b4..fa97c2f8c61 100644 --- a/doc/OnlineDocs/contributed_packages/iis.rst +++ b/doc/OnlineDocs/contributed_packages/iis.rst @@ -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 @@ -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 -------------- diff --git a/pyomo/contrib/iis/mis.py b/pyomo/contrib/iis/mis.py index bc0bccdd5cf..7044d483f65 100644 --- a/pyomo/contrib/iis/mis.py +++ b/pyomo/contrib/iis/mis.py @@ -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: @@ -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 @@ -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: @@ -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: diff --git a/pyomo/contrib/iis/tests/test_mis.py b/pyomo/contrib/iis/tests/test_mis.py index 266673f2ec9..bbdb2367016 100644 --- a/pyomo/contrib/iis/tests/test_mis.py +++ b/pyomo/contrib/iis/tests/test_mis.py @@ -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 @@ -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 @@ -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)