mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-08-27 18:06:17 +00:00
Simplify Pipeline.__eq__ logic (#6840)
This commit is contained in:
parent
acf4cd502f
commit
b1ec32dae0
@ -62,20 +62,9 @@ class Pipeline:
|
|||||||
Equal pipelines share every metadata, node and edge, but they're not required to use
|
Equal pipelines share every metadata, node and edge, but they're not required to use
|
||||||
the same node instances: this allows pipeline saved and then loaded back to be equal to themselves.
|
the same node instances: this allows pipeline saved and then loaded back to be equal to themselves.
|
||||||
"""
|
"""
|
||||||
if (
|
if not isinstance(other, Pipeline):
|
||||||
not isinstance(other, type(self))
|
|
||||||
or not getattr(self, "metadata") == getattr(other, "metadata")
|
|
||||||
or not getattr(self, "max_loops_allowed") == getattr(other, "max_loops_allowed")
|
|
||||||
or not hasattr(self, "graph")
|
|
||||||
or not hasattr(other, "graph")
|
|
||||||
):
|
|
||||||
return False
|
return False
|
||||||
|
return self.to_dict() == other.to_dict()
|
||||||
return (
|
|
||||||
self.graph.adj == other.graph.adj
|
|
||||||
and self._comparable_nodes_list(self.graph) == self._comparable_nodes_list(other.graph)
|
|
||||||
and self.graph.graph == other.graph.graph
|
|
||||||
)
|
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
@ -172,18 +161,6 @@ class Pipeline:
|
|||||||
|
|
||||||
return pipe
|
return pipe
|
||||||
|
|
||||||
def _comparable_nodes_list(self, graph: networkx.MultiDiGraph) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
Replaces instances of nodes with their class name in order to make sure they're comparable.
|
|
||||||
"""
|
|
||||||
nodes = []
|
|
||||||
for node in graph.nodes:
|
|
||||||
comparable_node = graph.nodes[node]
|
|
||||||
comparable_node["instance"] = comparable_node["instance"].__class__
|
|
||||||
nodes.append(comparable_node)
|
|
||||||
nodes.sort()
|
|
||||||
return nodes
|
|
||||||
|
|
||||||
def add_component(self, name: str, instance: Component) -> None:
|
def add_component(self, name: str, instance: Component) -> None:
|
||||||
"""
|
"""
|
||||||
Create a component for the given component. Components are not connected to anything by default:
|
Create a component for the given component. Components are not connected to anything by default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user