Skip to content

Commit

Permalink
Add rebase_pass to Backend (#176)
Browse files Browse the repository at this point in the history
* Add rebase_pass to Backend

* Add rebase_pass to TketSimBackend

* Update pytket/pytket/backends/backend.py

Co-authored-by: Alec Edgington <[email protected]>

Co-authored-by: Alec Edgington <[email protected]>
  • Loading branch information
sjdilkes and cqc-alec authored Jan 19, 2022
1 parent b82d50a commit 055558e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions pytket/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
Minor new features:

* Improve ``CnX`` gate decomposition for n=5,6,7.
* Add ``rebase_pass`` method to ``Backend``.

General:

Expand Down
12 changes: 12 additions & 0 deletions pytket/pytket/backends/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ def _check_all_circuits(
)
return True

@abstractmethod
def rebase_pass(self) -> BasePass:
"""
A single compilation pass that when run converts all gates in a Circuit to
an OpType supported by the Backend (ignoring architecture constraints).
:return: Compilation pass that converts gates to primitives supported by
Backend.
:rtype: BasePass
"""
...

@abstractmethod
def default_compilation_pass(self, optimisation_level: int = 1) -> BasePass:
"""
Expand Down
17 changes: 11 additions & 6 deletions pytket/tests/simulator/tket_sim_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ def required_predicates(self) -> List[Predicate]:
NoFastFeedforwardPredicate(),
]

def rebase_pass(self) -> BasePass:
return RebasePyZX()

def default_compilation_pass(self, optimisation_level: int = 1) -> BasePass:
assert optimisation_level in range(3)
if optimisation_level == 0:
return SequencePass([DecomposeBoxes(), RebasePyZX()])
return SequencePass([DecomposeBoxes(), self.rebase_pass()])
elif optimisation_level == 1:
return SequencePass([DecomposeBoxes(), SynthesiseTket(), RebasePyZX()])
return SequencePass(
[DecomposeBoxes(), SynthesiseTket(), self.rebase_pass()]
)
else:
return SequencePass(
[DecomposeBoxes(), FullPeepholeOptimise(), RebasePyZX()]
[DecomposeBoxes(), FullPeepholeOptimise(), self.rebase_pass()]
)

def process_circuits(
Expand Down Expand Up @@ -123,13 +128,13 @@ class TketSimShotBackend(TketSimBackend):
def default_compilation_pass(self, optimisation_level: int = 1) -> BasePass:
assert optimisation_level in range(3)
if optimisation_level == 0:
return SequencePass([DecomposeBoxes(), RebasePyZX()])
return SequencePass([DecomposeBoxes(), self.rebase_pass()])
elif optimisation_level == 1:
return SequencePass(
[
DecomposeBoxes(),
SynthesiseTket(),
RebasePyZX(),
self.rebase_pass(),
SimplifyInitial(allow_classical=False, create_all_qubits=True),
]
)
Expand All @@ -138,7 +143,7 @@ def default_compilation_pass(self, optimisation_level: int = 1) -> BasePass:
[
DecomposeBoxes(),
FullPeepholeOptimise(),
RebasePyZX(),
self.rebase_pass(),
SimplifyInitial(allow_classical=False, create_all_qubits=True),
]
)
Expand Down

0 comments on commit 055558e

Please sign in to comment.