From 6aad91418951484ee5cf808a0c147f96bc951223 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Thu, 20 Oct 2022 19:17:04 +0100 Subject: [PATCH] Remove tweedledum as a core dependency (#8947) * Remove tweedledum as a core dependency Maintenance on tweedledum has stagnated in recent months, and is no longer stable enough on our Tier-1 (and other) supported platforms, especially as further Python versions are released. This work was heralded by gh-8738, which contains more context on the change. * Add tweedledum pylint suppressions I couldn't get `.pylintrc`'s `ignore{,d}-modules` options to work right for this, so I just resorted to localised suppressions. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- qiskit/circuit/classicalfunction/__init__.py | 5 +++-- .../classicalfunction/boolean_expression.py | 4 ++-- .../classical_function_visitor.py | 2 +- .../circuit/classicalfunction/classicalfunction.py | 4 ++-- qiskit/circuit/classicalfunction/utils.py | 4 ++-- qiskit/circuit/library/phase_oracle.py | 2 +- .../notes/remove-tweedledum-0f21ca327a782bc3.yaml | 14 ++++++++++++++ requirements.txt | 4 ---- .../test_tweedledum2qiskit.py | 1 + 9 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/remove-tweedledum-0f21ca327a782bc3.yaml diff --git a/qiskit/circuit/classicalfunction/__init__.py b/qiskit/circuit/classicalfunction/__init__.py index d8cb8fc5ad50..04a8a7ffe16d 100644 --- a/qiskit/circuit/classicalfunction/__init__.py +++ b/qiskit/circuit/classicalfunction/__init__.py @@ -9,6 +9,7 @@ # Any modifications or derivative works of this code must retain this # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. + """ ==================================================================== ClassicalFunction compiler (:mod:`qiskit.circuit.classicalfunction`) @@ -97,9 +98,9 @@ def grover_oracle(a: Int1, b: Int1, c: Int1, d: Int1) -> Int1: """ -from qiskit.utils import optionals as _optionals +from qiskit.utils.optionals import HAS_TWEEDLEDUM -_optionals.HAS_TWEEDLEDUM.require_now("classical oracle creation") +HAS_TWEEDLEDUM.require_now("classical function oracles") # pylint: disable=wrong-import-position diff --git a/qiskit/circuit/classicalfunction/boolean_expression.py b/qiskit/circuit/classicalfunction/boolean_expression.py index a639f1404f73..8ac4c8356f24 100644 --- a/qiskit/circuit/classicalfunction/boolean_expression.py +++ b/qiskit/circuit/classicalfunction/boolean_expression.py @@ -15,8 +15,8 @@ from os.path import basename, isfile from typing import Callable, Optional -from tweedledum import BitVec, BoolFunction -from tweedledum.synthesis import pkrm_synth +from tweedledum import BitVec, BoolFunction # pylint: disable=import-error +from tweedledum.synthesis import pkrm_synth # pylint: disable=import-error from qiskit.circuit import QuantumCircuit from .classical_element import ClassicalElement diff --git a/qiskit/circuit/classicalfunction/classical_function_visitor.py b/qiskit/circuit/classicalfunction/classical_function_visitor.py index 51bfdb6beb96..1b882ec628cb 100644 --- a/qiskit/circuit/classicalfunction/classical_function_visitor.py +++ b/qiskit/circuit/classicalfunction/classical_function_visitor.py @@ -17,7 +17,7 @@ import ast import _ast -from tweedledum.classical import LogicNetwork +from tweedledum.classical import LogicNetwork # pylint: disable=import-error from .exceptions import ClassicalFunctionParseError, ClassicalFunctionCompilerTypeError diff --git a/qiskit/circuit/classicalfunction/classicalfunction.py b/qiskit/circuit/classicalfunction/classicalfunction.py index af4be828ce5f..dae3449db225 100644 --- a/qiskit/circuit/classicalfunction/classicalfunction.py +++ b/qiskit/circuit/classicalfunction/classicalfunction.py @@ -15,8 +15,8 @@ import ast from typing import Callable, Optional -from tweedledum.classical import simulate -from tweedledum.synthesis import pkrm_synth +from tweedledum.classical import simulate # pylint: disable=import-error +from tweedledum.synthesis import pkrm_synth # pylint: disable=import-error from qiskit.circuit import QuantumCircuit, QuantumRegister from qiskit.exceptions import QiskitError diff --git a/qiskit/circuit/classicalfunction/utils.py b/qiskit/circuit/classicalfunction/utils.py index 14c503785e87..c949aae5984f 100644 --- a/qiskit/circuit/classicalfunction/utils.py +++ b/qiskit/circuit/classicalfunction/utils.py @@ -12,8 +12,8 @@ """Internal utils for Classical Function Compiler""" -from tweedledum.ir import Qubit -from tweedledum.passes import parity_decomp +from tweedledum.ir import Qubit # pylint: disable=import-error +from tweedledum.passes import parity_decomp # pylint: disable=import-error from qiskit.circuit import QuantumCircuit diff --git a/qiskit/circuit/library/phase_oracle.py b/qiskit/circuit/library/phase_oracle.py index 91d85e7670a5..699eddacbd1a 100644 --- a/qiskit/circuit/library/phase_oracle.py +++ b/qiskit/circuit/library/phase_oracle.py @@ -71,7 +71,7 @@ def __init__( if synthesizer is None: def synthesizer(boolean_expression): - from tweedledum.synthesis import pkrm_synth + from tweedledum.synthesis import pkrm_synth # pylint: disable=import-error from qiskit.circuit.classicalfunction.utils import tweedledum2qiskit truth_table = boolean_expression._tweedledum_bool_expression.truth_table( diff --git a/releasenotes/notes/remove-tweedledum-0f21ca327a782bc3.yaml b/releasenotes/notes/remove-tweedledum-0f21ca327a782bc3.yaml new file mode 100644 index 000000000000..a3df4b1d1f99 --- /dev/null +++ b/releasenotes/notes/remove-tweedledum-0f21ca327a782bc3.yaml @@ -0,0 +1,14 @@ +--- +upgrade: + - | + ``tweedledum`` has been removed as a core requirement of Qiskit Terra. The + functionality provided (:mod:`qiskit.circuit.classicalfunction`) is still + available, if ``tweedledum`` is installed manually, such as by: + + .. code-block:: text + + pip install tweedledum + + This change was made because ``tweedledum`` development has slowed to the + point of not keeping up with new Python and OS releases, and was blocking + some Qiskit users from installing Qiskit. diff --git a/requirements.txt b/requirements.txt index c05a0827b706..de6eae23fcc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,10 +12,6 @@ shared-memory38;python_version<'3.8' typing-extensions; python_version < '3.8' singledispatchmethod; python_version < '3.8' -# To be removed as a requirement in Terra 0.23. Tweedledum's wheels are -# hopelessly broken on M1 mac, so we skip the waiting period for that. -tweedledum>=1.1,<2.0; platform_machine != 'arm64' or sys_platform != 'darwin' - # Hack around stevedore being broken by importlib_metadata 5.0; we need to pin # the requirements rather than the constraints if we need to cut a release # before stevedore is fixed. `importlib_metadata` is not (currently) a direct diff --git a/test/python/classical_function_compiler/test_tweedledum2qiskit.py b/test/python/classical_function_compiler/test_tweedledum2qiskit.py index 541cbbe4ef1f..488ad4061304 100644 --- a/test/python/classical_function_compiler/test_tweedledum2qiskit.py +++ b/test/python/classical_function_compiler/test_tweedledum2qiskit.py @@ -20,6 +20,7 @@ from qiskit.circuit.library.standard_gates import XGate if HAS_TWEEDLEDUM: + # pylint: disable=import-error from qiskit.circuit.classicalfunction.utils import tweedledum2qiskit from tweedledum.ir import Circuit