@@ -11,10 +11,11 @@ use std::{cmp::min, convert::TryInto, fs, num::NonZeroUsize, path::PathBuf};
1111
1212use pyo3:: prelude:: * ;
1313use tket:: optimiser:: badger:: BadgerOptions ;
14- use tket:: passes;
1514use tket:: passes:: composable:: { ComposablePass , WithScope } ;
1615use tket:: { Circuit , TketOp , op_matches} ;
1716
17+ use tket:: passes;
18+
1819use crate :: optimiser:: PyBadgerOptimiser ;
1920use crate :: state:: CompilationState ;
2021use crate :: utils:: { ConvertPyErr , create_py_exception} ;
@@ -32,6 +33,7 @@ pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
3233 m. add_function ( wrap_pyfunction ! ( self :: chunks:: chunks, & m) ?) ?;
3334 m. add_function ( wrap_pyfunction ! ( self :: tket1:: tket1_pass, & m) ?) ?;
3435 m. add_function ( wrap_pyfunction ! ( resolve_modifiers, & m) ?) ?;
36+ m. add_function ( wrap_pyfunction ! ( qsystem_rebase_pass, & m) ?) ?;
3537 m. add ( "PullForwardError" , py. get_type :: < PyPullForwardError > ( ) ) ?;
3638 m. add (
3739 "InlineFunctionsError" ,
@@ -64,6 +66,13 @@ create_py_exception!(
6466 PyInlineFunctionsError ,
6567 "Errors from the function inlining pass."
6668) ;
69+
70+ create_py_exception ! (
71+ tket_qsystem:: QSystemPassError ,
72+ PyQSystemPassError ,
73+ "Errors from the QSystem rebase pass."
74+ ) ;
75+
6776/// Flatten the structure of a Guppy-generated program to enable additional optimisations.
6877///
6978/// This should normally be called first before other optimisations.
@@ -203,3 +212,26 @@ fn resolve_modifiers(circ: &mut CompilationState, scope: Option<PyPassScope>) ->
203212 pass. run ( & mut circ. hugr ) . convert_pyerrs ( ) ?;
204213 Ok ( ( ) )
205214}
215+
216+ #[ pyfunction]
217+ #[ pyo3( signature=( circ, * , constant_fold = true , monomorphize = true , force_order = true , lazify = true , hide_funcs = true , scope = None ) ) ]
218+ fn qsystem_rebase_pass (
219+ circ : & mut CompilationState ,
220+ constant_fold : bool ,
221+ monomorphize : bool ,
222+ force_order : bool ,
223+ lazify : bool ,
224+ hide_funcs : bool ,
225+ scope : Option < PyPassScope > ,
226+ ) -> PyResult < ( ) > {
227+ let py_scope = scope. unwrap_or_default ( ) ;
228+ let qsystem_pass = tket_qsystem:: QSystemPass :: default_with_scope ( py_scope. scope )
229+ . with_constant_fold ( constant_fold)
230+ . with_monomorphize ( monomorphize)
231+ . with_force_order ( force_order)
232+ . with_lazify ( lazify)
233+ . with_hide_funcs ( hide_funcs) ;
234+
235+ qsystem_pass. run ( & mut circ. hugr ) . convert_pyerrs ( ) ?;
236+ Ok ( ( ) )
237+ }
0 commit comments