From 45691f712889c06a45b8cefaa27801c32492ad3c Mon Sep 17 00:00:00 2001 From: Emma Johnson Date: Mon, 2 Dec 2024 13:35:10 -0700 Subject: [PATCH 1/3] modifying the FME post-processing objective without creating and deleting it every iteration --- pyomo/contrib/fme/fourier_motzkin_elimination.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pyomo/contrib/fme/fourier_motzkin_elimination.py b/pyomo/contrib/fme/fourier_motzkin_elimination.py index 021650e8f9a..ad3a6b5aeb2 100644 --- a/pyomo/contrib/fme/fourier_motzkin_elimination.py +++ b/pyomo/contrib/fme/fourier_motzkin_elimination.py @@ -730,12 +730,9 @@ def post_process_fme_constraints( continue # deactivate the constraint projected_constraints[i].deactivate() - m.del_component(obj) - # make objective to maximize its infeasibility - obj = Objective( - expr=projected_constraints[i].body - projected_constraints[i].lower - ) - m.add_component(obj_name, obj) + # Our constraint looks like: 0 <= a^Tx - b, so make objective to + # maximize its infeasibility + obj.expr = projected_constraints[i].body - projected_constraints[i].lower results = solver_factory.solve(m) if results.solver.termination_condition == TerminationCondition.unbounded: obj_val = -float('inf') @@ -753,13 +750,13 @@ def post_process_fme_constraints( obj_val = value(obj) # if we couldn't make it infeasible, it's useless if obj_val >= tolerance: - m.del_component(projected_constraints[i]) del projected_constraints[i] else: projected_constraints[i].activate() # clean up m.del_component(obj) + del obj for obj in active_objs: obj.activate() # undo relax integrality From f382c1e29f240f560250b9aa82bab3747e3a6098 Mon Sep 17 00:00:00 2001 From: Emma Johnson Date: Mon, 2 Dec 2024 13:43:00 -0700 Subject: [PATCH 2/3] Removing outdated docs from the ComponentData docstring --- pyomo/core/base/component.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyomo/core/base/component.py b/pyomo/core/base/component.py index a5763264b14..5aa260cd9b2 100644 --- a/pyomo/core/base/component.py +++ b/pyomo/core/base/component.py @@ -732,11 +732,7 @@ class ComponentData(ComponentBase): This is the base class for the component data used in Pyomo modeling components. Subclasses of ComponentData are used in indexed components, and this class assumes that indexed - components are subclasses of IndexedComponent. Note that - ComponentData instances do not store their index. This makes - some operations significantly more expensive, but these are (a) - associated with I/O generation and (b) this cost can be managed - with caches. + components are subclasses of IndexedComponent. Constructor arguments: owner The component that owns this data object From 4dcfc6590bcaab1593c0aacb536648ab098fdb88 Mon Sep 17 00:00:00 2001 From: Emma Johnson Date: Mon, 2 Dec 2024 14:57:08 -0700 Subject: [PATCH 3/3] Raising a ValueError when a ComponentData is passed to del_component --- pyomo/core/base/block.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyomo/core/base/block.py b/pyomo/core/base/block.py index 656bf6008c4..de94dbe8ae8 100644 --- a/pyomo/core/base/block.py +++ b/pyomo/core/base/block.py @@ -34,6 +34,7 @@ from pyomo.common.timing import ConstructionTimer from pyomo.core.base.component import ( Component, + ComponentData, ActiveComponentData, ModelComponentFactory, ) @@ -1139,6 +1140,14 @@ def del_component(self, name_or_object): # return name = obj.local_name + if isinstance(obj, ComponentData) and not isinstance(obj, Component): + raise ValueError( + "Argument '%s' to del_component is a ComponentData object. Please " + "use the Python 'del' function to delete members of indexed " + "Pyomo objects. The del_component function can only be used to " + "delete IndexedComponents and ScalarComponents." % name + ) + if name in self._Block_reserved_words: raise ValueError( "Attempting to delete a reserved block component:\n\t%s" % (obj.name,)