From eca34781da660911aa2cee8ff2f620c6ba27f501 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 2 Nov 2023 16:50:25 +0000 Subject: [PATCH] Copy-in rather than copy-out in transpiler (#11176) This shifts the deepcopy of instructions in the transpiler to be at the input stage, rather than the output stage. This more closely matches our behaviour before the passmanager refactoring, but also has a performance benefit for circuits that require significant routing and is typically safer for transpiler passes. Output circuits are typically larger than input ones, so copy-in means less copying, and also makes the ownership model for tranpsiler passes clearer: a pass can assume the input operations are entirely owned by the circuit it receives, and that a pass must output a circuit that entirely owns its operations. --- qiskit/transpiler/passmanager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/transpiler/passmanager.py b/qiskit/transpiler/passmanager.py index 6ee5d702ddfa..c9c67be05d6a 100644 --- a/qiskit/transpiler/passmanager.py +++ b/qiskit/transpiler/passmanager.py @@ -65,7 +65,7 @@ def _passmanager_frontend( input_program: QuantumCircuit, **kwargs, ) -> DAGCircuit: - return circuit_to_dag(input_program, copy_operations=False) + return circuit_to_dag(input_program, copy_operations=True) def _passmanager_backend( self, @@ -73,7 +73,7 @@ def _passmanager_backend( in_program: QuantumCircuit, **kwargs, ) -> QuantumCircuit: - out_program = dag_to_circuit(passmanager_ir) + out_program = dag_to_circuit(passmanager_ir, copy_operations=False) out_name = kwargs.get("output_name", None) if out_name is not None: