Issue
When constructing a system in another package that doesn't have a concept of state (such as mes), echo must allow the setting of attributes with state after the OptimisationGraph has been built. As pydantic (currently v1) is used to force typing on echo objects, the setting of attributes with state on already instantiate objects causes pydantic to create a copy of that object. Issues arising from this usually manifest in a mismatch between ports on nodes (which are now copies), and ports on edges (which are the original). This causes the graph to be incomplete and all sorts of errors arise from it.
As a side note, since the copied node had the identical name, uid and all other attributes, the only way I could find to differentiate between the original and copy was to use id().
Previously we've tackled this issue by finding affected edges, deleting them and rebuilding them after data with state has been set for each node using echo.models.base.OptimisationGraph.update_node(). This function requires each node to have an update() function.
In the process of updating the EV nodes, I tried a different approach where each node had a set_stateful_attrs_at_init: bool = True option. If True, stateful data would set at instantiate of that node. If False, stateful data would be delayed until set_stateful_attrs() is called. However this too required rebuilding of all edges for the same reason as before.
This issue is linked to:
Solution
A good starting point would be to understand how the pydantic v1 -> v2 upgrade would impact this problem. We could also explore issue #67 further to understand if we can avoid this problem through "proper" usage of pydantic.
Issue
When constructing a system in another package that doesn't have a concept of state (such as mes), echo must allow the setting of attributes with state after the
OptimisationGraphhas been built. As pydantic (currently v1) is used to force typing on echo objects, the setting of attributes with state on already instantiate objects causes pydantic to create a copy of that object. Issues arising from this usually manifest in a mismatch between ports on nodes (which are now copies), and ports on edges (which are the original). This causes the graph to be incomplete and all sorts of errors arise from it.As a side note, since the copied node had the identical name, uid and all other attributes, the only way I could find to differentiate between the original and copy was to use
id().Previously we've tackled this issue by finding affected edges, deleting them and rebuilding them after data with state has been set for each node using
echo.models.base.OptimisationGraph.update_node(). This function requires each node to have anupdate()function.In the process of updating the EV nodes, I tried a different approach where each node had a
set_stateful_attrs_at_init: bool = Trueoption. IfTrue, stateful data would set at instantiate of that node. IfFalse, stateful data would be delayed untilset_stateful_attrs()is called. However this too required rebuilding of all edges for the same reason as before.This issue is linked to:
Solution
A good starting point would be to understand how the pydantic v1 -> v2 upgrade would impact this problem. We could also explore issue #67 further to understand if we can avoid this problem through "proper" usage of pydantic.