-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In hindsight this should have been part of #180. However, note that the Python tests currently fail: I get a segmentation fault, no idea why! drive by: renamed `PyDefaultTasoOptimiser` -> `PyTasoOptimiser`. --------- Co-authored-by: Agustin Borgna <[email protected]>
- Loading branch information
Showing
6 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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: 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. | ||
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 is None: | ||
rewriter = pkg_resources.resource_filename("pyrs", "data/nam_6_3.rwr") | ||
opt = optimiser.TasoOptimiser.load_precompiled(rewriter) | ||
|
||
def apply(circuit: Circuit) -> Circuit: | ||
"""Apply TASO optimisation to the circuit.""" | ||
return passes.taso_optimise( | ||
circuit, | ||
opt, | ||
max_threads, | ||
timeout, | ||
log_dir, | ||
rebase, | ||
) | ||
|
||
return CustomPass(apply) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from pytket import Circuit, OpType | ||
from pyrs.pyrs import passes | ||
from pyrs.passes import taso_pass | ||
|
||
|
||
def test_simple_taso_pass_no_opt(): | ||
c = Circuit(3).CCX(0, 1, 2) | ||
c = passes.taso_optimise(c, max_threads = 1, timeout = 0) | ||
print(c) | ||
assert c.n_gates_of_type(OpType.CX) == 6 | ||
taso = taso_pass(max_threads = 1, timeout = 0) | ||
taso.apply(c) | ||
assert c.n_gates_of_type(OpType.CX) == 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters