-
Notifications
You must be signed in to change notification settings - Fork 525
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
Disallow calling del_component
with ComponentData arguments
#3440
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty sure that the change to del_component
won't actually catch attempts to delete a component data.
del projected_constraints[i] | ||
else: | ||
projected_constraints[i].activate() | ||
|
||
# clean up | ||
m.del_component(obj) | ||
del obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary (it implicitly happens when you reassign obj
in the for loop in the next line)
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 | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't do what you think it does: line 1133 (obj = self.component(name_or_object)
) maps the incoming object into its component, so you shouldn't be able to trigger this exception. If we are going to change the behavior of del_component
to only admit Components (either by name or reference), we should
- change (possibly inline the logic from) line 1133
- document this in the docstring
- possibly add a deprecation path (because we are changing behavior that has been in Pyomo for over a decade)??
Fixes #3435
Summary/Motivation:
I think silently deleting the containing component when we call
del_component
on a ComponentData is rude, and the post-processing in Fourier-Motzkin elimination was falling victim to this mistake. This PR adds aValueError
todel_component
if it is given a ComponentData and revises the FME transformation post-processing routine.Changes proposed in this PR:
del_component
if the arguments is a ComponentDatadel_component
and, in fact, to not add and delete as many components in general.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: