From c4f0993782bb99d842ef8cdf34fa16ad449c401f Mon Sep 17 00:00:00 2001 From: Ammar Husain Date: Mon, 8 Apr 2024 09:41:33 -0400 Subject: [PATCH] feat: expose Tk2Op name (#307) a TODO was written for exposing the name as a public function on Tk2Op to avoid intos at caller also update the comment on the impl of Rewrite of PullForward to reflect change in hugr --- tket2/src/circuit/command.rs | 3 +-- tket2/src/ops.rs | 9 ++++++++- tket2/src/passes/commutation.rs | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tket2/src/circuit/command.rs b/tket2/src/circuit/command.rs index 3b5c4e66..24ed5ff9 100644 --- a/tket2/src/circuit/command.rs +++ b/tket2/src/circuit/command.rs @@ -501,8 +501,7 @@ mod test { assert_eq!(CommandIterator::new(&circ).count(), 3); - // TODO: Expose the operation names directly in Tk2Op to clean this up - let tk2op_name = |op: Tk2Op| >::into(op).name(); + let tk2op_name = |op: Tk2Op| op.exposed_name(); let mut commands = CommandIterator::new(&circ); assert_eq!(commands.size_hint(), (3, Some(3))); diff --git a/tket2/src/ops.rs b/tket2/src/ops.rs index 84f33540..d6b535d9 100644 --- a/tket2/src/ops.rs +++ b/tket2/src/ops.rs @@ -70,9 +70,16 @@ pub enum Tk2Op { Reset, } +impl Tk2Op { + /// Expose the operation names directly in Tk2Op + pub fn exposed_name(&self) -> smol_str::SmolStr { + >::into(*self).name() + } +} + /// Whether an op is a given Tk2Op. pub fn op_matches(op: &OpType, tk2op: Tk2Op) -> bool { - op.name() == >::into(tk2op).name() + op.name() == tk2op.exposed_name() } #[derive(Clone, Copy, Debug, Serialize, Deserialize, EnumIter, Display, PartialEq, PartialOrd)] diff --git a/tket2/src/passes/commutation.rs b/tket2/src/passes/commutation.rs index c493a015..36124566 100644 --- a/tket2/src/passes/commutation.rs +++ b/tket2/src/passes/commutation.rs @@ -281,6 +281,8 @@ impl Rewrite for PullForward { fn invalidation_set(&self) -> Self::InvalidationSet<'_> { // TODO: This could avoid creating a vec, but it'll be easier to do once // return position impl trait is available. + // This is done in the Rewrite trait of hugr so once that version + // is released, it can be updated here let mut nodes = vec![self.command.node()]; let next_nodes = self.new_nexts.values().map(|c| c.node()); nodes.extend(next_nodes);