Skip to content

Commit

Permalink
Move default rewriter to packaged data
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 31, 2023
1 parent aaf2bad commit a075b92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
File renamed without changes.
31 changes: 15 additions & 16 deletions pyrs/pyrs/passes.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
from pathlib import Path
from typing import Optional
import pkg_resources

from pytket import Circuit
from pytket.passes import CustomPass
from pyrs.pyrs import passes, optimiser


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 <https://github.com/CQCL/tket2/tree/main/taso-optimiser>`_
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,
Expand Down

0 comments on commit a075b92

Please sign in to comment.