diff --git a/pyrs/nam_6_3.rwr b/pyrs/pyrs/data/nam_6_3.rwr similarity index 100% rename from pyrs/nam_6_3.rwr rename to pyrs/pyrs/data/nam_6_3.rwr diff --git a/pyrs/pyrs/passes.py b/pyrs/pyrs/passes.py index 7fcba8b6..81e8b64b 100644 --- a/pyrs/pyrs/passes.py +++ b/pyrs/pyrs/passes.py @@ -1,4 +1,6 @@ from pathlib import Path +from typing import Optional +import pkg_resources from pytket import Circuit from pytket.passes import CustomPass @@ -6,29 +8,26 @@ def taso_pass( - rewriter_dir=None, - rewriter_file=None, - max_threads=None, - timeout=None, - log_dir=None, - rebase=None, + rewriter: Optional[Path] = None, + max_threads: Optional[int] = None, + timeout: Optional[int] = None, + log_dir: Optional[Path] = None, + rebase: Optional[bool] = None, ) -> CustomPass: """Construct a TASO pass. - A Taso optimiser may be specified using either `rewriter_dir` or `rewriter_file`. - If `rewriter_dir` is specified, the optimiser will be loaded from the file - `rewriter_dir/nam_6_3.rwr`. By default, will search for a rewritier in - the current directory. The rewriter must be precompiled. + The Taso optimiser requires a pre-compiled rewriter produced by the + `compile-rewriter `_ + utility. If `rewriter` is not specified, a default one will be used. The arguments `max_threads`, `timeout`, `log_dir` and `rebase` are optional and will be passed on to the TASO optimiser if provided.""" - if rewriter_dir is None: - rewriter_dir = "." - if rewriter_file is None: - rewriter_file = Path(rewriter_dir) / "nam_6_3.rwr" - opt = optimiser.TasoOptimiser.load_precompiled(rewriter_file) + if rewriter is None: + rewriter = pkg_resources.resource_filename("pyrs", "data/nam_6_3.rwr") + print("Using default rewriter", rewriter) + opt = optimiser.TasoOptimiser.load_precompiled(rewriter) - def apply(circuit: Circuit): + def apply(circuit: Circuit) -> Circuit: """Apply TASO optimisation to the circuit.""" return passes.taso_optimise( circuit,