diff --git a/tket2/src/circuit.rs b/tket2/src/circuit.rs index 5d3afff8..10728089 100644 --- a/tket2/src/circuit.rs +++ b/tket2/src/circuit.rs @@ -231,6 +231,22 @@ impl Circuit { CommandIterator::new(self) } + /// Returns the top-level operations in the circuit, in some topological + /// order. + /// + /// This is a subset of the commands returned by [`Circuit::commands`], only + /// including [`Tk2Op`]s, pytket ops, and any other custom operations. + /// + /// [`Tk2Op`]: crate::Tk2Op + #[inline] + pub fn operations(&self) -> impl Iterator> + '_ + where + Self: Sized, + { + // Traverse the circuit in topological order. + self.commands().filter(|cmd| cmd.optype().is_custom_op()) + } + /// Compute the cost of the circuit based on a per-operation cost function. #[inline] pub fn circuit_cost(&self, op_cost: F) -> C @@ -570,6 +586,7 @@ mod tests { ); assert_eq!(circ.qubit_count(), qubits); assert_eq!(circ.num_operations(), 3); + assert_eq!(circ.operations().count(), 3); assert_eq!(circ.units().count(), qubits + bits); assert_eq!(circ.nonlinear_units().count(), 0);