Description
Summary
Related to IDAES/idaes-pse#741
In some more complex IDAES models, we have cases where we want Blocks
to register themselves with other Blocks
, e.g. for automating aggregation of quantities across a number of sub-models. However, this means that when one of these Blocks
is deleted, we also need to clean up these references.
Currently, we are overloading del_component
to check for these types of Blocks
and call some custom code to clean up the references. It would be helpful if Pyomo could build an in-built call back for this custom clean up code.
Rationale
Within IDAES, we are implementing a framework for costing of capital equipment in a process. The model contains a number of Blocks
representing unit operations, each of which need to have capital costing calculations associated with them, which we are doing by sub-Blocks
attached to the unit operation Block
. We then need to aggregate all the unit operation costs into a single, process wide cost - to save having to iterate over all the Blocks
in the model and look for specific components associated with costing, we are registering all the Blocks
associated with the capital costing at the top level of the model so that we know which Blocks
to aggregate from.
In case we need to delete one of these costing Blocks
, we also need to be able to clean up these references which requires the ability to call custom code as part of del_component
.
Description
At the moment we are overloading del_component
with some checks to call the custom code if required, but I think it would be helpful (and more robust) if Pyomo could provide a hook for a callback as part of del_component
that could be used to execute the clean-up code.