Skip to content

Commit

Permalink
Copy-in rather than copy-out in transpiler (#11176)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jakelishman authored Nov 2, 2023
1 parent dabc5e6 commit eca3478
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions qiskit/transpiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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,
passmanager_ir: DAGCircuit,
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:
Expand Down

0 comments on commit eca3478

Please sign in to comment.