diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index cddbfb7ca8..41e270cf25 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -7,6 +7,7 @@ Changelog Minor new features: * Improve ``CnX`` gate decomposition for n=5,6,7. +* Add ``rebase_pass`` method to ``Backend``. General: diff --git a/pytket/pytket/backends/backend.py b/pytket/pytket/backends/backend.py index 9373e12331..0194fa69e7 100644 --- a/pytket/pytket/backends/backend.py +++ b/pytket/pytket/backends/backend.py @@ -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: """ diff --git a/pytket/tests/simulator/tket_sim_backend.py b/pytket/tests/simulator/tket_sim_backend.py index abcbec9c24..1cf89685f7 100644 --- a/pytket/tests/simulator/tket_sim_backend.py +++ b/pytket/tests/simulator/tket_sim_backend.py @@ -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( @@ -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), ] ) @@ -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), ] )