Skip to content

Commit

Permalink
Avoid intermediate DAGs in Optimize1qGatesDecomposition (#12176)
Browse files Browse the repository at this point in the history
This commit removes the use of intermediate DAGCircuit objects and
calling substitute_node_with_dag() in the Optimize1qGatesDecomposition
pass. Since everything is 1q it's very easy to just directly insert the
nodes on the DAG prior to the run and then remove the old nodes. This
avoids a lot of extra operations and overhead to create a second dagcircuit
for each identified run and then substiting that dag in place of the
run.
  • Loading branch information
mtreinish committed Apr 22, 2024
1 parent 7175368 commit 497603b
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)
from qiskit.circuit import Qubit
from qiskit.dagcircuit.dagcircuit import DAGCircuit
from qiskit.dagcircuit.dagnode import DAGOpNode


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -213,10 +214,15 @@ def run(self, dag):
if best_circuit_sequence is not None and self._substitution_checks(
dag, run, best_circuit_sequence, basis, qubit
):
new_dag = self._gate_sequence_to_dag(best_circuit_sequence)
dag.substitute_node_with_dag(run[0], new_dag)
for gate_name, angles in best_circuit_sequence:
op = NAME_MAP[gate_name](*angles)
node = DAGOpNode(NAME_MAP[gate_name](*angles), run[0].qargs, dag=dag)
node._node_id = dag._multi_graph.add_node(node)
dag._increment_op(op)
dag._multi_graph.insert_node_on_in_edges(node._node_id, run[0]._node_id)
dag.global_phase += best_circuit_sequence.global_phase
# Delete the other nodes in the run
for current_node in run[1:]:
for current_node in run:
dag.remove_op_node(current_node)

return dag
Expand Down

0 comments on commit 497603b

Please sign in to comment.