Skip to content
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
1 change: 1 addition & 0 deletions tket/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod pytket;
pub use pytket::lower_to_pytket;

pub mod tuple_unpack;
#[allow(deprecated)]
pub use tuple_unpack::find_tuple_unpack_rewrites;

pub mod unpack_container;
14 changes: 7 additions & 7 deletions tket/src/passes/pytket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
//! This is a best-effort attempt, and may not always succeed.

use derive_more::{Display, Error, From};
use hugr::algorithms::untuple::{UntupleError, UntupleRecursive};
use hugr::algorithms::{ComposablePass, UntuplePass};
use hugr::{HugrView, Node};
use itertools::Itertools;

use crate::serialize::pytket::OpConvertError;
use crate::Circuit;

use super::find_tuple_unpack_rewrites;

/// Try to lower a circuit to a form that can be encoded as a pytket legacy circuit.
pub fn lower_to_pytket<T: HugrView<Node = Node>>(
circ: &Circuit<T>,
Expand All @@ -22,10 +21,7 @@ pub fn lower_to_pytket<T: HugrView<Node = Node>>(

// Remove sequences of tuple pack-unpack operations,
// typically generated by guppy.
let rewrites = find_tuple_unpack_rewrites(&circ).collect_vec();
for rewrite in rewrites {
rewrite.apply(&mut circ).unwrap();
}
UntuplePass::new(UntupleRecursive::NonRecursive).run(circ.hugr_mut())?;

Ok(circ)
}
Expand All @@ -42,6 +38,10 @@ pub enum PytketLoweringError {
/// Function calls are not supported.
#[display("Non-local operations found. Function calls are not supported.")]
NonLocalOperations,
/// An error occurred during the untuple pass.
#[display("untuple pass error: {_0}")]
#[from]
UntupleError(UntupleError),
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions tket/src/passes/tuple_unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::Circuit;

/// Find tuple pack operations followed by tuple unpack operations
/// and generate rewrites to remove them.
#[deprecated(since = "0.15.1", note = "Use hugr::algorithms::UntuplePass instead")]
pub fn find_tuple_unpack_rewrites(
circ: &Circuit<impl HugrView<Node = Node>>,
) -> impl Iterator<Item = CircuitRewrite> + '_ {
Expand Down Expand Up @@ -239,6 +240,7 @@ mod test {
) -> Result<(), Box<dyn std::error::Error>> {
let mut num_rewrites = 0;
loop {
#[allow(deprecated)]
let Some(rewrite) = find_tuple_unpack_rewrites(&circ).next() else {
break;
};
Expand Down
Loading