Skip to content

Commit 35fe285

Browse files
authored
feat: Deprecate local find_tuple_unpack rewrite (#1188)
We moved the untuple rewrite into a hugr pass (https://docs.rs/hugr/latest/hugr/algorithms/struct.UntuplePass.html), but never removed it from here.
1 parent 06ac607 commit 35fe285

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

tket/src/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod pytket;
1111
pub use pytket::lower_to_pytket;
1212

1313
pub mod tuple_unpack;
14+
#[allow(deprecated)]
1415
pub use tuple_unpack::find_tuple_unpack_rewrites;
1516

1617
pub mod unpack_container;

tket/src/passes/pytket.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
//! This is a best-effort attempt, and may not always succeed.
55
66
use derive_more::{Display, Error, From};
7+
use hugr::algorithms::untuple::{UntupleError, UntupleRecursive};
8+
use hugr::algorithms::{ComposablePass, UntuplePass};
79
use hugr::{HugrView, Node};
8-
use itertools::Itertools;
910

1011
use crate::serialize::pytket::OpConvertError;
1112
use crate::Circuit;
1213

13-
use super::find_tuple_unpack_rewrites;
14-
1514
/// Try to lower a circuit to a form that can be encoded as a pytket legacy circuit.
1615
pub fn lower_to_pytket<T: HugrView<Node = Node>>(
1716
circ: &Circuit<T>,
@@ -22,10 +21,7 @@ pub fn lower_to_pytket<T: HugrView<Node = Node>>(
2221

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

3026
Ok(circ)
3127
}
@@ -42,6 +38,10 @@ pub enum PytketLoweringError {
4238
/// Function calls are not supported.
4339
#[display("Non-local operations found. Function calls are not supported.")]
4440
NonLocalOperations,
41+
/// An error occurred during the untuple pass.
42+
#[display("untuple pass error: {_0}")]
43+
#[from]
44+
UntupleError(UntupleError),
4545
}
4646

4747
#[cfg(test)]

tket/src/passes/tuple_unpack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::Circuit;
1616

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

0 commit comments

Comments
 (0)