From 6f5048365ae8032bb736764d4acbd9117cabc9e6 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 25 Aug 2023 08:13:46 -0400 Subject: [PATCH] Do not deepcopy operations in Unroll3qOrMore (#10702) In the Unroll3qOrMore pass internally is quite simple it iterates over every operation in the circuit and for any operation that uses >= 3 qubits and recursively decompsing it into all 1 and 2 qubit operations, converting it to a DAGCircuit and substituting the >=3 qubit gates with the equivalent circuit. However, during this DAGCircuit conversion step we're spending a large amount deep copying the operation objects. However, we don't need to do this because nothing in the circuit will be reused with shared references so we can skip the copying and just pass the operation objects by reference onto the DAG (as that's all we need). This commit makes that change by using the `copy_operations` flag we introduced in #9848 on circuit_to_dag() to disable the internal copying. --- qiskit/transpiler/passes/basis/unroll_3q_or_more.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/basis/unroll_3q_or_more.py b/qiskit/transpiler/passes/basis/unroll_3q_or_more.py index 54a3ebf4c915..5fb37112a7bb 100644 --- a/qiskit/transpiler/passes/basis/unroll_3q_or_more.py +++ b/qiskit/transpiler/passes/basis/unroll_3q_or_more.py @@ -80,7 +80,7 @@ def run(self, dag): "Cannot unroll all 3q or more gates. " "No rule to expand instruction %s." % node.op.name ) - decomposition = circuit_to_dag(node.op.definition) + decomposition = circuit_to_dag(node.op.definition, copy_operations=False) decomposition = self.run(decomposition) # recursively unroll dag.substitute_node_with_dag(node, decomposition) return dag