From 097df4230169a1cb3c68f445dd47ec2cd1f02bf2 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 28 Aug 2020 07:47:47 -0400 Subject: [PATCH] Remove deepcopies from DAGCircuit.__eq__ The __eq__ method of the dagcircuit class was previously deep copying the retworkx PyDAG objects for both self and other to force a reindexing of the node indices in the graphs to acvoid a bug in retworkx (see Qiskit/retworkx#27 for more details). In the next retworkx a workaround for that bug was introduced which removes the need for doing the deepcopy calls. This commit does that and removes the deep copies which should improve the performance of run __eq__ o dagcircuit objects. --- qiskit/dagcircuit/dagcircuit.py | 8 ++------ requirements.txt | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/qiskit/dagcircuit/dagcircuit.py b/qiskit/dagcircuit/dagcircuit.py index b98b4092205c..81c958dd9a7a 100644 --- a/qiskit/dagcircuit/dagcircuit.py +++ b/qiskit/dagcircuit/dagcircuit.py @@ -773,12 +773,8 @@ def _full_pred_succ_maps(self, pred_map, succ_map, input_circuit, return full_pred_map, full_succ_map def __eq__(self, other): - # TODO remove deepcopy calls after - # https://github.com/mtreinish/retworkx/issues/27 is fixed - slf = copy.deepcopy(self._multi_graph) - oth = copy.deepcopy(other._multi_graph) - - return rx.is_isomorphic_node_match(slf, oth, + return rx.is_isomorphic_node_match(self._multi_graph, + other._multi_graph, DAGNode.semantic_eq) def topological_nodes(self): diff --git a/requirements.txt b/requirements.txt index dcba1b03daf3..ac1d4ff01403 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ contextvars>=2.4;python_version<'3.7' jsonschema>=2.6 networkx>=2.2;python_version>'3.5' networkx>=2.2,<2.4;python_version=='3.5' -retworkx>=0.4.0 +retworkx>=0.5.0 numpy>=1.17 ply>=3.10 psutil>=5 diff --git a/setup.py b/setup.py index a400d98de61d..ae5d79ca836b 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ "networkx>=2.2;python_version>'3.5'", # Networkx 2.4 is the final version with python 3.5 support. "networkx>=2.2,<2.4;python_version=='3.5'", - "retworkx>=0.4.0", + "retworkx>=0.5.0", "numpy>=1.17", "ply>=3.10", "psutil>=5",