From 4bd2dd8df362621ced1665a7357de89f6b18a854 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 31 Oct 2024 06:40:20 -0400 Subject: [PATCH] Avoid iterating over nodes in Split2QUnitaries if there are no unitaries (#13384) This commit adds a check to the start of the split_2q_unitaries rust function that is the core of the Split2QUnitaries transpiler pass to do a lookup if there are any `UnitaryGate` objects in the dag without iterating over the dag. The pass only will split unitary gates so we can avoid checking the name of each gate individually if we know there aren't any up front. --- crates/accelerate/src/split_2q_unitaries.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/accelerate/src/split_2q_unitaries.rs b/crates/accelerate/src/split_2q_unitaries.rs index 6950ea59021..ac2577c2fc2 100644 --- a/crates/accelerate/src/split_2q_unitaries.rs +++ b/crates/accelerate/src/split_2q_unitaries.rs @@ -28,6 +28,9 @@ pub fn split_2q_unitaries( dag: &mut DAGCircuit, requested_fidelity: f64, ) -> PyResult<()> { + if !dag.get_op_counts().contains_key("unitary") { + return Ok(()); + } let nodes: Vec = dag.op_nodes(false).collect(); for node in nodes {