Skip to content

Commit

Permalink
Add fast path through dag_to_circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Jun 29, 2024
1 parent 48ec3ce commit cba43f1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions qiskit/converters/dag_to_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import copy

from qiskit.circuit import QuantumCircuit, CircuitInstruction
from qiskit._accelerate.circuit import StandardGate


def dag_to_circuit(dag, copy_operations=True):
Expand Down Expand Up @@ -71,10 +72,24 @@ def dag_to_circuit(dag, copy_operations=True):
circuit.calibrations = dag.calibrations

for node in dag.topological_op_nodes():
op = node.op
if copy_operations:
op = copy.deepcopy(op)
circuit._append(CircuitInstruction(op, node.qargs, node.cargs))
if not isinstance(node._raw_op, StandardGate):
op = node.op
if copy_operations:
op = copy.deepcopy(op)
circuit._append(CircuitInstruction(op, node.qargs, node.cargs))
else:
circuit._append(
CircuitInstruction(
node._raw_op,
node.qargs,
node.cargs,
params=node.params,
label=node.label,
duration=node.duration,
unit=node.unit,
condition=node.condition,
)
)

circuit.duration = dag.duration
circuit.unit = dag.unit
Expand Down

0 comments on commit cba43f1

Please sign in to comment.