Skip to content

Commit

Permalink
Remove deepcopies from DAGCircuit.__eq__ (Qiskit#4992)
Browse files Browse the repository at this point in the history
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/rustworkx#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.
  • Loading branch information
mtreinish authored Sep 18, 2020
1 parent dfd3150 commit e137554
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,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):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contextvars>=2.4;python_version<'3.7'
jsonschema>=2.6
networkx>=2.2
retworkx>=0.4.0
retworkx>=0.5.0
numpy>=1.17
ply>=3.10
psutil>=5
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"contextvars>=2.4;python_version<'3.7'",
"jsonschema>=2.6",
"networkx>=2.2",
"retworkx>=0.4.0",
"retworkx>=0.5.0",
"numpy>=1.17",
"ply>=3.10",
"psutil>=5",
Expand Down

0 comments on commit e137554

Please sign in to comment.