Skip to content

Commit

Permalink
feat: expose Tk2Op name (#307)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Cobord committed Apr 8, 2024
1 parent 70e9e12 commit c4f0993
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions tket2/src/circuit/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| <Tk2Op as Into<OpType>>::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)));
Expand Down
9 changes: 8 additions & 1 deletion tket2/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
<Tk2Op as Into<OpType>>::into(*self).name()
}
}

/// Whether an op is a given Tk2Op.
pub fn op_matches(op: &OpType, tk2op: Tk2Op) -> bool {
op.name() == <Tk2Op as Into<OpType>>::into(tk2op).name()
op.name() == tk2op.exposed_name()
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, EnumIter, Display, PartialEq, PartialOrd)]
Expand Down
2 changes: 2 additions & 0 deletions tket2/src/passes/commutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c4f0993

Please sign in to comment.