From 22e791ac868bb0c3b5603b3fce15af03001c8404 Mon Sep 17 00:00:00 2001 From: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:58:02 +0000 Subject: [PATCH] Remove deprecated auto_rebase_pass and auto_squash_pass. (#1693) --- pytket/docs/changelog.rst | 7 +++ pytket/docs/faqs.rst | 4 +- pytket/docs/passes.rst | 7 +-- pytket/pytket/passes/__init__.py | 1 - pytket/pytket/passes/auto_rebase.py | 93 ----------------------------- pytket/tests/predicates_test.py | 15 ----- pytket/tests/zx_diagram_test.py | 2 +- 7 files changed, 11 insertions(+), 118 deletions(-) delete mode 100644 pytket/pytket/passes/auto_rebase.py diff --git a/pytket/docs/changelog.rst b/pytket/docs/changelog.rst index bd7a814086..5fd2aac7d4 100644 --- a/pytket/docs/changelog.rst +++ b/pytket/docs/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +Unreleased +---------- + +API changes: + +* Remove the deprecated methods `auto_rebase_pass()` and `auto_squash_pass()`. + 1.35.0 (November 2024) ---------------------- diff --git a/pytket/docs/faqs.rst b/pytket/docs/faqs.rst index d5e333b6f2..926b0205f2 100644 --- a/pytket/docs/faqs.rst +++ b/pytket/docs/faqs.rst @@ -9,9 +9,9 @@ Q: Can I convert a pytket :py:class:`Circuit` to a gateset of my choice? A: Yes, this can be done in many cases provided the target gateset is a set of one and two qubit pytket :py:class:`OpType` s. There are two types of rebase -1) :py:meth:`auto_rebase_pass` - this uses a set of hardcoded decompositions to convert between gatesets. This can be used quickly when the gateset is one widely used on quantum hardware e.g. IBM's {X, SX, Rz, CX} gateset. +1) :py:meth:`AutoRebase` - this uses a set of hardcoded decompositions to convert between gatesets. This can be used quickly when the gateset is one widely used on quantum hardware e.g. IBM's {X, SX, Rz, CX} gateset. -2) :py:class:`RebaseCustom` - This can be used instead of `auto_rebase_pass` in cases where there is no hardcoded conversion available. +2) :py:class:`RebaseCustom` - This can be used instead of `AutoRebase` in cases where there is no hardcoded conversion available. In this case the user will have to specify how to implement TKET's {TK1, CX} or {TK1, TK2} operations in terms of the target :py:class:`OpType` s. See the manual section on `rebases `_ for examples. diff --git a/pytket/docs/passes.rst b/pytket/docs/passes.rst index 9b9b3df4c2..f68dec3c2a 100644 --- a/pytket/docs/passes.rst +++ b/pytket/docs/passes.rst @@ -7,7 +7,7 @@ There are passes such as `FullPeepholeOptimise `_ and `PauliSimp `_ which perform optimisation by targeting phase gadget and Pauli gadget structures within circuits. For more on these optimisation techniques see the `corresponding publication `_. -Rebase passes can be used to convert a circuit to a desired gateset. See `RebaseCustom `_ and `auto_rebase_pass `_. +Rebase passes can be used to convert a circuit to a desired gateset. See `RebaseCustom `_ and `AutoRebase `_. For more on pytket passes see the `compilation `_ section of the user manual or the `notebook tutorials `_ @@ -25,8 +25,3 @@ pytket.passes.script .. automodule:: pytket.passes.script :members: compilation_pass_from_script, compilation_pass_grammar - -pytket.passes.auto_rebase -~~~~~~~~~~~~~~~~~~~~~~~~~ -.. automodule:: pytket.passes.auto_rebase - :members: auto_rebase_pass, auto_squash_pass \ No newline at end of file diff --git a/pytket/pytket/passes/__init__.py b/pytket/pytket/passes/__init__.py index 65d104fab1..d69e6d833a 100644 --- a/pytket/pytket/passes/__init__.py +++ b/pytket/pytket/passes/__init__.py @@ -16,7 +16,6 @@ from pytket._tket.passes import * -from .auto_rebase import auto_rebase_pass, auto_squash_pass from .passselector import PassSelector from .resizeregpass import scratch_reg_resize_pass from .script import compilation_pass_from_script, compilation_pass_grammar diff --git a/pytket/pytket/passes/auto_rebase.py b/pytket/pytket/passes/auto_rebase.py deleted file mode 100644 index 37e5d22d1c..0000000000 --- a/pytket/pytket/passes/auto_rebase.py +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright 2019-2024 Cambridge Quantum Computing -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import warnings - -from pytket.circuit import OpType -from pytket.passes import AutoRebase, AutoSquash, BasePass - - -class NoAutoRebase(Exception): - """Automatic rebase could not be found. - - "DEPRECATED: will be removed after pytket 1.33." - """ - - def __init__(self, *args: object, **kwargs: dict) -> None: - warnings.warn( - "The `NoAutoRebase` exception is deprecated along with " - "`auto_rebase_pass()` and `auto_squash_pass()`. " - "`AutoRebase` and `AutoSquash` will raise `RuntimeError` instead.", - DeprecationWarning, - ) - super().__init__(*args, **kwargs) - - -def auto_rebase_pass(gateset: set[OpType], allow_swaps: bool = False) -> BasePass: - """Attempt to generate a rebase pass automatically for the given target - gateset. - - Checks if there are known existing decompositions - to target gateset and TK1 to target gateset and uses those to construct a - custom rebase. - Raises an error if no known decompositions can be found, in which case try - using RebaseCustom with your own decompositions. - - In addition to the gate types in ``gateset``, any ``Measure`` and ``Reset`` - operations in the original circuit are retained. Conditional - operations are also allowed. ``Phase`` gates may also be introduced. - - :param gateset: Set of supported OpTypes, target gate set. - :type gateset: FrozenSet[OpType] - :raises NoAutoRebase: No suitable decomposition found. - :return: Rebase pass. - :rtype: AutoRebase - - .. deprecated:: 1.29.0 - Will be removed after pytket 1.33, please use `AutoRebase` instead. - """ - warnings.warn( - "The `auto_rebase_pass()` method is deprecated and will be removed after " - "pytket 1.33, please use `AutoRebase` instead.", - DeprecationWarning, - ) - try: - return AutoRebase(gateset, allow_swaps) - except RuntimeError: - raise NoAutoRebase( - "No known decomposition from TK1, CX or TK2 to available gateset." - ) - - -def auto_squash_pass(gateset: set[OpType]) -> BasePass: - """Attempt to generate a squash pass automatically for the given target - single qubit gateset. - - :param gateset: Available single qubit gateset - :type gateset: Set[OpType] - :return: Squash to target gateset - :rtype: AutoSquash - - .. deprecated:: 1.29.0 - Will be removed after pytket 1.33, please use `AutoSquash` instead. - """ - warnings.warn( - "The `auto_squash_pass()` method is deprecated and will be removed after " - "pytket 1.33, please use `AutoSquash` instead.", - DeprecationWarning, - ) - try: - return AutoSquash(gateset) - except RuntimeError: - raise NoAutoRebase("No known decomposition from TK1 to available gateset.") diff --git a/pytket/tests/predicates_test.py b/pytket/tests/predicates_test.py index 1bda5404cc..c09098ffd1 100644 --- a/pytket/tests/predicates_test.py +++ b/pytket/tests/predicates_test.py @@ -86,8 +86,6 @@ ThreeQubitSquash, ZXGraphlikeOptimisation, ZZPhaseToRz, - auto_rebase_pass, - auto_squash_pass, ) from pytket.pauli import Pauli from pytket.placement import GraphPlacement, Placement @@ -1094,19 +1092,6 @@ def test_greedy_pauli_synth() -> None: assert GreedyPauliSimp().apply(c) -def test_auto_rebase_deprecation(recwarn: Any) -> None: - _ = auto_rebase_pass({OpType.TK1, OpType.CX}) - assert len(recwarn) == 1 - w = recwarn.pop(DeprecationWarning) - assert issubclass(w.category, DeprecationWarning) - assert "deprecated" in str(w.message) - _ = auto_squash_pass({OpType.TK1}) - assert len(recwarn) == 1 - w = recwarn.pop(DeprecationWarning) - assert issubclass(w.category, DeprecationWarning) - assert "deprecated" in str(w.message) - - if __name__ == "__main__": test_predicate_generation() test_compilation_unit_generation() diff --git a/pytket/tests/zx_diagram_test.py b/pytket/tests/zx_diagram_test.py index ac8e7aebea..17be46a8d5 100644 --- a/pytket/tests/zx_diagram_test.py +++ b/pytket/tests/zx_diagram_test.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from math import isclose, pow +from math import isclose from typing import Tuple import numpy as np