Skip to content

Commit

Permalink
Do not deepcopy operations in Unroll3qOrMore (#10702)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtreinish authored Aug 25, 2023
1 parent 676b329 commit 6f50483
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/basis/unroll_3q_or_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6f50483

Please sign in to comment.