Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose Tk2Op name #307

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading