From fcebffdbb61617c1e7d96c37b8f007e81b903e8f Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 25 Jul 2024 16:05:35 -0400 Subject: [PATCH] Also include standard gates in .gate_nodes() return --- crates/circuit/src/dag_circuit.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/circuit/src/dag_circuit.rs b/crates/circuit/src/dag_circuit.rs index b149d4c6fdd9..12dc0e84bf0f 100644 --- a/crates/circuit/src/dag_circuit.rs +++ b/crates/circuit/src/dag_circuit.rs @@ -3913,15 +3913,16 @@ new_condition = (new_target, value) /// Returns: /// list[DAGOpNode]: the list of DAGOpNodes that represent gates. fn gate_nodes(&self, py: Python) -> PyResult>> { - let mut nodes = Vec::new(); - for (node, weight) in self.dag.node_references() { - if let NodeType::Operation(ref packed) = weight { - if let OperationRef::Gate(_) = packed.op.view() { - nodes.push(self.unpack_into(py, node, weight)?); + self.dag.node_references().filter_map(|(node, weight)| { + match weight { + NodeType::Operation(ref packed) => match packed.op.view() { + OperationRef::Gate(_) | OperationRef::Standard(_) => Some(self.unpack_into(py, node, weight)), + _ => None } + _ => None, } - } - Ok(nodes) + }) + .collect() } /// Get the set of "op" nodes with the given name.